Unable to unset setguid bit
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
coreutils (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
In Precise, it is possible to set the guid bit for a directory but not to unset it.
$ chmod g=rwxs Y
foo@precise:/tmp/X$ ls -l
total 4
drwxrwsr-x 2 foo adm 4096 Feb 5 18:48 Y
foo@precise:/tmp/X$ chmod g= Y
foo@precise:/tmp/X$ ls -l
total 4
drwx--Sr-x 2 maintenance adm 4096 Feb 5 18:48 Y
foo@precise:/tmp/X$ chmod g=rwx Y
maintenance@
total 4
drwxrwsr-x 2 foo adm 4096 Feb 5 18:48 Y
foo@precise:/tmp/X$ chmod 0775 Y
foo@precise:/tmp/X$ ls -l
total 4
drwxrwsr-x 2 foo adm 4096 Feb 5 18:48 Y
ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: bash 4.2-1ubuntu1
ProcVersionSign
Uname: Linux 3.2.0-14-
ApportVersion: 1.91-0ubuntu1
Architecture: i386
Date: Sun Feb 5 18:52:29 2012
InstallationMedia: Ubuntu-Server 12.04 LTS "Precise Pangolin" - Alpha i386 (20111129)
ProcEnviron:
LANGUAGE=en_US:en
PATH=(custom, no user)
LANG=en_US.UTF-8
SHELL=/bin/bash
SourcePackage: bash
UpgradeStatus: No upgrade log present (probably fresh install)
Thanks for taking the time to report this. The behaviour you describe may seem surprising (and it was to me, too!), but is actually what the man page describes:
chmod preserves a directory's set-user-ID and set-group-ID bits unless
you explicitly specify otherwise. You can set or clear the bits with
symbolic modes like u+s and g-s, and you can set (but not clear) the
bits with a numeric mode.
So, you can clear the setgid bit on the directory in your example with "chmod g-s Y", but not with "chmod 0775 Y". Since this is the defined behaviour that others may have come to expect for both interactive use and in long-established scripts, it's unlikely to be changed now.