home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / bsd / 10704 < prev    next >
Encoding:
Internet Message Format  |  1992-12-28  |  10.4 KB

  1. Xref: sparky comp.unix.bsd:10704 comp.unix.questions:15004 comp.unix.wizards:5339
  2. Newsgroups: comp.unix.bsd,comp.unix.questions,comp.unix.wizards
  3. Path: sparky!uunet!mcsun!fuug!prime!mits!karttu
  4. From: karttu@mits.mdata.fi (Antti Karttunen)
  5. Subject: Re: WEIRD IDEA? (chroot) Some corrections.
  6. Organization: MITS, Helsinki, Finland
  7. Date: Mon, 28 Dec 1992 21:44:12 GMT
  8. Message-ID: <1992Dec28.214412.29732@prime.mdata.fi>
  9. Followup-To: comp.unix.bsd,comp.unix.wizards
  10. Keywords: chroot, shadow login, pirates BBS
  11. References: <1992Dec26.191816.26596@prime.mdata.fi>
  12. Sender: usenet@prime.mdata.fi (Usenet poster)
  13. Nntp-Posting-Host: mits.mdata.fi
  14. Lines: 206
  15.  
  16. It seems that there were some serious flaws in the chrooting-scheme
  17. I posted here two days ago, flaws which would have resulted an
  18. unbootable system in the worst case. I'm grateful to Gordon Burditt
  19. for pointing them out, and with his permission I post the reply he
  20. mailed to me.
  21.  
  22. > = Gordon.
  23. >> = Me (Antti Karttunen).
  24.  
  25. >Date: Sun, 27 Dec 92 11:10 CST
  26. >From: gordon@sneaky.lonestar.org (Gordon Burditt)
  27. >To: karttu
  28. >Subject: Re: WEIRD IDEA? (chroot)
  29. >Newsgroups: comp.unix.bsd,comp.unix.questions
  30. >In-Reply-To: <1992Dec26.191816.26596@prime.mdata.fi>
  31. >Organization: Gordon Burditt
  32. >Cc: 
  33. >Status: RO
  34. >
  35. >>We are thinking about building a kind of unix BBS-system,
  36. >>and for one reason (don't ask me why) I would want to keep certain class
  37. >>of users segregated from the rest, and their id's in the separate
  38. >>passwd-file.
  39. >>
  40. >>We probably will be using BSD 4.3, and I have thought about using the
  41. >>chroot function for these special users, in the patched login I'm
  42. >>about to hack.
  43. >>
  44. >>Now, let's assume that the root-directory for these special users
  45. >>is called /usr/customers. To there I'll create subdirectories
  46. >>bin, dev, usr, etc, 'emulating' the real /bin, /dev, /usr and /etc
  47. >>directories, like is done with the most ftp-sites nowadays.
  48. >>I want to give these users access to certain commands but not to all,
  49. >>so I copy some commands from real /bin to our 'fake' /bin, namely
  50. >>/usr/customers/bin. Because we probably will have / and /usr in the
  51. >>separate filesystems I can't use hard links, and neither the symbolic links
  52. >>will work from 'inside' /usr/customers to 'outside' of it. To the rest of
  53. >>commands, programs and files in /usr/ucb, /usr/bin, /usr/games,
  54. >>/usr/local/bin and /usr/lib I can make hard links with ln.
  55. >
  56. >Suppose your worst nightmare happens:  someone cracks root INSIDE
  57. >the chroot environment.  You really don't want modified versions of
  58. >binaries used outside the chroot environment - Trojan Horse programs
  59. >could sucker root OUTSIDE the chroot environment into running them.
  60. >You probably want COPIES of binaries instead of links, even if they
  61. >take more disk space.
  62. >
  63. >Note that having the inode number of the chroot / not equal to 2
  64. >(not the top of a mounted filesystem) is a dead giveaway to the user
  65. >that he's in a chroot environment.
  66. >
  67. >>(Hmm, just realized that I could move some of the commands in /bin to
  68. >>/usr/customers/bin and then make symbolic links to them from the real /bin
  69. >>From 'outside' to 'inside' they will work, of course.)
  70. >
  71. >Sure you want to do that?
  72. >
  73. >Is /usr a mounted filesystem?  Consider what happens when you're single
  74. >user or booting and and /usr isn't mounted yet.  DON'T put the only
  75. >copy of mount on /usr !!!
  76. >
  77. >If your system has shared libraries, those need to be available in
  78. >the chroot environment.  And you really don't want to have those
  79. >only available on a non-root disk, as booting may become impossible.
  80. >
  81. >>About devices in /dev,  man chroot  gives the following warning:
  82. >>
  83. >>  BUGS
  84. >>       One should exercise extreme caution when    referencing device
  85. >>       files in    the new    root file system.
  86. >>
  87. >>and then tells nothing about why this extreme caution is needed.
  88. >
  89. >If someone cracks root INSIDE the chroot environment, they can make
  90. >their own devs (they might have to download a binary of mknod)
  91. >and do damage outside the chroot environment.  
  92. >
  93. >Having multiple copies of tty devs can cause problems with locking,
  94. >especially dialin/dialout.  Your hacked-up login should change ownership
  95. >on BOTH copies of the tty devs when someone logs into the chroot section,
  96. >and change back both copies when someone logs out.   You'll probably
  97. >have to maintain a chroot-version of utmp yourself.
  98. >
  99. >
  100. >>With these I could probably again move the tty-devices and others
  101. >>to /usr/customers/dev and then make symbolic links to them from /dev,
  102. >
  103. >Is /usr a mounted filesystem?  Consider what happens while booting,
  104. >and you don't have /usr mounted yet.
  105. >
  106. >>or create devices with the same names into /usr/customers/dev
  107. >>with /etc/mknod command. Probably it's this latter case where we
  108. >>will run into more problems, if we have processes started by special
  109. >>and normal users trying to access the same devices via /dev and
  110. >>/usr/customers/dev, with differing protections and different owners
  111. >>in these device-files.
  112. >>
  113. >>With mail there are probably some problems when considering the mail
  114. >>between special and other users (separate spool-directories), but I
  115. >>think they will be also solvable with symbolic links or weird alias-tricks.
  116. >
  117. >Leaving outside user's mailboxes inside the chroot environment leaves
  118. >a possibility of mischief (spying, mail tampering, etc.).  Whether
  119. >it's worth the risk is up to you.
  120. >
  121. >>1) Has anybody built this kind of system before, for _interactive_ users?
  122. >>(I don't mean the ftp-servers).
  123. >
  124. >Well, I tried it briefly on System III Xenix.  The system wasn't really
  125. >used heavily, and there weren't any seriously hostile users.  System III/
  126. >System V login cooperates by using a shell beginning with '*' in the
  127. >password file as an indication to do a chroot, and the home-directory
  128. >field indicating where, and then it loops back and does its thing again
  129. >using the new password files.  JFH's Shadow Login package does this
  130. >nicely.  Even if you don't want to install it on your system, reading the
  131. >source code will give you an idea of things you need to take care of.
  132. >
  133. >>2) Have I forgot anything essential, something which will run us
  134. >>into deep problems later? (If we want to use some software X or thing Y
  135. >>in the future.)
  136. >
  137. >I recommend initially, for testing purposes, writing a script to construct
  138. >the /usr/customers tree, and making sure that if you do a 
  139. >"rm -rf /usr/customers" except maybe for user-specific stuff (like
  140. >home directories, mail, message base, and arrange for password and group
  141. >file entries to survive the upgrade), none of the outside users will be 
  142. >affected.  (DON'T put the only copy of binaries of standard utilities 
  143. >inside the chroot environment!)  Have a root-privileged chroot login, 
  144. >which you can get rid of after testing if you like, but you might find 
  145. >it easier to use it to do maintenance like changing chroot-user's 
  146. >passwords when they forget them.  You might need this "build" script if 
  147. >your system software gets an upgrade, to upgrade the copies.  
  148. >
  149. >Keep editing the script, and tearing down and re-creating /usr/customers, 
  150. >until you are convinced it works well enough to let real users in.  It
  151. >might be worthwhile if you have a couple of knowledgable and hackerish
  152. >but trustworthy users who can test out the environment and report bugs
  153. >and security holes, don't mind having the environment destroyed 
  154. >occasionally, and let them in during the initial testing.
  155. >
  156. >Make yourself an unprivileged chroot'ed login from which you can test
  157. >things.  It's very easy to disable things by forgetting or not knowing
  158. >that ls calls awk sometimes, or similar things.  When users complain
  159. >that things are broken, use your test account to reproduce the problem.
  160. >Don't give it group "sys" or any special privileges - admins with
  161. >privileged logins are often blind to problems because their accounts
  162. >don't have the problem due to extra privileges.  This account might also 
  163. >be a good point-of-contact for mail from chroot customers.
  164. >
  165. >Lots of wierd things will happen if you forget to give users access
  166. >to /dev/null and /dev/tty.  Don't forget to give the users a
  167. >decent termcap file.  Someone has to maintain a pseudo-utmp file
  168. >containing at least the chroot users (some programs respond with
  169. >"you don't exist!" or other rude messages if an entry isn't found).
  170. >
  171. >                        Gordon L. Burditt
  172. >                        sneaky.lonestar.org!gordon
  173.  
  174. Further points from Gordon:
  175.  
  176. >There are other programs you don't want stuck over in /usr/customers
  177. >while you're trying to fix the system after a bad crash.  It is useful
  178. >to be able to fix the root disk first, THEN worry about fixing the others,
  179. >rather than having to do all of them at once.  
  180. >
  181. >It's nice to have, say, ls around.  Things like test, expr, and 
  182. >echo (if not built into the shell) are handy so shell scripts work.
  183. >Oh, yes, you need a shell, too.  rm, mkdir, rmdir, cat, and an editor
  184. >are handy also.  All of these might be useful over in /usr/customers
  185. >also, but you don't want the only copy there.  Naturally you also need
  186. >restore programs, fsck, mkfs or newfs, but users probably don't need
  187. >these.
  188. >
  189. >In general, I'd advise not having the only copy of any standard system
  190. >executable over under /usr/customers.  Make copies.  You can put specially 
  191. >crippled editors, specially configured mailers, unique versions of the 
  192. >password and group files, user data, BBS software and a message base 
  193. >there, but not stuff the normal system needs.  I'm not that familiar with 
  194. >NFS, but if your system has it, you might manage to NFS-mount a bin 
  195. >directory on your root disk onto /usr/customers/bin (preferably read-only).
  196. >
  197.  
  198. JFH's Shadow Login package mentioned above can be downloaded at least
  199. from the following ftp-sites:
  200.  
  201. pinus.slu.se:
  202. /pub/usenet/comp.sources.misc/volume26/shadow  (The main code is here)
  203.                               volume28/shadow  (These later volumes
  204.                               volume29/shadow   contain
  205.                               volume30/shadow   just patches).
  206.  
  207. archie.au: similarly in /usenet/comp.sources.misc/volume26-volume29
  208. gatekeeper.dec.com: similarly in /.0/comp.sources.misc/*
  209.  
  210. And from many other sites also. Check with your local archie.
  211.  
  212. Other netters have told me about the software called Pirates BBS, which
  213. also uses a chroot trick. It can be downloaded from the ftp-site:
  214. src.doc.ic.ac.uk::/computing/comms/bbs/PBBS
  215.  
  216. (Note: Now I crossposted this to comp.unix.wizards also, and set the
  217. follow-ups so that comments won't go to comp.unix.questions anymore.
  218. I hope the topic is/remains wizardy enough.)
  219.  
  220. --
  221. Antti Karttunen / karttu@mits.mdata.fi / $B%"%s%C%F%#!!%+%k%C%H%%%M%s(J
  222.