home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!howland.reston.ans.net!hsdndev!husc-news.harvard.edu!husc8.harvard.edu!maziere1
- From: maziere1@husc8.harvard.edu (David Mazieres)
- Newsgroups: comp.unix.sys5.r4
- Subject: Followup: SUID/mkdir(1) weirdness
- Message-ID: <1993Jan9.165708.19148@husc3.harvard.edu>
- Date: 9 Jan 93 21:57:01 GMT
- Organization: Harvard University Science Center
- Lines: 43
- Nntp-Posting-Host: husc8.harvard.edu
-
- Much thanks to guy@auspex.com and mbm@oasis.icl.co.uk for replying to my
- earlier post about set-uid shell scripts. It seems that the following
- things are true in SVR4.0:
-
- First, one of the bugs for set-uid shell scripts--namely the fact that
- one could exec a symbolic link to a shell script, quickly change the symbolic
- link to point to another file, and if the timing was good make your own
- shell script run set-uid--has been fixed in SVR4.0. The fix is to open
- the file for reading, and then pass in "/dev/fd/N" (where N is usually 3)
- as argv[0]. This means that you can't link several SUID shell scriptso different pathnames and then check argv[0] to decide what to do, but
- you can just chmod u+s any old shell script and have it run SUID.
-
- Second, "truss /bin/mkdir" reveals the following:
-
- > truss mkdir mkdir_test
- execve("/usr/bin/mkdir", 0x08047E70, 0x08047E7C) argc = 2
- open("/dev/zero", O_RDONLY, 020000537744) = 3
- mmap(0x00000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, 3, 0) = 0x8002E000
- getuid() = 100 [ 100 ]
- getuid() = 100 [ 100 ]
- getgid() = 100 [ 100 ]
- getgid() = 100 [ 100 ]
- close(3) = 0
- sysi86(SI86FPHW, 0x8002C4C0, 0x8002BFE4, 0x8000B185) = 0x00000000
- getuid() = 100 [ 100 ]
- setuid(100) = 0
- getgid() = 100 [ 100 ]
- setgid(100) = 0
- mkdir("mkdir_test", 0777) = 0
- _exit(0)
- > exit
-
- That's right, /bin/mkdir actually does a setuid(uid)! The only conceivable
- reason for this is backwards compatibility. Before the mkdir(2) system call
- was available, mkdir(1) ran set-uid root to be able to mknod the directory
- and then link . and .. in it. Obviously if mkdir was already SUID it would
- not have had access to the effective UID of its own process before the
- exec system call, so all directories were made with the real UID as owner.
-
- That still does not explain why the group of the new directory can't be
- the same as the effective GID, but oh well, this bug/feature has apparently
- been fixed in SVR4.2. In the meantime, I'll just use GNU mkdir in the
- very few shell-scripts I actually need to have.
-