Date: Thu, 7 Oct 2010 02:01:34 +0400 From: Sergey Kandaurov <pluknet@gmail.com> To: Alexander Best <arundel@freebsd.org> Cc: freebsd-hackers@freebsd.org, Garrett Cooper <gcooper@freebsd.org> Subject: Re: issue with unsetting 'arch' flag Message-ID: <AANLkTikYX0vsxZi=J6Asekk-Kd_Y4MyemjDxM5FXARng@mail.gmail.com> In-Reply-To: <20101006193827.GA13528@freebsd.org> References: <20101005235054.GA45827@freebsd.org> <AANLkTi=sA4GP=B61tbEmG6B0CYcET=dCFMJByoS_5=yi@mail.gmail.com> <20101006173522.GA92402@freebsd.org> <AANLkTi==F4zFmJxqOBzMCk%2Buci6XbvoQBe4mqxHjtbr6@mail.gmail.com> <20101006193827.GA13528@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 6 October 2010 23:38, Alexander Best <arundel@freebsd.org> wrote: > On Wed Oct =A06 10, Garrett Cooper wrote: >> On Wed, Oct 6, 2010 at 10:35 AM, Alexander Best <arundel@freebsd.org> wr= ote: >> > On Wed Oct =A06 10, Garrett Cooper wrote: >> >> On Tue, Oct 5, 2010 at 4:50 PM, Alexander Best <arundel@freebsd.org> = wrote: >> >> > hi there, >> >> > >> >> > i think the following example shows the problem better than a long = explanation: >> >> > >> >> > `touch ftest && chflags arch ftest && chflags -vv 0 ftest`. >> >> > =A0^^non-root =A0 =A0 ^^root =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^^non-r= oot >> >> > >> >> > chflags claims to have cleared the 'arch' flag (which should be imp= ossible 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,= jpaetzel) >> >> > and stable/7 (nox). >> >> > On stable/6 it does NOT exist (jpaetzel). chflags properly fails wi= th EPERM. >> >> >> >> =A0 =A0 Fails for me when I call the syscall directly, as I would exp= ect, >> >> 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) >> >> >> >> =A0 =A0 According to my basic inspection in strtofflags >> >> (.../lib/libc/gen/strtofflags.c), it works as well. >> >> =A0 =A0 And last but not least, executing the commands directly on th= e 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 >> > >> > thanks for your test app and helping out with this problem. i'm not su= re >> > however you understood the problem. probably i didn't explain it right= : >> > >> > $ sudo rm -d /tmp/chflags.XXXXXX >> > $ tmpfile=3D`mktemp /tmp/chflags.XXXXXX` >> > $ sudo chflags arch $tmpfile >> > $ chflags noarch $tmpfile >> > >> > is what's causing the problem. the last chflags call should fail, but = it >> > doesn't. >> >> Sorry... my CLI based example was stupid. I meant: >> >> $ tmpfile=3D`mktemp /tmp/chflags.XXXXXX` >> $ chflags arch $tmpfile >> chflags: /tmp/chflags.V2NpXR: Operation not permitted >> $ chflags noarch $tmpfile >> $ rm $tmpfile >> >> Currently chflags(2) states: >> >> =A0 =A0 =A0The SF_IMMUTABLE, SF_APPEND, SF_NOUNLINK, and SF_ARCHIVED fla= gs may only >> =A0 =A0 =A0be set or unset by the super-user. =A0Attempts to set these f= lags by non- >> =A0 =A0 =A0super-users are rejected, >>> attempts by non-superusers to c= lear >> flags that >> =A0 =A0 =A0are already unset are silently ignored. <<< =A0These flags ma= y be set at any >> =A0 =A0 =A0time, but normally may only be unset when the system is in si= ngle-user >> =A0 =A0 =A0mode. =A0(See init(8) for details.) >> >> So this behavior is already well documented :). The EPERM section >> should really note SF_ARCHIVED though (whoever added the flag forgot >> to add that particular item to the ERRORS section). > > that's perfectly alright. clearing an unset flag shouldn't cause any erro= r to > be returned. however in my example arch *does* get set and still trying t= o > unset it as normal user doesn't return an error. > It's even more interesting. As far as I could parse the code: - UFS has no special handling for SF_ARCHIVED (I found only it for msdosfs) - ufs_setattr() does not handle unsetting SF_ARCHIVED, so all what it does is simply return zero. - /bin/chflags doesn't check the actual flags value from inode after calling chflags() syscall, and blindly assumes all is well, if chflags() returns with zero, --=20 wbr, pluknet
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTikYX0vsxZi=J6Asekk-Kd_Y4MyemjDxM5FXARng>