Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 49224 - ebuild.sh sfperms enhancement
Summary: ebuild.sh sfperms enhancement
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All All
: High enhancement (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-27 17:26 UTC by Cory Visi (RETIRED)
Modified: 2004-05-02 13:31 UTC (History)
2 users (show)

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


Attachments
ebuild.sh.diff (ebuild.sh.diff,753 bytes, text/plain)
2004-04-27 17:26 UTC, Cory Visi (RETIRED)
Details
ebuild.sh.diff (ebuild.sh.diff,842 bytes, text/plain)
2004-04-27 17:28 UTC, Cory Visi (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Cory Visi (RETIRED) gentoo-dev 2004-04-27 17:26:14 UTC
Solar, this is the sfperms change I mentioned to you briefly awhile ago. Rather than saying "in my opinion" 50 times below, please assume that everything said below is my opinion and my idea of security implementation. Here is my logic behind it:

First of all, there is no difference between handling SetGIDs and SetUIDs. The file has elevated privileges, and should not be edited by anyone. This logic is consistent with the UNIX logic that when you change the file owner of a SetUID file, it loses its SetUID bit. It follows that we should remove all read/write bits from any SetxID file. So I have grouped together the two blocks and handled them identically.

Now, the find statement is ridiculous, but I believe it has to be that way. We do not care about files that are any combination of -x,+s. These are most likely the result of broken install scripts anyway. At most, we could produce a warning for this. I believe the sequence of ORs I use is the only way to properly catch all the possible setuid/setgid combinations that actually do something (i.e. that we care about).

Finally, the `file..` check is to catch setuid/setgid scripts. Scripts will not run without read permission, so we cannot remove that. At most, we can remove the write permission, so there is an else clause for that.

What do you think? I'm running this now, and I like the results.

I wasn't sure what to set "component" or "keywords" to for this.
Comment 1 Cory Visi (RETIRED) gentoo-dev 2004-04-27 17:26:41 UTC
Created attachment 30197 [details]
ebuild.sh.diff
Comment 2 Cory Visi (RETIRED) gentoo-dev 2004-04-27 17:28:46 UTC
Created attachment 30199 [details]
ebuild.sh.diff

previous diff was the wrong version
Comment 3 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-04-28 01:51:30 UTC
the script problem isn't solved by your file check.
i can quite easily dump some text info a file, WITHOUT the '#!...' header, that that is a perfectly valid script.

How about checking that the file is ELF type instead?
Comment 4 solar (RETIRED) gentoo-dev 2004-04-28 11:06:51 UTC
I just checked and I don't see where ebuild.sh is removing the +w bit
anymore. (I'll check look harder in a few to verify).

Anyway sure we could really do 'go-rw' on all setXid files.

Bitwise permissions to only get the executable ones is not what the
feature was designed to do or how it should behave. Think least
privilege (ie what if file has a really bad set of perms say 7777)

We also don't want to make sure it's ELF,COFF,a.out, script or 
otherwise. Only thing that matters is if it's type 'f'. If a script has
a setXid permission then I for one want it to break. An example of this
would be bug #42908  I'd much rather have a user/dev report it as a bug
so that the .ebuild may be corrected. file(1) is also something I'd
rather us not depend on for this feature.
Comment 5 Cory Visi (RETIRED) gentoo-dev 2004-04-30 06:21:23 UTC
To respond to the file command not detecting all scripts, I'm not sure scripts without the #!/path/to/shell are perfectly valid. Scripts without that are usually sourced. I understand if you do not want to use the file command in ebuild.sh, though.

I believe there are definite legit uses of a setgid script. I'm not sure about a setuid one, but maybe. For instance, you could have a script to wall SMB messages from samba. This would need to be setgid tty if you had wall -s. I actually use a script like this, and I check at the beginning for $PPID = 1, which seems to be fairly safe. I don't think scripts with a +s are necessarily broken, and removing +r from those scripts will certainly break them.

What is the intention of the permission check, if it's not for executable setXids? Do you want to make a separate check for 777 files? How do we know a 777 file is a mistake? Some ebuilds probably need this.
Comment 6 solar (RETIRED) gentoo-dev 2004-04-30 07:42:58 UTC
Scripts should never be suid this is a well documented fact. A 
distribution surely should not be dishing them out either. If you want
to play risky games with your local security then that's fine for your 
local box but not acceptable for gentoo QA. I certainly don't want to 
change this functionality or see it changed in anyway that shifts it
away from a least privilege model.

If you know a single ebuild that will yields o+w or a seXid script then 
I want to know about it because that's a potential security risk and
must be fixed, package.masked and or removed from the tree. 

In short the sfperms feature is perfect and does exactly what it does 
the way it's supposed to and is documented as doing so.

The only change we could/should make if any is tie in full go-rw 
is if 'strict' was found in FEATURES.

If you think otherwise then please propose a new feature.
Comment 7 Cory Visi (RETIRED) gentoo-dev 2004-04-30 08:33:25 UTC
I do not agree about the scripts, but it's not a big issue. I do not know of any examples.

What about changing the find so it ignores non-executable setXids?
Comment 8 solar (RETIRED) gentoo-dev 2004-04-30 09:22:11 UTC
no.
Comment 9 Nicholas Jones (RETIRED) gentoo-dev 2004-05-02 13:31:07 UTC
Solar's disagreement sounds right to me.