home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / vms / 20208 < prev    next >
Encoding:
Internet Message Format  |  1993-01-02  |  13.7 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!ucbvax!lrw.com!leichter
  2. From: leichter@lrw.com (Jerry Leichter)
  3. Newsgroups: comp.os.vms
  4. Subject: re: re: Re: HELP!!! Security problem for gurus. [Directories]
  5. Message-ID: <9301021337.AA28427@uu3.psi.com>
  6. Date: 2 Jan 93 12:35:06 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: world
  9. Organization: The Internet
  10. Lines: 268
  11.  
  12.  
  13.     >[I wrote:]
  14.     >    One of the fields shown was "TYPE" at offset 4.  [...] it had
  15.     >    the exact same value [...] for ALL directory entries in ALL
  16.     >    .DIR files.  I wondered what OTHER valid values for that field
  17.     >    existed [...]
  18.     >
  19.     >Interesting.  The ODS-II specs, as best I can recall, define two
  20.     >possible entry types:  Files and links.  Files are what you would
  21.     >expect. A link is a like a Unix "soft link":  A text string that
  22.     >replaces the file specification being parsed.  While specified way
  23.     >back when ODS-II was first designed (i.e., when VMS was designed),
  24.     >this feature has never been implemented.
  25.  
  26.     [Chris Chiesa responds:]
  27.     Being unfamiliar as I am with the specific behavior of "a Unix 'soft
  28.     link'," can you elaborate on the intended behavior of this 
  29.     interesting-sounding never-implemented feature?  I'm just wondering
  30.     what we're missing out on.
  31.  
  32. A Unix soft link (also known as a symbolic link, or symlink for short) is
  33. similar to a logical name embedded in the file system.  For example, if entry
  34. /u1/leichter/file were a link to /u2/chiesa/other_file, then when someone
  35. attempted to read /u1/leichter/file, when Unix got to the link it would throw
  36. out the file name it had so far and start again with the other file,
  37. /u2/chiesa/other_file.  That name might resolve to a file, to another link, or
  38. to nothing at all.  But assuming that other_file actually exists, the link
  39. would provide me with a way to refer to a file in your directory indirectly.
  40. (If my default directory were /u1/leichter, then I would only have to mention
  41. the spec "file" to get to the link.)
  42.  
  43. This kind of link would be easily interpretable in a VMS environment:  If the
  44. link is a fully specified file (device, directory, etc.), then it simply
  45. replaces the original specification.  (There are still some interesting
  46. complications as to how this should interact with RMS filename parsing,
  47. especially how it should be used for "sticky defaults" applied to later files;
  48. but in this simple case the solutions are pretty simple.)
  49.  
  50. More generally, we have to decide what to do if the link is NOT a fully
  51. specified name.  For example, suppose by current directory is /u1/leichter,
  52. and I refer to /u1/leichter/subdir/link, which is a link to somefile.  What
  53. directory should we search for "somefile" in?  If we simply replace the entire
  54. spec, we effectively look in the current default directory.  If we replace
  55. only the last element of the spec, we look in the same directory link was
  56. found in.  (I.e., we either get just "somefile", to which the default
  57. directory is applied, or /u1/leichter/subdir/somefile.)  Unix takes the second
  58. interpretation:  Interpret relative to the directory in which the link is
  59. found.  However, it does this even though it really replaces the entire spec.
  60. The reason for this peculiar state of affairs has to do with links to
  61. directory.  The actual rule is:  If, while interpreting any element of a spec,
  62. you encounter a link, throw out everything in the spec up to this point,
  63. insert the link value, then stick back the rest of the spec.  Now, temporarily
  64. using the directory in which the link was found as the default directory,
  65. interpret the resulting spec.
  66.  
  67. Thus, if /chiesa/ld is a link to local_directory, then a reference to
  68.  
  69.         /chiesa/ld/sources/v2/foo.c
  70.  
  71. will be resolved to
  72.  
  73.         local_directory/sources/v2/foo.c
  74.  
  75. relative to /chiesa, or
  76.  
  77.         /chiesa/local_directory/sources/v2/foo.c
  78.  
  79. How should this work on VMS?  It's not at all obvious, given the more complex
  80. syntax of VMS file specifications - and, much more to the point, the existing
  81. complex semantics of VMS file name parsing.  It would all have to be worked
  82. out in a useful way.  It never has been.
  83.  
  84.     >(ODS-II has several other "spec'ed but never implemented" features,
  85.     >including a hashed file type and something I gather will finally
  86.     >appear in VMS V6: Access-mode restricted files (i.e., files that can
  87.     >only be accessed from inner-mode code, regardless of the usual
  88.     >protections on the file).
  89.  
  90.     Very interesting!  What's a "hashed" file type?  Again, can you
  91.     elaborate?
  92.  
  93. The documentation doesn't say, but from context (and from knowing what was
  94. going on in the field at the time the spec was written), it was almost
  95. certainly intended to describe a file structure which used hashed index
  96. tables, rather than the B*-trees of RMS indexed files.
  97.  
  98.             This may be a loaded question, but: how does it happen
  99.     that features can  BE "spec'd but never implemented?"
  100.  
  101. The spec gets written before the code, you know - quite some time before.
  102. It's also written for rather different purposes.  The ODS-II spec was written
  103. to describe a very general new file system to replace ODS-I, the RSX file
  104. system.  It's common for the architect to specify things that look as if they
  105. might soon be needed.  Sometimes he's right; sometimes he's wrong.
  106.  
  107.                                    What determines
  108.     whether a particular feature gets implemented right away, or after a
  109.     long delay (how long has ODS-II been in existence with
  110.     spec'ed-but-never-implemented features?), or never?
  111.  
  112. ODS-II pre-dates VMS.  What decides when or if features get implemented is
  113. complex and tough to pin down.  Theoretically, product management specifies
  114. features based on customer demand.  While this MIGHT happen in the new,
  115. reformed DEC, in practice the reality is fairly chaotic, with features being
  116. decided on by a mix of product managers, various other levels of managers -
  117. and ultimately the implementors, who can effectively veto things by making
  118. very high cost estimates, or add things by just doing them.  A famous example
  119. is the reverse-video "Interrupt" you get for CTRL/Y.  This started out as a
  120. joke played on the VMS group by the terminal driver implementor:  He snuck it
  121. in one day.  Everyone liked it, so it ended up in the product.
  122.  
  123.                                  And, finally, how
  124.     do YOU find out about these things, Jerry?
  125.  
  126. That would be telling.
  127.  
  128.                             Inquiring minds... etc.
  129.     ;-)
  130.  
  131. Seriously, I have a copy of the ODS-II spec - after all, I *did* work for DEC
  132. for 12 years!  It's not a particularly secret spec; I know other people have
  133. copies, probably more recent ones than mine.
  134.  
  135.     >I believe DIRECTORY accesses the directory files directly, rather
  136.     >than going through RMS.  It probably doesn't check the validity of
  137.     >the entries it sees.
  138.  
  139.     It seems evident from what I've observed, that DIRECTORY doesn't
  140.     (currently)  validate at least the contents of the "type" field I
  141.     played with -- but I'm afraid I don't see how it makes any difference
  142.     whether one "accesses the directory files directly" OR "(goes) through
  143.     RMS."  If I open "filespec.DIR" as a FILE, I can read it just fine
  144.     using RMS -or- "directly."  Do I misunderstand you, Jerry?
  145.  
  146. No; that's just what I mean.  The SUPPORTED access to .DIR files is through
  147. RMS, which is the component of VMS that maintains them.  The $SEARCH service
  148. lets you wild-card through a directory; if you or I wanted to write a replace-
  149. ment for DIRECTORY, $SEARCH would be the supported way for us to do it.  I
  150. believe, however, the DIRECTORY simply reads the .DIR file as a file.  Sure,
  151. that might (or might not) go through RMS; actually, it might be simplest to
  152. simply map the directory into memory as a disk section.  But even if it went
  153. through RMS, it would be as a normal file, not as a directory; RMS would not
  154. be trying to interpret the records as directory entries.
  155.  
  156.     >Just out of curiosity (since you've done this already), did DIRECTORY
  157.     >work when you were looking at more than just the file spec?  (Every
  158.     >other field - well, every other field except the file id - requires
  159.     >access to the file's header.  Did DIRECTORY manage to access the
  160.     >header?)
  161.  
  162.     Ehhhhhh...  I'm afraid you've caught me out, here, Jerry.  I did ONLY
  163.     a "DIRECTORY" command and a "DIRECTORY filespec" command - didn't try
  164.     /DATE or /SIZE or any of the file-header-access-requiring qualifiers.
  165.     I'll try this and get back to this thread, if someone else doesn't
  166.     beat me to it as seems highly probable.
  167.  
  168. Well, no one has yet!
  169.  
  170.     >    I expect that this technique--
  171.     >
  172.     >     [...] 
  173.     >
  174.     >      c) would stymie any system manager, probably any CSC
  175.     >         representative, who hasn't read this post just now,
  176.     >    regardless of privs;
  177.     >
  178.     >Actually, I have serious doubts about c.  ANALYZE/DISK is pretty
  179.     >certain to check directory entries for validity.  Your munged entries
  180.     >will stand out like a sore thumb.  It's a good bet that
  181.     >ANALYZE/DISK/REPAIR would fix the invalid entries by removing them
  182.     >and then later noticing the files involved are lost and moving them
  183.     >to [SYSLOST].
  184.  
  185.     Didn't think of that.
  186.  
  187. That's how people get caught!  :-)  It's VERY hard to think of everything....
  188.  
  189.                    I can count the number of times I've done an
  190.     ANALYZE/DISK in my six-year VMS career (four of them as a system
  191.     manager of a very small system) on the fingers of one hand, and I
  192.     don't think  I've EVER used /REPAIR... 
  193.  
  194. I'm surprised.  You might want to try it - you'll probably recover some space.
  195. Almost every disk that's been in use for a while has some lost files on it
  196. SOMEWHERE....
  197.  
  198.     >If you want to hack with directory entries, there are plenty of other
  199.     >things you could do.  
  200.  
  201.     Some very interesting ideas, Jerry -- thanks!  I'll have to do some
  202.     "playing!" (Yeah, it WILL probably require me to use ANALYZE/DISK
  203.     again afterwards,  and maybe /REPAIR for the first time ;-) )
  204.  
  205.     > [...] you are safe only as long as the
  206.     >file isn't noticed.
  207.  
  208.     Ah, that's the bottom line, isn't it...  Sometimes the best place to
  209.     hide something is right out in plain sight... "The Purloined Letter"
  210.     taught us that, a long time ago... ;-)
  211.  
  212. Actually, the VMS file system, and security system in general, was DESIGNED to
  213. make it hard to hide things.  That's part of good security design.  For
  214. example, on RSTS you could (if privileged) mark any executable file as
  215. "privileged"; it would then run as a privileged program.  (This is similar to
  216. the Unix setuid bit.)  What this means is that, if I can momentarily get
  217. privileges, I can hid a program that will regain those privileges anywhere
  218. at all on the disk, under any innocent name I like.  If you let me remove a
  219. disk from the system and later put it back, I can take it to another system
  220. which lets me "diddle the bits" on the disk and do the same.  Finding my
  221. hidden privileged program would be a pain in the neck.  It can remain hidden
  222. on the disk for years, waiting for me to exploit it.
  223.  
  224. In VMS, on the other hand, the only way to make a program privileged is to
  225. INSTALL it.  To get my own file installed as privileged, I'd have to edit one
  226. of a small number of known command files (or modify an existing program that
  227. is already installed privileged).  Both of these are much harder to do, and
  228. much easier to find, than marking some innocuous file.  (Of course, there are
  229. other, more subtle things I could do - but let's not go into that here.)
  230.  
  231.     >BTW, it's not impossible that SOME invalid directory entries will
  232.     >could cause (probably non-fatal) bugchecks.  
  233.  
  234.     I remember seeing RMS bugs in the past that would delete the erring
  235.     process upon encountering certain errors in on-disk or file structure.
  236.     I was always surprised to find such dramatic bugs in RMS, an otherwise
  237.     extremely robust-seeming entity...  
  238.  
  239. Well, nothing's perfect.  RMS is a rather complicated piece of code.
  240.  
  241.     >Also, the future direction of VMS seems to be to forbid direct access
  242.     >to directory files (at least direct write access).  You could find
  243.     >your modified directory entries completely inaccessible after the
  244.     the next upgrade!
  245.  
  246.     That's VERY interesting!  At what level of the system would this be
  247.     implemented?  Disk driver (mark certain media blocks /NOWRITE)?
  248.     $QIO-ACP interface ("don't allow access to any file whose "I'm a
  249.     directory" bit is set")?  Write-Logical-(or-Physical)-Block $QIO
  250.     request?  Blocking directory-write access at any level would pose
  251.     difficulties and paradoxes.  For example, RMS needs to be able to
  252.     update directories, which would seem to preclude blocking
  253.     directory-writing at the driver or $QIO levels, but NOT blocking such
  254.     access at those levels would hardly prevent "illegal" modifications in
  255.     the intended manner, as simply bypassing RMS would be sufficient...
  256.     Ah well, some combination of access-mode and file-attribute check
  257.     could be applied that would at least make "illegal" modification MORE
  258.     DIFFICULT  than it is today.
  259.  
  260. The easiest way to do it would be to create directories with an access-mode
  261. restriction allowing access only from executive (or kernel) modes.  When you
  262. get down to the bottom level, the only way to access a file is through a
  263. channel, and channels have associated access levels.  The rule for access-mode
  264. restricted files would be that the mode of the channel must be at least as
  265. privileged as the mode of the file.  User-mode code can only create user-mode
  266. channels, so would not be able to get to a directory file directly.  This
  267. might be enforced by the driver, or I suppose the concept of access-mode
  268. restrictions might be extended to cover all devices, in which case it would
  269. be enforced by the I/O system in conjunction with the disk drivers.
  270.  
  271. RMS, running in executive mode, would have no trouble assigning an exec-mode
  272. channel to get to the directory file - in fact, it generally does that now.
  273. (Actually, the only change necessary would be for RMS to also check the access
  274. mode restriction on the file against the access mode of its caller, since RMS
  275. always opens exec-mode channels for files it is accessing for outer modes to
  276. prevent them from screwing around with files it is working on.  The UFO option
  277. (User File Open) gets around this....)
  278.                             -- Jerry
  279.  
  280.