Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 35785 - chown does not reset sgid bit
Summary: chown does not reset sgid bit
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: x86 All
: High normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-14 01:11 UTC by Rajiv Aaron Manglani (RETIRED)
Modified: 2004-01-25 17:51 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rajiv Aaron Manglani (RETIRED) gentoo-dev 2003-12-14 01:11:52 UTC
when the group of a file that is setgid is changed, the setgid bit should be removed (says solar, and also the comments in chown_common() in sys_fs/open.c).

however, on x86 running 2.4.23-aa1:

# touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test
-rwxr-sr-x    1 root     root            0 Dec 14 03:59 test
-rwxr-sr-x    1 root     utmp            0 Dec 14 03:59 test

and on x86 running 2.6.0-test11-gentoo-r1:

-rwxr-sr-x    1 root     root            0 Dec 13 22:46 test
-rwxr-sr-x    1 root     utmp            0 Dec 13 22:46 test

oddly 2.6.0-test10-benh1 running on ppc seems to do the right thing:

# touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test
-rwxr-sr-x    1 root     root            0 Dec 14 08:06 test
-rwxr-xr-x    1 root     utmp            0 Dec 14 08:06 test

so is this code non-functional on x86? or is it wrong on ppc?


also note, on a x86 redhat 6.2 box running 2.2.19-6.2.16:

# touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test
-rwxr-sr-x    1 root     root            0 Dec 14 04:08 test
-rwxr-xr-x    1 root     utmp            0 Dec 14 04:08 test
Comment 1 Rajiv Aaron Manglani (RETIRED) gentoo-dev 2003-12-14 01:25:27 UTC
on a ppc running 2.4.22-ben2:

# touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test
-rwxr-sr-x    1 root     root            0 Dec 14 01:24 test
-rwxr-xr-x    1 root     utmp            0 Dec 14 01:24 test

(this is the expected result).
Comment 2 Tim Yamin (RETIRED) gentoo-dev 2003-12-14 15:07:23 UTC
Can you try the latest vanilla * prepatch * sources for both 2.4 and 2.6? If they both give this, I'd really recommend sending this upstream. This does look like a X86 problem of some sort.
Comment 3 solar (RETIRED) gentoo-dev 2003-12-16 14:58:49 UTC
scox has tracked this down to be a bug in CHOWN(1)
I'll ask him to paste his example code in here which shows this as well as his recomendations.

Comment 4 Andrea Luzzardi 2003-12-16 15:19:30 UTC
I've added some debug code to chown_common(), and the modes seem to be accurate before and after notify_change() is called.

By stracing CHOWN(1), i've noticed the following :
4374  chown32("test", 1000, 10)         = 0
4374  chmod("test", 0102654)            = 0
In fact, it seems that CHOWN(1) sets the original stored modes just after calling sys_chmod().

I wrote up a little application that calls sys_chown(), and the setuid/setgid flags were correctly removed, so this seems to be a coreutils' chown issue (feature?).

In my opinion, CHOWN(1) shouldn't touch at kernel set flags, so we should either remove the chmod() call from it, or make it remove setuid/setgid modes (the first solution is preferable).

Maybe we need some input from the coreutils guys.
Comment 5 Tim Yamin (RETIRED) gentoo-dev 2003-12-16 15:31:15 UTC
Rajiv: Can you get the "chown --version" for each of your results?
Comment 6 Rajiv Aaron Manglani (RETIRED) gentoo-dev 2003-12-17 23:32:42 UTC
versions, corresponding to the output shown above:

on x86 running 2.4.23-aa1: chown (coreutils) 5.0
on x86 running 2.6.0-test11-gentoo-r1: [unknown, was not my machine]
on ppc running 2.6.0-test10-benh1: chown (coreutils) 5.0.91
on a x86 redhat 6.2 box running 2.2.19-6.2.16: chown (GNU fileutils) 4.0p
on a ppc running 2.4.22-ben2: chown (coreutils) 5.0.91


and brad_mssw adds this... note that the behavior below is correct (setgid bit gets removed):

02:29 	<brad_mssw>	laptop root # touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test; chown --version
02:29 	<brad_mssw>	-rwxr-sr-x    1 root     root         6653 Dec 18 02:28 test
02:29 	<brad_mssw>	-rwxr-xr-x    1 root     utmp         6653 Dec 18 02:28 test
02:29 	<brad_mssw>	chown (coreutils) 5.0.91
02:29 	<brad_mssw>	Written by David MacKenzie.
02:29 	<brad_mssw>	on 2.6.0-test10-gentoo-r1


02:30 	<brad_mssw>	amd64 root # touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test; chown --version
02:30 	<brad_mssw>	-rwxr-sr-x    1 root     root            0 Dec 18 02:51 test
02:30 	<brad_mssw>	-rwxr-xr-x    1 root     utmp            0 Dec 18 02:51 test
02:30 	<brad_mssw>	chown (coreutils) 5.0.91
02:30 	<brad_mssw>	Written by David MacKenzie.
02:30 	<brad_mssw>	on 2.6.0-gentoo
Comment 7 Brian Jackson (RETIRED) gentoo-dev 2003-12-17 23:45:59 UTC
coreutils-5.0-r6
WRXsti linux-2.6-bk # touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test; chown --version
-rwxr-sr-x    1 root     utmp            0 Dec 18 01:44 test
-rwxr-sr-x    1 root     utmp            0 Dec 18 01:44 test
chown (coreutils) 5.0
Written by David MacKenzie.

coreutils-5.0.91-r2
WRXsti linux-2.6-bk # touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test; chown --version
-rwxr-sr-x    1 root     utmp            0 Dec 18 01:47 test
-rwxr-sr-x    1 root     utmp            0 Dec 18 01:47 test
chown (coreutils) 5.0.91
Written by David MacKenzie.
Comment 8 Brian Jackson (RETIRED) gentoo-dev 2003-12-17 23:49:36 UTC
even weirder, I opened a new terminal, and:
WRXsti root # touch test; chmod 2755 test; ls -l test; chown root:utmp test; ls -l test; chown --version
-rwxr-sr-x    1 root     root            0 Dec 18 01:50 test
-rwxr-xr-x    1 root     utmp            0 Dec 18 01:50 test
chown (coreutils) 5.0.91
Written by David MacKenzie.
Comment 9 Andrea Luzzardi 2003-12-18 03:17:32 UTC
Could you also strace chown and see if chmod is called ?
Comment 10 Brian Jackson (RETIRED) gentoo-dev 2003-12-18 10:15:36 UTC
Yes it does.

...
lstat64("test", {st_mode=S_IFREG|S_ISGID|0755, st_size=0, ...}) = 0
chown32(0xdffffb74, 0, 0x196)           = 0
exit_group(0)                           = ?

I also figured out the weirdness I was having. You have to make sure you rm test before running those steps ;) Silly me.
Comment 11 Brian Jackson (RETIRED) gentoo-dev 2003-12-18 10:17:33 UTC
sorry misread that, no chmod is not called with coreutils-5.0.91
Comment 12 Andrea Luzzardi 2003-12-18 18:45:14 UTC
Okay, then we can conclude that it's a coreutils 5.0 issue and that it has been fixed on coreutils 5.0.91
Comment 13 Seemant Kulleen (RETIRED) gentoo-dev 2004-01-14 15:29:27 UTC
coreutils-5.0.91-r4 needs A LOT of testing, because I'd really like to make it arch stable on x86 before Friday's portage snapshot for GRP
Comment 14 SpanKY gentoo-dev 2004-01-25 17:51:39 UTC
coreutils-5.0.91-r4.ebuild is in stable