The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-11 17:08 Noel Chiappa
  2017-05-11 21:34 ` Dave Horsfall
  0 siblings, 1 reply; 77+ messages in thread
From: Noel Chiappa @ 2017-05-11 17:08 UTC (permalink / raw)


    > From: Warner Losh

    > There's a dcheck.c in the TUHS v7 sources. How's that related?

That was one of the earlier tools - not sure how far back it goes, but it's in
V6, but not V5. It consistency checks the directory tree. Another tool, 'icheck',
consistency checks file blocks and the free list.

	Noel



^ permalink raw reply	[flat|nested] 77+ messages in thread
[parent not found: <mailman.1.1494986402.2329.tuhs@minnie.tuhs.org>]
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-16 13:20 Noel Chiappa
  2017-05-16 13:46 ` Clem Cole
  0 siblings, 1 reply; 77+ messages in thread
From: Noel Chiappa @ 2017-05-16 13:20 UTC (permalink / raw)


    > From: "Steve Johnson"

    > a DEC repairperson showed up to do "preventive maintenance" and managed
    > to clobber the nascent file system.
    > Turns out DEC didn't have any permanent file systems on machines that
    > small...

A related story (possibly a different version of this one) which I read (can't
remember where, now) was that he trashed the contents of the RS04 fixed-head
hard disk, because on DEC OS's, those were only used for swapping.

	Noel


^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-14 21:44 Noel Chiappa
  0 siblings, 0 replies; 77+ messages in thread
From: Noel Chiappa @ 2017-05-14 21:44 UTC (permalink / raw)


    > From: Random832

    > Ah. There's the other piece. You start the SUID program under the
    > debugger, and ... it simply starts it non-suid. *However*, in the
    > presence of shared text ...  you can make changes to the text image
    > ... which will be reused the *next* time it is started *without* the
    > debugger.

So I actually tried to do this (on a V6 system running on an emulator), after
whipping up a tiny test program (which prints "1", and the real and current
UIDs): the plan was to patch it to print a different number.

However, after a variety of stubbed toes and hiccups (gory details below, if
anyone cares), including a semi-interesting issue with the debugger and pure
texts), I'm punting: when trying to set a breakpoint in a pure text, I get the
error message "Can't set breakpoint", which sort of correlates with the
comment in the V6 sig$ptrace(): "write user I (for now, always an error)".

So it's not at all clear that the technique we thought would work would, in
fact, work - unless people weren't using a stock V6 system, but rather one
that had been tweaked to e.g. allow use of debuggers on pure-text programs
(including split I+D).

It's interesting to speculate on what the 'right' fix would be, if somehow the
techique above did work. The 'simple' fix, on systems with a PWB1-line XWRIT
flag, would be to ignore SETUID bits when doing an exec() of a pure text that
had been modified. But probably 'the' right fix would be to give someone
debugging a pure-text program their own private copy of the text. (This would
also prevent people who try to run the program from hitting breakpoints while
it's being debugged. :-)


But anyway, it's clear that back when, when I thought I'd found the bug, I
clearly hadn't - which is why when I looked into the source, it looked like it
had been 'already' been fixed. (And why Jim G hemmed and hawed...)

But I'm kind of curious about that mod in PWB1 that writes a modified pure
text back to the swap area when the last process using it exits. What was the
thinking behind that? What's the value to allowing someone to patch the
in-core pure text, and then save those patches? And there's also the 'other
people who try and run a program beind debugged are going to hit breakpoints'
issue, if you do allow writing into pure texts...


	Noel


--------


For the gory details: to start with, attempting to run a pure-text program
(whether SUID or not) under the debugger produced a "Can't execute
{program-name} Process terminated."  error message.

'cdb' is printing this error message just after the call to exec() (if that
fails, and returns). I modified it to print the error number when that
happens, and it's ETXTBSY. I had a quick look at the V6 source, to see if I
could see what the problem is, and it seems to be be (in sys1$exec()):

    if(u.u_arg[1]!=0 && (ip->i_flag&ITEXT)==0 && ip->i_count!=1) {
		     u.u_error = ETXTBSY;
			       goto bad;
			       }

What that code does is a little obscure; I'm not sure I understand it. The
first term checks to see if the size of the text segment is non-zero (which it
is not, in both 0407 and 0410 files). The second is, I think, looking to see
if the inode is marked as being in use for a pure text (which it isn't, until
later in exec()). The third checks to make sure nobody else is using the file.

So I guess this prevents exec() of a file which is already open, and not for a
pure text. (Why this is the Right Thing is not instantly clear to me...)

Anyway, the reason this fails under 'cdb' is that the debugger already has it
open (to be able to read the code). So I munged the debugger to close it
before doing the exec(), and then the error went away.

Then I ran into a long series of issues, the details of which are not at all
interesting, connected with the fact that the version of 'cdb' I was using
(one I got off a Tim Shoppa modified V6 disk) doesn't correspond to either of
the sources I have for 'cdb'.

When I switched to the latest source (so I could fix the issue above), it had
some bug where it wouldn't work unless there was a 'core' file. But eventually
I kludged it enough to get the 'can't set breakpoints' message, at which point
I threw in the towel.



^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-13  1:25 Noel Chiappa
  0 siblings, 0 replies; 77+ messages in thread
From: Noel Chiappa @ 2017-05-13  1:25 UTC (permalink / raw)


    > From: Random832

    > It seems to me that this check is central to being able to (or not)
    > modify the in-core image of any process at all other than the one being
    > traced (say, by attaching to a SUID program that has already dropped
    > privileges, and making changes that will affect the next time it is
    > run).

Right, good catch: if you have a program that was _both_ sticky and SUID, when
the system is idle (so the text copy in the swap area won't get recycled),
call up a copy under the debugger, patch it, exit (leaving the patched copy),
and then re-run it without the debugger.

I'd have to check the handling of patched sticky pure texts - to see if they
are retained or not.

{Checks code.}

Well, the code to do with pure texts is _very_ different between V6 and
PWB1.

The exact approach above might not work in V6, because the modified (in-core)
copy of pure texts are simply deleted when the last user exits them. But it
might be possible for a slight variant to work; leave the copy under the
debugger (which will prevent the in-core copy from being discarded), and then
run it again without the debugger. That might do it.

Under PWB1, I'm not sure if any variant would work (very complicated, and I'm
fading). There's an extra flag bit, XWRIT, which is set when a pure text is
written into; when the last user stops using the in-code pure text, the
modified text is written to swap.  (It lools like the in-core copy is always
discarded when the last user stops using it.) But the check for sticky would
probably stop a sticky pure-text being modified? But maybe the approach that
seems like it would work under V6 (leave the patched, debugger copy running,
and start a new instance) looks like it should work here too.

So maybe the sticky thing is irrelevant? On both V6 and PWB1, it just needs a
pure text which is SETUID: start under the debugger, patch, leave running, and
start a _new_ copy, which will run the patched version as the SUID user.

      Noel



^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-13  0:44 Noel Chiappa
  2017-05-13  0:51 ` Random832
  0 siblings, 1 reply; 77+ messages in thread
From: Noel Chiappa @ 2017-05-13  0:44 UTC (permalink / raw)


    > From: Dave Horsfall

    > Err, isn't that the sticky bit, not the setuid bit?

Oh, right you are. I just looked in the code for ptrace(), and assumed that
was it.

The fix is _actually_ in sys1$exec() (in V6) and sys1$getxfile() (in PWB1 and
the MIT system:

	/*
	 * set SUID/SGID protections, if no tracing
	 */

	if ((u.u_procp->p_flag&STRC)==0) {
                if(ip->i_mode&ISUID)
			if(u.u_uid != 0) {
				u.u_uid = ip->i_uid;
				u.u_procp->p_uid = ip->i_uid;
				}

The thing is, this code is identical in V6, PWB1, and MIT system!?

So now I'm wondering - was this really the bug? Or was there some
bug in ptrace I don't see, which was the actual bug that's being
discussed here.

Because is sure looks like this would prevent the exploitation that I
described (start an SUID program under the debugger, then patch the code).

Or perhaps somehow this fix was broken by some other feature,, and that
introduced the exploit?

	  Noel


^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-12 23:30 Noel Chiappa
  2017-05-12 23:38 ` Dave Horsfall
  2017-05-13  0:22 ` Clem Cole
  0 siblings, 2 replies; 77+ messages in thread
From: Noel Chiappa @ 2017-05-12 23:30 UTC (permalink / raw)


    > From: Clem Cole

    > I said -- profil - I intended to say  ptrace(2)

Is that the one where running an SUID program under the debugger allowed one
to patch the in-core image of said program?

If so, I have a story, and a puzzle, about that.


A couple of us, including Jim Gettys (later of X-windows fame) were on out way
out to dinner one evening (I don't recall when, alas, but I didn't meet him
until '80 or so), and he mentioned this horrible Unix security bug that had
just been found. All he would tell me about it (IIRC) was that it involved
ptrace.

So, over dinner (without the source) I figured out what it had to be:
patching SUID programs. So I asked him if that was what it was, and I don't
recall his exact answer, but I vaguely recall he hemmed and hawed in a way
that let me know I'd worked it out.

So when we got back from dinner, I looked at the source to our system to see
if I was right, and.... it had already been fixed! Here's the code:

	if (xp->x_count!=1 || xp->x_iptr->i_mode&ISVTX)
		goto error;

Now, we'd been running that system since '77 (when I joined CSR), without any
changes to that part of the OS, so I'm pretty sure this fix pre-dates your
story?

So when I saw your email about this, I wondered 'did that bug get fixed at
MIT when some undergrad used it to break in' (I _think_ ca. '77 is when they
switched from an OS called Delphi on the -11/45 used for the undergrad CS
programming course - I _think_ they switched that machine from Delphi to
Unix), or did it come with PWB1? (Like I said, that system was mostly PWB1.)

So I just looked in the PWB1 sources, and... there it is, the _exact_ same
fix. So we must have got it from PWB1.

So now the question is: did the PWB guys find and fix this, and forget to
tell the research guys? Or did they tell them, and the research guys blew
them off? Or what?

	Noel


^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-12 18:43 Doug McIlroy
  2017-05-12 18:56 ` Dan Cross
  0 siblings, 1 reply; 77+ messages in thread
From: Doug McIlroy @ 2017-05-12 18:43 UTC (permalink / raw)



>  We all took the code back and promised to get patches out ASAP and not tell any one about it.

Fascinating. Chnages were installed frequently in the Unix lab, mostly
at night without fanfare. But an actual zero-day should have been big
enough news for me to have heard about. I'm pretty sure I didn't; Dennis
evidently kept his counsel.

Doug


^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-12 15:12 Noel Chiappa
  2017-05-12 15:17 ` Clem Cole
  0 siblings, 1 reply; 77+ messages in thread
From: Noel Chiappa @ 2017-05-12 15:12 UTC (permalink / raw)


    > From: "Ron Natalie"

    > Ordered writes go back to the original BSD fast file system, no?  I seem
    > to recall that when we switched from our V6/V7 disks, the filesystem got
    > a lot more stable in crashes.

I had a vague memory of reading about that, so I looked in the canonical FFS
paper (McKusick et al, "A Fast File System for UNIX" [1984)]) but found no
mention of it.

I did find a paper about 'fsck' (McKusick, Kowalski, "Fsck: The UNIX File
System Check Program") which talks (in Section 2.5. "Updates to the file
system") about how "problem[s] with asynchronous inode updates can be avoided
by doing all inode deallocations synchronously", but it's not clear if they're
talking about something that was actually done, or just saying
(hypothetically) that that's how one would fix it.

Is is possible that the changes to the file system (e.g. the way free blocks
were kept) made it more crash-proof?

     Noel



^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-11 14:07 Noel Chiappa
  2017-05-11 14:21 ` Larry McVoy
  2017-05-11 16:15 ` Clem Cole
  0 siblings, 2 replies; 77+ messages in thread
From: Noel Chiappa @ 2017-05-11 14:07 UTC (permalink / raw)


    > From: Clem Cole

    > it was was originally written for the for the 6th edition FS (which I
    > hope I have still have the sources in my files) ...
    > I believe Noel recovered a copy in his files recently.

Well, I have _something_. It's called 'fcheck', not 'fsck', but it looks like
what we're talking about - maybe it was originally named, or renamed, to be in
the same series as {d,i,n}check? But it does have the upper-case error
messages... :-) Anyway, here it is:

  http://ana-3.lcs.mit.edu/~jnc/tech/unix/s1/fcheck.c
  http://ana-3.lcs.mit.edu/~jnc/tech/unix/man8/fcheck.8

Interestingly, the man page for it makes reference to a 'check' command, which
I didn't recall at all; here it is:

  http://ana-3.lcs.mit.edu/~jnc/tech/unix/s1/check.c
  http://ana-3.lcs.mit.edu/~jnc/tech/unix/man8/check.8

for those who are interested.


    > Noel has pointed out that MIT had it in the late 1970s also, probably
    > brought back from BTL by one of their summer students.

I think most of the Unix stuff we got from Bell (e.g. the OS, which is clearly
PWB1, not V6) came from someone who was in a Scout unit there in high school,
of all bizarre connections! ISTR this came the same way, but maybe I'm wrong.
It definitely arrived later than the OS - we'd be using icheck/dcheck for
quite a while before it arrived - so maybe it was another channel?

The only thing that for sure (that I recall) that didn't come this way was
Emacs. Since the author had been a grad student in our group at MIT, I think
you all can guess how we got that!

	Noel



^ permalink raw reply	[flat|nested] 77+ messages in thread
* [TUHS] The evolution of Unix facilities and architecture
@ 2017-05-10 14:08 Diomidis Spinellis
  2017-05-10 14:38 ` Steffen Nurpmeso
  2017-05-11  0:49 ` Clem Cole
  0 siblings, 2 replies; 77+ messages in thread
From: Diomidis Spinellis @ 2017-05-10 14:08 UTC (permalink / raw)


I've made available on GitHub a series of tables showing the evolution 
of Unix facilities (as documented in the man pages) over the system's 
lifetime [1] and two diagrams where I attempted to draw the 
corresponding architecture [2].  I've also documented the process in a 
short blog post [3].  I'd welcome any suggestions for corrections and 
improvements you may have, particularly for the architecture diagrams.

[1] https://dspinellis.github.io/unix-history-man/
[2] https://dspinellis.github.io/unix-architecture/
[3] https://www.spinellis.gr/blog/20170510/

Cheers,

Diomidis



^ permalink raw reply	[flat|nested] 77+ messages in thread

end of thread, other threads:[~2017-05-19 14:31 UTC | newest]

Thread overview: 77+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 17:08 [TUHS] The evolution of Unix facilities and architecture Noel Chiappa
2017-05-11 21:34 ` Dave Horsfall
     [not found] <mailman.1.1494986402.2329.tuhs@minnie.tuhs.org>
2017-05-19 14:31 ` David
  -- strict thread matches above, loose matches on Subject: below --
2017-05-16 13:20 Noel Chiappa
2017-05-16 13:46 ` Clem Cole
2017-05-14 21:44 Noel Chiappa
2017-05-13  1:25 Noel Chiappa
2017-05-13  0:44 Noel Chiappa
2017-05-13  0:51 ` Random832
2017-05-13  0:55   ` Dave Horsfall
2017-05-13  1:17   ` Chris Torek
2017-05-13 15:25   ` Steve Simon
2017-05-13 16:55     ` Clem Cole
2017-05-13 17:19       ` William Pechter
2017-05-14 12:55         ` Derek Fawcus
2017-05-14 22:12           ` Dave Horsfall
2017-05-15  1:24             ` Nemo
2017-05-15 18:00               ` Steve Johnson
2017-05-16 22:33                 ` Ron Natalie
2017-05-16 23:13                   ` Arthur Krewat
2017-05-16 23:18                     ` Ron Natalie
2017-05-13 23:01     ` Dave Horsfall
2017-05-12 23:30 Noel Chiappa
2017-05-12 23:38 ` Dave Horsfall
2017-05-12 23:52   ` Random832
2017-05-13  0:26     ` Dave Horsfall
2017-05-13  0:48       ` Random832
2017-05-13  0:22 ` Clem Cole
2017-05-13  0:23   ` Clem Cole
2017-05-12 18:43 Doug McIlroy
2017-05-12 18:56 ` Dan Cross
2017-05-12 19:43   ` Clem Cole
2017-05-12 20:06     ` Clem Cole
2017-05-12 20:40       ` Jeremy C. Reed
2017-05-12 21:29         ` Clem Cole
2017-05-12 21:29   ` Ron Natalie
2017-05-12 15:12 Noel Chiappa
2017-05-12 15:17 ` Clem Cole
2017-05-12 15:18   ` Clem Cole
2017-05-12 15:46     ` Clem Cole
2017-05-11 14:07 Noel Chiappa
2017-05-11 14:21 ` Larry McVoy
2017-05-11 16:17   ` Clem Cole
2017-05-11 17:11     ` Michael Kjörling
2017-05-11 21:44       ` Dave Horsfall
2017-05-11 22:06         ` Warner Losh
2017-05-12  6:24         ` Hellwig Geisse
2017-05-12 21:12           ` Dave Horsfall
2017-05-12 23:25             ` Hellwig Geisse
2017-05-11 16:15 ` Clem Cole
2017-05-11 16:52   ` Warner Losh
2017-05-11 17:12     ` Clem Cole
2017-05-11 20:37       ` Ron Natalie
2017-05-11 22:25         ` Larry McVoy
2017-05-11 22:30           ` Ron Natalie
2017-05-11 23:47           ` Dave Horsfall
2017-05-11 23:48             ` Ron Natalie
2017-05-12  0:21               ` Larry McVoy
2017-05-12  2:42                 ` Warner Losh
2017-05-12  0:16             ` Larry McVoy
2017-05-12  1:41               ` Wesley Parish
2017-05-12  1:05             ` Toby Thain
2017-05-12  8:17               ` Michael Kjörling
2017-05-12 13:56                 ` Tim Bradshaw
2017-05-12 14:22                   ` Michael Kjörling
2017-05-12 14:30                   ` Larry McVoy
2017-05-12 15:11                     ` Tim Bradshaw
2017-05-12 15:52                     ` Chet Ramey
2017-05-12 16:21                       ` Warner Losh
2017-05-12  8:15             ` Harald Arnesen
2017-05-14  4:30           ` Theodore Ts'o
2017-05-14 17:40             ` Clem Cole
2017-05-10 14:08 Diomidis Spinellis
2017-05-10 14:38 ` Steffen Nurpmeso
2017-05-10 23:09   ` Erik Berls
2017-05-11 12:40     ` Steffen Nurpmeso
2017-05-11  0:49 ` Clem Cole

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).