🦣 @dalias@hachyderm.io 🦣 Profile picture
Nov 4, 2022 8 tweets 2 min read Read on X
So today #musl discovered a longstanding 🤦🤦🤦 bug in Linux's ELF loader...
For whatever reason, Linux has two copies of the ELF loading code in binfmt_elf.c, one for the main program and the other for the "program interpreter" (dynamic linker). The former handles BSS right but the latter doesn't.
ELF program LOAD segments can have p_memsz>p_filesz, representing a mapping larger in memory than in the image on disk, with the remainder zero-filled (mapping zero paged if needed).
For the main program, Linux handles this fine. But for the interpreter, it only maps p_filesz, not p_memsz. Then, at the very end, it goes back and performs one additional mapping for the remaining "bss" if needed.
This happens to work if there's only one data segment mapping that utilizes p_memsz>p_filesz, or if where the page boundaries fall make it so that no additional mapping is needed.
Unfortunately, lld wants to make multiple LOAD segments with data, one for the GOT and related machinery, and the other for actual program data. In this case, the kernel just doesn't map enough memory for the GOT, and process crashes (in ldso) on entry. 🤦
I think Linux may also be failing to do the right zero-fill (leaving junk mapped from disk present) even when it's not crossing a page boundary. Depending on what the linker did (e.g. if it put data segment before GOT seg rather than after), this could cause severe malfunctions.
The kernel has apparently always had this brokenness, and kernels in the wild will have it for decades to come. So does lld need to stop generating such output? Or should ldso do some workaround on itself in case it was linked this way?

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with 🦣 @dalias@hachyderm.io 🦣

🦣 @dalias@hachyderm.io 🦣 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @RichFelker

Nov 3, 2022
Spicy take: spatial memory unsafety (ala the OpenSSL bug) is a nearly solved problem in C with modern tooling and could be even moreso with a little effort. Temporal memory unsafety is the only hard part and where memory safe languages shine...
..but the need for temporal memory safety can be largely avoided with programming styles that just don't use complicated object lifetimes.
Re: spatial unsafety, one observation I noticed again in the OpenSSL bug was that, even in the presence of ssp, there's a risk that overflows clobber pointers other than the return address before overflow is caught at return...
Read 5 tweets
Oct 26, 2022
On the verge of Twitter possibly becoming (even more of a) cesspit, and folks rushing to offer inadequate alternatives, some thoughts on what value Twitter has...
Why is it that, while other social media and group chat platforms are full of junk from over a year ago being passed around and treated like news, Twitter is on top of uncovering stuff as it happens, debunking bs, and surfacing relevant expertise?
IMO, it's because the core value of Twitter is as a source of trust in domain expertise that comes from the unified public social graph of follow relationships and individually curated follows.
Read 9 tweets
Oct 24, 2022
Ok, so my poll a couple days ago came out strongly in favor of 3D printing tweets on main. Little did I suspect the first followup would be in the intersection of 3D printing and infosec... 😬 🧵 coming.
Some background: Klipper is the modern motion control & firmware system for these kind of machines, with high level model running on a Python capable host (usually rpi with Linux) & mcu only processing very low level motor stepping, etc.
This is as opposed to doing all the motion planning math, ui, etc. on an underpowered mcu in a monolithic Arduino-style C++ program (Marlin), which become a limiting factor for high speed & quality (very oversimplified explanation but hey it's not the point).
Read 8 tweets
Aug 22, 2021
Short 🧵on philosophy of software and systems. 1/N
Often maintaining musl, I encounter attempts to contribute from new folks who see "cleaning something up" or making a minor or questionable optimization as an easy way to get involved, and end up turning them down. 2/N
This has prompted me to think a little bit more about why. On the surface, it's because it makes more review burden for me and for others who don't want to just trust me but check correctness of changes, with little measurable value.

But is there a mental model behind this? 3/N
Read 7 tweets
Aug 22, 2021
Following up to explain this for folks who might not realize right away what this means:

They're instructed to make decisions on admissibility for immigration based on the output of Google Translate. 1/N
This is software that gratuitously inserts gender into nongendered language (possibly radically altering meaning) and reproduces all the biases of the corpus it was trained on. 2/N
It absolutely will use more or less ominous English phrasing for the same concepts from different languages simply based on the biases it was trained on with regard for what subjects in the source language are commonly translated into English. 3/N
Read 4 tweets
Apr 29, 2021
Wow, turning Windows Defender off makes Windows like 100x faster and fixes catastrophic OOM crashing. But it's nearly impossible to do on Windows 10 Home.
All the old registry ways to disable Defender have been removed, and stopping the service is blocked by some undocumented access control layer. Only group policy can turn it off and Home lacks GP.
Fortunately Home actually does have group policy, but it's just not installed. There's an undocumented way to add it without even needing network access.
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(