home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / linux / 9661 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  5.5 KB

  1. Path: sparky!uunet!mcsun!uknet!cam-orl!iwj
  2. From: Ian Jackson (iwj@cam-orl.co.uk)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: clearing SUID bit on writes
  5. Summary: Mandatory record locking needs the sgid bit to stay
  6. Keywords: sgid, locking
  7. Message-ID: <1992Sep2.100340.25938@cam-orl.co.uk>
  8. Date: 2 Sep 92 10:03:40 GMT
  9. References: <kecw=5m00VogI1C1Jm@andrew.cmu.edu> <1992Sep1.235018.14835@fwi.uva.nl> <1992Sep1.170221.17317@athena.mit.edu>
  10. Sender: Ian Jackson (iwj@pepper.cam-orl.co.uk)
  11. Organization: Olivetti Research Ltd
  12. Lines: 143
  13.  
  14. In article <1992Sep1.170221.17317@athena.mit.edu>
  15.            tytso@ATHENA.MIT.EDU (Theodore Ts'o) writes:
  16. >When System V does is whenever you write to a setuid file (not just when
  17. >you append to it), it clears the setuid and setgid bits.  This prevents
  18. >a security hole if you have a setuid program which is group or world
  19. >writeable.  I don't think anything would break if we added this behavior
  20. >to Linux.  On the other hand, there's a much simpler way of avoiding the
  21. >security hole, which is to simply don't create group or world writeable
  22. >setuid files.
  23.  
  24. Careful! I don't know if you want to support mandatory record locking,
  25. but if you do you need to keep the sgid bit set on writes if all the
  26. execute bits are clear. I don't know anybody who's ever used mandatory
  27. locking, so this may be a red herring, but it's worth thinking about.
  28.  
  29. I'll enclose some manpage extracts for lockf(3), stat(2) & write(2)
  30. (SunOS 4.1.2).  They are a little unclear, but I tried it (small
  31. transcript also enclosed) and it only clears the sgid bit if one of
  32. the execute bits is set.
  33.  
  34. ----------
  35.  
  36. LOCKF(3)               C LIBRARY FUNCTIONS               LOCKF(3)
  37.  
  38. NAME
  39.      lockf - record locking on files
  40.  
  41. SYNOPSIS
  42.      #include <unistd.h>
  43.  
  44.      int lockf(fd, cmd, size)
  45.      int fd, cmd;
  46.      long size;
  47.  
  48. DESCRIPTION
  49.      lockf() places, removes, and tests for  exclusive  locks  on
  50.      sections  of files.  These locks are either advisory or man-
  51.      datory depending on the mode bits of the file.  The lock  is
  52.      mandatory  if the set-GID bit (S_ISGID) is set and the group
  53.      execute bit (S_IXGRP) is clear (see stat(2V) for information
  54.      about mode bits).  Otherwise, the lock is advisory.
  55.  
  56.      If a process holds a mandatory exclusive lock on  a  segment
  57.      of  a  file,  both read and write operations block until the
  58.      lock is removed (see WARNINGS).
  59.  
  60.      An advisory lock does not affect read and  write  access  to
  61.      the locked segment.  Advisory locks may be used by cooperat-
  62.      ing processes checking for locks using F_GETLCK  and  volun-
  63.      tarily observing the indicated read and write restrictions.
  64.  
  65.      [ ... ]
  66.  
  67. WARNINGS
  68.      Mandatory record locks are dangerous.  If a runaway or  oth-
  69.      erwise  out-of-control  process should hold a mandatory lock
  70.      on a file critical to the system and fail  to  release  that
  71.      lock,  the entire system could hang or crash.  For this rea-
  72.      son, mandatory record locks may be removed in a future SunOS
  73.      release.n Use advisory record locking whenever possible.
  74.  
  75.      [ ... ]
  76.  
  77. BUGS
  78.      lockf() locks do not interact in any way with locks  granted
  79.      by  flock(),  but  are  compatible  with  locks  granted  by
  80.      fcntl().
  81.  
  82. Sun Release 4.1   Last change: 21 January 1990
  83.  
  84. ----------
  85.  
  86. WRITE(2V)                 SYSTEM CALLS                  WRITE(2V)
  87.  
  88. NAME
  89.      write, writev - write output
  90.  
  91. SYNOPSIS
  92.      [ ... ]
  93.  
  94. DESCRIPTION
  95.      [ ... ]
  96.      If the real user is not the super-user, then write()  clears
  97.      the set-user-id bit on a file.  This prevents penetration of
  98.      system security by a user who  "captures"  a  writable  set-
  99.      user-id file owned by the super-user.
  100.  
  101. [ ... - there is no mention of the set-group-id bit - iwj ]
  102. Sun Release 4.1   Last change: 21 January 1990
  103.  
  104. ----------
  105.  
  106. STAT(2V)                  SYSTEM CALLS                   STAT(2V)
  107.  
  108. NAME
  109.      stat, lstat, fstat - get file status
  110.  
  111. SYNOPSIS
  112.      [ ... ]
  113.  
  114. DESCRIPTION
  115.      [ ... - including stat structure layout - ... ]
  116.  
  117.      The status information word st_mode is bit-encoded using the
  118.      following masks and bits:
  119.  
  120.      S_ISUID        Set user  ID  on  execution.   The  process's
  121.                     effective user ID is set to that of the owner
  122.                     of the file when the file is run as a program
  123.                     (see  execve(2V)).   On  a regular file, this
  124.                     bit should be cleared on any write.
  125.  
  126.      S_ISGID        Set group ID  on  execution.   The  process's
  127.                     effective group ID is set to that of the file
  128.                     when the  file  is  run  as  a  program  (see
  129.                     execve(2V)).   On  a  regular  file, this bit
  130.                     should be cleared on any write.
  131.  
  132. Sun Release 4.1   Last change: 21 January 1990
  133.  
  134. ----------
  135.  
  136. Script started on Wed Sep  2 10:55:32 1992
  137. $ rm -f foo; touch foo
  138. $ chmod 2666 foo; ls -lg foo
  139. -rw-rwSrw-  1 iwj      other           0 Sep  2 10:55 foo
  140. $ echo >>foo; ls -lg foo
  141. -rw-rwSrw-  1 iwj      other           1 Sep  2 10:55 foo
  142. $ chmod 2766 foo; ls -lg foo
  143. -rwxrwSrw-  1 iwj      other           1 Sep  2 10:55 foo
  144. $ echo >>foo; ls -lg foo
  145. -rwxrw-rw-  1 iwj      other           2 Sep  2 10:55 foo
  146. $ chmod 2676 foo; ls -lg foo
  147. -rw-rwsrw-  1 iwj      other           2 Sep  2 10:55 foo
  148. You have mail in /usr/spool/mail/iwj
  149. $ echo >>foo; ls -lg foo
  150. -rw-rwxrw-  1 iwj      other           3 Sep  2 10:56 foo
  151. $ rm foo
  152. $ exit
  153. Script done on Wed Sep  2 10:56:48 1992
  154. -- 
  155. Ian Jackson                             The opinions expressed here are my own.
  156.               iwj@cam-orl.co.uk / ...!mcsun!uknet!cam-orl!iwj
  157.