home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sun.admin
- Path: sparky!uunet!gatech!news.ans.net!cmcl2!prism.poly.edu!kapela
- From: kapela@prism.poly.edu (Theodore S. Kapela)
- Subject: Re: Need to let Non-Root use Mount
- Message-ID: <1992Dec14.140327.17774@prism.poly.edu>
- Organization: Polytechnic University, New York
- References: <hq8qvm+@lynx.unm.edu> <1931@enst.enst.fr>
- Date: Mon, 14 Dec 92 14:03:27 GMT
- Lines: 67
-
- This has been brought up several times in the past, and someone always
- makes the same suggestion. (Hopefully) before someone gets "burned"
- I thought it wise to mention this. . .
-
- In article <1931@enst.enst.fr> tardieu@inf.enst.fr writes:
- >In article <hq8qvm+@lynx.unm.edu>, khan@us17501.mdc.com (Naseer Khan) writes:
- >-> Hello Sun Gurus,
- >->
- >-> The command they need to execute is 'mount -r /dev/sr0 /cdrom'
- >-> So, I thought I'd see if I could put that in a shell file and
- >-> set it's permission to 4755 (with setuid) and have it owned
- >-> by root. I didn't have much hope for this, suspecting that the
- >-> shell probably wouldn't be passing the user-id around. Well,
- >-> I guess I was right in my pessimism. It gives the same old
-
- Set-UID shell scripts are generally *BAD* for security.
-
- >main()
- >{
- > if (getuid()==getpwnam("username")->pw_uid) {
- > setuid(0);
- > execl("/usr/etc/mount","mount","param1","param2",...,(char *)0);
- > }
- > else write(2,"Permission denied\n",18);
- >}
- >
- >where you put the username instead of 'username', and the parameters you
- >want to give to mount instead of 'param1',...
- >
-
- NO NO NO NO NO!!!! This is an even worse security risk than Set-UID shell
- scripts (You can thank Sun for that). /usr/etc/mount does *NOT* handle the
- actual mounting of the device. Instead, it does an execlp - NOTE THE
- "p" in the funtion name - to mount the actual device. If you look in /usr/etc,
- you will see a bunch of files "mount_*". These are what actually do the
- mounting, and, even though /usr/etc/mount is the one that complains about
- your perms, it is these that actually need you to be root.
-
- >You need to BE root to execute the mount command, not to have the effective uid
- >root.
- >
-
- The reason that just setting your effective uid to 0 (IE the setuid shell
- script) does not work is that effective uid is *NOT* preserved accross the
- execlp() in /usr/etc/mount.
-
- Now - in case anyone hasn't noticed yet, I specifically pointed out which
- version of the exec() routines is used. If you don't know why I said this,
- or where the security risk is, you should see the man pages for execl()
- (and friends. . .)
-
- If you want to write a proper wrapper for /usr/etc/mount to let normal
- users mount/umount the cdrom (or floppy, or tape drive. . .), you
- must search the environment for the "PATH", and munge it so it *only*
- contains /usr/etc (getenv()/putenv() will work fine here). In the
- case of SunOS, you should also REMOVE any LD_LIBRARY_PATH you may
- find. You may also set up a simple access control list using a
- unix group. Add a group to /etc/group (say, "mounters") that contains
- those users you want to be able to use your "mount" wrapper. Then,
- search the group list (via getgrnam) for permission.
-
-
- --
- ..............................................................................
- Theodore S. Kapela kapela@poly.edu
- Center for Applied Large-Scale Computing
- Polytechnic University
-