From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 6 17:09:23 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E6C7F106564A; Wed, 6 Oct 2010 17:09:22 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-gy0-f182.google.com (mail-gy0-f182.google.com [209.85.160.182]) by mx1.freebsd.org (Postfix) with ESMTP id 889998FC0A; Wed, 6 Oct 2010 17:09:22 +0000 (UTC) Received: by gyg4 with SMTP id 4so3268077gyg.13 for ; Wed, 06 Oct 2010 10:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=rJKoO6d7/XWbYQOnMWTYp2gjzcMlDO1/RPWNS49lcoM=; b=rTPmzJyyGhfRNkk3HGoRe/96BqyKFjqQwCHVEbn6xDQ3jKVez3pwOgwUSt0W36W/dJ 0/CKbKjNkSWzAxlHS6kMoOOv2TWvopzcCowWIwxomQnAA1RSE7XjyWs/peqxUP6oXVwL R9G3CmVzzTrdYU+a4gUNed6mVO5SBPrfdjxog= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=xKxKHSkvamlp4yc1HJS50Oi596Bh1s8RX98Vtp0cm8acno2TIfgr8vq620ZnonQNA+ qykNuK3dyMjmgAQSszOh5I90WyvmdZ/Na9OKrMKJ5iJIxNRPGoawj4jGiJRAdGpXkoxg Zi+war5XJSS/RnhEv8cRxLcmFdkzQwnswPFJk= MIME-Version: 1.0 Received: by 10.42.1.75 with SMTP id 11mr3043873icf.6.1286384961290; Wed, 06 Oct 2010 10:09:21 -0700 (PDT) Sender: yanegomi@gmail.com Received: by 10.231.184.3 with HTTP; Wed, 6 Oct 2010 10:09:21 -0700 (PDT) In-Reply-To: <20101005235054.GA45827@freebsd.org> References: <20101005235054.GA45827@freebsd.org> Date: Wed, 6 Oct 2010 10:09:21 -0700 X-Google-Sender-Auth: aplxqdWYXEEajF4d-6JDuufpcOI Message-ID: From: Garrett Cooper To: Alexander Best Content-Type: multipart/mixed; boundary=90e6ba181872a98a1d0491f5d630 Cc: freebsd-hackers@freebsd.org Subject: Re: issue with unsetting 'arch' flag X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Oct 2010 17:09:23 -0000 --90e6ba181872a98a1d0491f5d630 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, Oct 5, 2010 at 4:50 PM, Alexander Best wrote: > hi there, > > i think the following example shows the problem better than a long explan= ation: > > `touch ftest && chflags arch ftest && chflags -vv 0 ftest`. > =A0^^non-root =A0 =A0 ^^root =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^^non-root > > chflags claims to have cleared the 'arch' flag (which should be impossibl= e as > non-root user), but indeed has done nothing. > > i've tried the same with 'sappnd' and that works as can be expected. > > The issue was confirmed to exist in HEAD (me), stable/8 (pgollucc1, jpaet= zel) > and stable/7 (nox). > On stable/6 it does NOT exist (jpaetzel). chflags properly fails with EPE= RM. Fails for me when I call the syscall directly, as I would expect, and passes when I'm superuser: $ ./test_chflags (uid, euid) =3D (1000, 1000) test_chflags: chflags: Operation not permitted test_chflags: lchflags: Operation not permitted $ sudo ./test_chflags (uid, euid) =3D (0, 0) According to my basic inspection in strtofflags (.../lib/libc/gen/strtofflags.c), it works as well. And last but not least, executing the commands directly on the CLI work= : $ tmpfile=3D`mktemp /tmp/chflags.XXXXXX` $ chflags arch $tmpfile chflags: /tmp/chflags.nQm1IL: Operation not permitted $ rm $tmpfile $ tmpfile=3D`mktemp /tmp/chflags.XXXXXX` $ sudo chflags arch $tmpfile $ sudo chflags noarch $tmpfile $ rm $tmpfile Your results may (but shouldn't) vary [unless your environment is setup differently]... Please note that I'm using UFS2 with SUJ... not all filesystems support this (ext2/3/4? msdosfs? ZFS?), so I would be careful about which filesystem you pick and whether or not there's a bug where it's not properly identifying that the operation you're attempting to perform is valid. Thanks, -Garrett $ uname -a FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #9 r211309M: Thu Aug 19 22:50:36 PDT 2010 root@bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA amd64 --90e6ba181872a98a1d0491f5d630 Content-Type: application/octet-stream; name="test_chflags.c" Content-Disposition: attachment; filename="test_chflags.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_geyg1gi71 I2luY2x1ZGUgPHN5cy9zdGF0Lmg+CiNpbmNsdWRlIDxlcnIuaD4KI2luY2x1ZGUgPGZjbnRsLmg+ CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8dW5pc3RkLmg+CgppbnQgbWFpbihpbnQgYXJn YywgY2hhciphcmd2W10pCnsKCglwcmludGYoIih1aWQsIGV1aWQpID0gKCVkLCAlZClcbiIsIGdl dHVpZCgpLCBnZXRldWlkKCkpOwoKCWNoYXIgdGVtcGxhdGVbXSA9ICIvdG1wL2NoZmxhZ3MuWFhY WFhYIjsKCWNoYXIgKnRtcGZpbGU7CgoJdG1wZmlsZSA9IG1rdGVtcCh0ZW1wbGF0ZSk7CgoJaWYg KHRtcGZpbGUgPT0gTlVMTCkKCQllcnIoMSwgIm1rdGVtcCIpOwoKCWlmIChjbG9zZShvcGVuKHRt cGZpbGUsIE9fQ1JFQVQpKSkKCQllcnIoMSwgImNsb3NlKG9wZW4oLi4pKSIpOwoKCWlmIChjaGZs YWdzKHRtcGZpbGUsIFNGX0FSQ0hJVkVEKSAhPSAwKQoJCXdhcm4oImNoZmxhZ3MiKTsKCWlmIChs Y2hmbGFncyh0bXBmaWxlLCBTRl9BUkNISVZFRCkgIT0gMCkKCQl3YXJuKCJsY2hmbGFncyIpOwoK CWlmIChjaGZsYWdzKHRtcGZpbGUsIDApICE9IDApCgkJZXJyKDEsICJjaGZsYWdzKDApIik7Cgll bHNlCgkJdW5saW5rKHRtcGZpbGUpOwoKCXJldHVybiAoMCk7Cn0K --90e6ba181872a98a1d0491f5d630--