13 comments

  • SoftTalker20 hours ago
    I had to use <i>ed</i> once in a very limited recovery situation. I don&#x27;t remember the details but even vi was not an option. It&#x27;s not terrible if you just need to change a few lines. Using it on a teletype to write code all day would get tedious quickly. Full-screen editors had to have been an amazing productivity boost.
    • b00ty4breakfast3 hours ago
      ed makes <i>a lot</i> more sense if you remember they were printing everything to paper rather than using a glass tty when it was first developed
    • irusensei6 hours ago
      I had to use it when I installed 9front on a computer that has no graphics card just a serial port (APU2C2). I had only a serial device at 9600bps and the other text editors (sam, acme) didn&#x27;t worked. I wanted to turn it into a CPU server so I can use drawterm to access it remotely and that requires editing a few files.
    • fooker20 hours ago
      The amount of code was relatively low.<p>Not the million line codebases we have today. 50-100 lines was the usual program or script.
      • avadodin17 hours ago
        iirc they were initially using actual ttys(as in typewriters) and the input delay was hell which is the reason so many UNIX commands are two letters.<p>So likely they would work on the printout:<p><pre><code> 1,$n </code></pre> And then input the corrections into ed(1).
        • fooker17 hours ago
          That was one generation before this. In unix v4 times, input latency was in the order of ~100ms, basically limited by the serial port.<p>Pretty advanced terminals were starting to show up too - <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;VT100" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;VT100</a>
  • mgerdts22 hours ago
    What is up with fin? Is it really just writing an int 0 in the memory right after some variable present in libc or similar?<p><pre><code> extern fin; if(getpw(0, pwbuf)) goto badpw; (&amp;fin)[1] = 0;</code></pre>
    • oguz-ismail222 hours ago
      Predecessor of<p><pre><code> extern FILE *stdin;</code></pre>
    • formerly_proven21 hours ago
      I’m guessing v4 C didn’t have structs yet (v6 C does, but struct members are actually in the global namespace and are basically just sugar for offset and a type cast; member access even worked on literals. That’s why structs from early unix APIs have prefixed member names, like st_mode.
      • topspin19 hours ago
        &gt; I’m guessing v4 C didn’t have structs yet<p>There may have been a early C without structs (B had none,) but according to Ken Thompson, the addition of structs to C was an important change, and a reason why his third attempt rewrite UNIX from assembly to a portable language finally succeeded. Certainly by the time the recently recovered v4 tape was made, C had structs:<p><pre><code> ~&#x2F;unix_v4$ cat usr&#x2F;sys&#x2F;proc.h struct proc { char p_stat; char p_flag; char p_pri; char p_sig; char p_null; char p_time; int p_ttyp; int p_pid; int p_ppid; int p_addr; int p_size; int p_wchan; int *p_textp; } proc[NPROC]; &#x2F;* stat codes *&#x2F; #define SSLEEP 1 #define SWAIT 2 #define SRUN 3 #define SIDL 4 #define SZOMB 5 &#x2F;* flag codes *&#x2F; #define SLOAD 01 #define SSYS 02 #define SLOCK 04 #define SSWAP 010</code></pre>
      • Boltgolt19 hours ago
        )
        • jacquesm17 hours ago
          Heh. I had the same impulse but then didn&#x27;t do it, upon refreshing the page your comment was there :)
    • flatline22 hours ago
      According to the chatbot, the first word of `fin` is the file descriptor, the second its state. &quot;Reset stdin’s flags to a clean state&quot;.
  • asveikau16 hours ago
    A bit of a code review (some details from the patch removed for clarity):<p><pre><code> + register int i; q = password; - while((*q = getchar()) != &#x27;\n&#x27;) + i = 0; + while((*q = getchar()) != &#x27;\n&#x27;) { + if (++i &gt;= sizeof(password)) + goto error; </code></pre> You don&#x27;t actually need i here. i is the same as (q - password). It would be idiomatic C to simply rewrite the loop condition as: while (q &lt; password+sizeof(password) &amp;&amp; (*q = getchar()) != &#x27;\n&#x27;). To preserve your &quot;goto error;&quot; part, maybe you could do the overflow check when null terminating outside the loop.
    • shakna15 hours ago
      Isn&#x27;t sizeof only standardised in C89? Wouldn&#x27;t shock me if this form needs to be an rvalue.<p>The author did try pointer arithmetic:<p>&gt; I initially attempted a fix using pointer arithmetic, but the 1973 C compiler didn’t like it, while it didn’t refuse the syntax, the code had no effect.
      • asveikau15 hours ago
        This surprised me too. The snippet I was quoting from was already using sizeof, though.<p>I missed the blurb about pointer arithmetic. Would be interesting to go into detail about what &quot;had no effect&quot; means.
  • WalterBright15 hours ago
    Back in the 80s, when I was writing a C compiler, C compilers typically had a maximum size for string literals. The behavior was to detect overflow, issue an error message, and fail compilation.<p>I took a different tack. The buffer was allocated with malloc. When a string was larger, it was realloced to a larger size. This worked until memory was exhausted, and then the program quit.<p>It was actually less code to implement than having a fixed size buffer.<p>Ditto for the other compilation limits, such as length of a line. The only limit was running out of memory.
  • serpent4 hours ago
    Are you sure any buffer overflows were actually fixed in 1973?
  • b-kuiper22 hours ago
    so, is there already somebody that wrote the exploit for it? are there any special things to consider exploiting such architecture back in the day or do the same basic principles apply?
    • MajesticHobo217 hours ago
      Yeah, somebody came up with one here: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46469897">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46469897</a>
    • b-kuiper22 hours ago
      EDIT: removed due to low effort and mark-up issues. thank you all for your feedback.
      • b-kuiper22 hours ago
        perhaps the downvoters can tell me why they are downvoting? i&#x27;m curious to hear whether if this would work on unix v4 or whether there are special things to consider. I thought i would ask claude for a basic example so people could perhaps provide feedback. i guess people consider it low effort reply? anyway, thanks for your input.
        • csnover21 hours ago
          Your response is a non-sequitur that does not answer the question you yourself posed, and you are responding to yourself with a chatbot. Given that it is a non-sequitur, presumably it is also the case that no work was done to verify whether the output of the LLM was hallucinated or not, so it is probably also wrong in some way. LLMs are token predictors, not fact databases; the idea that it would be reproducing a “historical exploit” is nonsensical. Do you believe what it says because it says so in a code comment? Please remember what LLMs are actually doing and set your expectations accordingly.<p>More generally, people don’t participate in communities to have conversations with someone else’s chatbot, and especially not to have to vicariously read someone else’s own conversation with their own chatbot.
        • AgentME21 hours ago
          The explanation it gives at the start appears to be on the right track but then the post has two separate incomplete&#x2F;flawed attempts at coding it. (The first one doesn&#x27;t actually put the expected crypt() output in the payload, and the second one puts null bytes in the password section of the payload where they can&#x27;t go.)
        • MaulingMonkey21 hours ago
          &gt; perhaps the downvoters can tell me why they are downvoting?<p>Not one of the actual downvoters, but:<p>Lack of proper indenting means your code as posted doesn&#x27;t even compile. e.g. I presume there was a `char* p;` that had `*` removed as markdown.<p>Untested AI slop code is gross. You&#x27;ve got two snippets doing more or less the same thing in two different styles...<p>First one hand-copies strings character by character, has an incoherent explaination about what `pwbuf` actually is (comment says &quot;root::&quot;, code actually has &quot;root:k.:\n&quot;, but neither empty nor &quot;k.&quot; are likely to be the hash that actually matches a password of 100 spaces plus `pwbuf` itself, which is presumably what `crypt(password)` would try to hash.)<p>Second one is a little less gross, but the hardcoded `known_hash` is again almost certainly incorrect... and if by some miracle it was accurate, the random unicode embedded would cause source file encoding to suddenly become critical to compiling as intended, plus the `\0`s written to `*p` mean su.c would hit the `return;` here before even attempting to check the hash, assuming you&#x27;re piping the output of these programs to su:<p><pre><code> while((*q = getchar()) != &#x27;\n&#x27;) if(*q++ == &#x27;\0&#x27;) return; </code></pre> A preferrable alternative to random nonsensical system specific hardcoded hashes would be to simply call `crypt` yourself, although you might need a brute force loop as e.g. `crypt(password);` in the original would presumably overflow and need to self-referentially include the `pwbuf` and thus the hash. That gets messy...
          • avadodin18 hours ago
            crypt is defined in assembly at s3 crypt.s and it would appear to use the same family of &quot;cryptographic machine&quot; as V6&#x27;s crypt.c but it is even shorter and I can&#x27;t tell if it has bounds checks or not — V6 limits output size to 512.<p><i>edit:</i> if hash output length is variable it may be impossible to find a solution and then a side channel timing attack is probably the best option.
            • avadodin13 hours ago
              someone liked this but note that someone else had already determined it is limited to 64 bytes on a previous HN post so the overflow hack does work.
  • w-m19 hours ago
    The password and pwbuf arrays are declared one right after the other. Will they appear consecutive in memory, i.e. will you overwrite pwbuf when writing past password?<p>If so, could you type the same password that’s exactly 100 bytes twice and then hit enter to gain root? With only clobbering one additional byte, of ttybuf?<p>Edit: no, silly, password is overwritten with its hash before the comparison.
    • loeg17 hours ago
      &gt; will you overwrite pwbuf when writing past password?<p>Right.<p>&gt; If so, could you type the same password that’s exactly 100 bytes twice and then hit enter to gain root? With only clobbering one additional byte, of ttybuf?<p>Almost. You need to type crypt(password) in the part that overflows to pwbuf.
  • nineteen99922 hours ago
    Already patched this on my x86_64 v4 UNIX port. Hehe.
    • nullpoint4202 hours ago
      That sounds really fun!
    • retrac14 hours ago
      &gt; x86_64 v4 UNIX port<p>What compiler are you using?
      • nineteen99912 hours ago
        gcc. Im also working on a port of the original compiler, but that&#x27;s a much lower priority for me.
  • WalterBright15 hours ago
    Having a buffer with a fixed size is always a red flag for further checking.
  • ChrisArchitect22 hours ago
    Related:<p><i>An initial analysis of the discovered Unix V4 tape</i><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46367744">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46367744</a><p><i>Unix v4 (1973) – Live Terminal</i><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46468283">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46468283</a>
  • emilfihlman8 hours ago
    The source has<p>ttybuf[2] =&amp; ~010;<p>Which is another bug.
    • messe7 hours ago
      What&#x27;s the bug? If you&#x27;re referring to the =&amp; syntax, then that&#x27;s just how &amp;= used to be written in older versions of C.
  • kazinator19 hours ago
    Remotely exploiting a buffer overflow in Unix like it&#x27;s 1973.<p># ... sound of crickets ...<p>Wanna see me do it again?
    • nineteen99912 hours ago
      Remotely? ... this version of UNIX doesn&#x27;t have any networking.