home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / sys5 / r4 / 1195 < prev    next >
Encoding:
Internet Message Format  |  1993-01-09  |  2.4 KB

  1. Path: sparky!uunet!wupost!howland.reston.ans.net!hsdndev!husc-news.harvard.edu!husc8.harvard.edu!maziere1
  2. From: maziere1@husc8.harvard.edu (David Mazieres)
  3. Newsgroups: comp.unix.sys5.r4
  4. Subject: Followup:  SUID/mkdir(1) weirdness
  5. Message-ID: <1993Jan9.165708.19148@husc3.harvard.edu>
  6. Date: 9 Jan 93 21:57:01 GMT
  7. Organization: Harvard University Science Center
  8. Lines: 43
  9. Nntp-Posting-Host: husc8.harvard.edu
  10.  
  11. Much thanks to guy@auspex.com and mbm@oasis.icl.co.uk for replying to my
  12. earlier post about set-uid shell scripts.  It seems that the following
  13. things are true in SVR4.0:
  14.  
  15. First, one of the bugs for set-uid shell scripts--namely the fact that
  16. one could exec a symbolic link to a shell script, quickly change the symbolic
  17. link to point to another file, and if the timing was good make your own
  18. shell script run set-uid--has been fixed in SVR4.0.  The fix is to open
  19. the file for reading, and then pass in "/dev/fd/N" (where N is usually 3)
  20. 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
  21. you can just chmod u+s any old shell script and have it run SUID.
  22.  
  23. Second, "truss /bin/mkdir" reveals the following:
  24.  
  25. > truss mkdir mkdir_test
  26. execve("/usr/bin/mkdir", 0x08047E70, 0x08047E7C)  argc = 2
  27. open("/dev/zero", O_RDONLY, 020000537744)    = 3
  28. mmap(0x00000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, 3, 0) = 0x8002E000
  29. getuid()                    = 100  [ 100 ]
  30. getuid()                    = 100  [ 100 ]
  31. getgid()                    = 100  [ 100 ]
  32. getgid()                    = 100  [ 100 ]
  33. close(3)                    = 0
  34. sysi86(SI86FPHW, 0x8002C4C0, 0x8002BFE4, 0x8000B185) = 0x00000000
  35. getuid()                    = 100  [ 100 ]
  36. setuid(100)                    = 0
  37. getgid()                    = 100  [ 100 ]
  38. setgid(100)                    = 0
  39. mkdir("mkdir_test", 0777)            = 0
  40. _exit(0)
  41. > exit
  42.  
  43. That's right, /bin/mkdir actually does a setuid(uid)!  The only conceivable
  44. reason for this is backwards compatibility.  Before the mkdir(2) system call
  45. was available, mkdir(1) ran set-uid root to be able to mknod the directory
  46. and then link . and .. in it.  Obviously if mkdir was already SUID it would
  47. not have had access to the effective UID of its own process before the
  48. exec system call, so all directories were made with the real UID as owner.
  49.  
  50. That still does not explain why the group of the new directory can't be
  51. the same as the effective GID, but oh well, this bug/feature has apparently
  52. been fixed in SVR4.2.  In the meantime, I'll just use GNU mkdir in the
  53. very few shell-scripts I actually need to have.
  54.