Live data from Hacker News

Task_t considered harmful

googleprojectzero.blogspot.com

41–50 of 89 posts

Re: Task_t considered harmful

#41
post #38

Earlier quoted context omitted.

Apple needs to take a bit of those tens of billions of dollars they have sitting around and spend it on starting from scratch with something that's not horrifically crufty. The quality of their software is lagging so far behind the quality of their hardware right now. Realistically, I think we may just be at the point where operating systems and all the stuff the companies put on top of them are too complicated to ke…

Hundreds of billions?

Yep, $237.6B in cash and equivalents

http://blogs.marketwatch.com/thetell/2016/10/25/apple-earnin...

Re: Task_t considered harmful

#43
Bug 1: Many XNU drivers save task_t's on the heap without bumping their refcount.

    1. Attacker creates process A and B
    2. B->A send task port Bt
    3. A->XNU request IOKit framebuffer client for Bt
    4. A ditches Bt, retains client
    5. Kill B; Bt in client now dangling
    6. Trigger creation of privileged C, unrelated to A & B
    7. C inherits memory once used by Bt
    8. A use retained framebuffer client to write C's memory
What's important to understand is that this is not just a single UAF, but a pattern of UAFs scattered throughout XNU.

Fix: at step 3, check to make sure the task being given to IOKit is owned by the task making the IOKit request.

Bug 2: IOKit drivers cache task details on their stack; the lifetime of that cached task is the lifetime of the IOKit kernel object, not of the program that made the request. In particular: if you execve() an SUID, the task_t is repurposed.

    1. Attacker creates process A and B
    2. B->XNU request IOKit framebuffer for Bt, Bc
    3. B->A send client Bc
    4. B execve /bin/su. B is now running as root.
    5. A use retained framebuffer client to write B's memory
The tricky thing here is that this isn't just one bug, but a pattern of bugs: every place where a driver stashes a task_t on the heap and exposes functionality through a passable object is a place where colluding processes can potentially take advantage of SUIDs to raise privileges.

Fix: Lifetime of IOKit clients now tied to lifetime of creating process.

Bug 3: Even if a driver doesn't save a task_t on the heap, they're saved on the stack during the servicing of system calls and kernel mach message handlers, so there are race conditions.

    1. Attacker creates process A and B
    2. B->A send task port Bt
    3a. A->XNU task_threads(Bt), retrieving thread ports for Bt
    3b. (simultaneously) execve /bin/su. B is now running as root.
    4a. task_threads converts Bt to a task_t
    4b. execve modifies the same task_t to replace thread ports
    4c. task_threads retrieves the (now privileged) thread ports.
    5. A uses thread ports to overwrite registers and take control of B.
Fix: Kernel objects now check to see if a task_t has been touched by execve before returning them to userland. Even if you win the race, that failsafe prevents the kernel from giving you privileged objects.

Bug 4: You don't need the kernel to give you a privileged object directly; all you need is to be able to influence a privileged object.

    1. Attacker creates process A and B
    2. B->A send task port Bt
    3a. A->XNU task_set_exception_port(Bt), wiring A to B's exceptions
    3b. (simultaneously) execve /bin/su with rlimited stack. B is now running as root, briefly.
    4a. task_set_exception_port converts Bt to a task_t
    4b. execve modifies the same task_t to replace thread ports
    4c. task_set_exception_port rewrites the exception port.
    5. stack access in B, running /bin/su as root, causes a SEGV
    6. XNU generates an exception message, passing with it the thread ports, to A    
    7. A uses thread ports to overwrite registers and take control of B.
Fix: table flip. Rewrite execve so it generates entirely new task_ts when loading binaries, rather than repurposing old task_t.

This is all pretty magnificent. What's best about it is that it totally justifies the title of the post: pretty much every place in XNU where they save a task_t creates a TOCTTOU bug.

Re: Task_t considered harmful

#44
post #33
post #28

“Considered Harmful” Essays Considered Harmful ( http://meyerweb.com/eric/comment/chech.html )

Why are you linking to an harmful essay then?

Because human brains are pattern-matching engines; parent comment saw the phrase "considered harmful", didn't read the article, and linked a previously-read article that they presumed was related based on the title alone.

Re: Task_t considered harmful

#45

Can someone explain what this means for the end user?

It's a pattern of privilege escalation bugs. If you run untrusted code on your machine, that code can obtain root or alter the kernel, potentially even if it's running as nobody.

There is a relatively long sequence of attempts to band-aid the bug, all of which failed, because Ian Beer found a systemic flaw, not just a single point flaw. So, the other implication for users is a general sense of foreboding.

Re: Task_t considered harmful

#46
post #11

Copying my comment from the earlier submission that didn't gain much traction here: What an absolutely amazing tour-de-force of a devastating design flaw in all versions of macOS and iOS and tvOS and watchOS! The negotiations detailed in the bug report timeline about meetings between "senior apple and google leadership" for keeping this secret past the general deadline really underlines that.

Yeah - the failed mitigations followed by a "long term" fix was interesting as well. Apple literally had to change execve() this late in the OS's development cycle to allocate new task and thread structs(that's two extra allocations and copies in hot path!) to fix it for good. That this design problem lingered around for so long doesn't look good for Apple - it's one thing for a use after free bug in obscure piece of…

This is kind of a "perfect storm" situation for Apple. At least three vectors are converging:

1. Apple inherited OSX from NeXT, and with it the Mach subsystem. Mach overcomplicates XNU.

2. XNU has become incredibly popular by dint of being shipped in the iPhone. Avie Tevanian probably did not see that coming when they designed the original BSD/Cocoa/XNU/whatever architecture. Regardless: it is now difficult to make sweeping architectural changes in XNU, because of the enormous installed base.

3. Ian Beer is simultaneously very clever and also willing to wade into the XNU Mach fire swamp.

I think it's fair to criticize Apple for designing the XNU frankenkernel. I think it's less legit to say that the presence of this bug class "looks bad" --- it's 2016 and this is just getting published. This is one of those bug classes that is sort of obvious in retrospect, and you wonder why people didn't catch it earlier.

Re: Task_t considered harmful

#47
post #38

Earlier quoted context omitted.

Business as usual with macOS. The other day I was browsing the ocspd source code. Turns out it calls openssl using system(). So openssl is officially deprecated on macOS and yet they're using it internally to handle certificates?! And there's an enlightening comment: /* Given a path to a DER-encoded CRL file and a path to a PEM-encoded * CA issuers file, use OpenSSL to validate the CRL. This is a hack, * necessitated…

Apple needs to take a bit of those tens of billions of dollars they have sitting around and spend it on starting from scratch with something that's not horrifically crufty. The quality of their software is lagging so far behind the quality of their hardware right now. Realistically, I think we may just be at the point where operating systems and all the stuff the companies put on top of them are too complicated to ke…

So far as the current state of the art in computer engineering goes, we don't know how to completely rewrite a system as complicated as XNU without creating fresh batches of implementation errors. So this is a little like suggesting Apple use its hundreds of billions of dollars to build an iPhone battery that only needs to be recharged once a month.

We may someday get an XNU rewrite, but probably not until software engineering produces a new approach to building complex systems reliably that works at the scale (here: number of developers and shipping schedule) Apple needs.

Re: Task_t considered harmful

#48

Interesting timeline stuff here: https://bugs.chromium.org/p/project-zero/issues/detail?id=83...

It's funny, but I think it's written that way on purpose, not just as snark.

It's a little tricky to keep track of what happened here. There are 4 bugs in this post, and (I think) 2 different timelines: the UAF timeline for the first bug, and the TOCTTOU timeline for the 3 subsequent bugs. What's important to understand about the three TOCTTOU bugs is that there's a "right" fix for that bug, and a series of wrong fixes that delay the inevitable. Ian Beer and GPZ probably go into this whole process knowing what the right fix is, and with predictions on how they'll defeat any of the wrong fixes.

So it looks like GPZ reported a bug and then found flaws in the mitigations, but really all three of the flaws they found were known, at least conceptually, when GPZ reported the TOCTTOU race to Apple.

In the TOCTTOU timeline, Apple got an extension. Subtextually, it sounds like Tim Cook called Sundar Pichai. GPZ does not want to give extensions. They have a 90 day disclosure timeline, it's very well known, and probably the healthiest disclosure process in the industry. It's problematic for GPZ to give extensions because next time Tavis Ormandy finds a vulnerability in Norton Antivirus, Symantec is going to try to play chicken, and GPZ doesn't want to be at day 89 having to decide whether to drop zero-day versus being held hostage by a patch schedule.

But if a bug escalates all the way to Tim Cook, GPZ is probably pretty OK just with the degree to which that raises the profile of their bug --- it's hard to look at that and think Apple isn't taking your bug extremely seriously. So they'll trade the raised profile for the 5 week extension.

So they include a bunch of fuck-yous to Apple in the disclosure timeline, messaging to other vendors that GPZ is not going to budge even if your dumb original fix turns out to have a flaw that Ian Beer will notice and exploit. If you want the extension, you'd better have a Tim Cook.

Or maybe they're just having fun. Either way, a good read!

Re: Task_t considered harmful

#49
post #11

Copying my comment from the earlier submission that didn't gain much traction here: What an absolutely amazing tour-de-force of a devastating design flaw in all versions of macOS and iOS and tvOS and watchOS! The negotiations detailed in the bug report timeline about meetings between "senior apple and google leadership" for keeping this secret past the general deadline really underlines that.

Yeah - the failed mitigations followed by a "long term" fix was interesting as well. Apple literally had to change execve() this late in the OS's development cycle to allocate new task and thread structs(that's two extra allocations and copies in hot path!) to fix it for good. That this design problem lingered around for so long doesn't look good for Apple - it's one thing for a use after free bug in obscure piece of…

>(that's two extra allocations and copies in hot path!)

I've never really thought of process spawning as a hot-path (in the hundreds+ of calls per second sense). What software so heavily relies on spawning so many processes so quickly that the overhead of malloc would be noticeable?

Re: Task_t considered harmful

#50
post #49

Earlier quoted context omitted.

Yeah - the failed mitigations followed by a "long term" fix was interesting as well. Apple literally had to change execve() this late in the OS's development cycle to allocate new task and thread structs(that's two extra allocations and copies in hot path!) to fix it for good. That this design problem lingered around for so long doesn't look good for Apple - it's one thing for a use after free bug in obscure piece of…

>(that's two extra allocations and copies in hot path!) I've never really thought of process spawning as a hot-path (in the hundreds+ of calls per second sense). What software so heavily relies on spawning so many processes so quickly that the overhead of malloc would be noticeable?

Yeah, I don't see the hot path problem either. I think the bigger issue is doing deep brain surgery on XNU as a hotfix; it's the kind of thing you want to put off for a next major release.
Post reply on HN