News for hackers. Stuff that matters.
Re:Dynamic linking by saagarjha on Friday June 26, 2020 @10:47PM (#23659118)
I know how ASLR/ROP/PLT/GOT/RELRO work, but I'm still not understanding what's going on here. When you statically link a binary, you get…one file. And that gets loaded into memory together, and to make it PIE you have all the jumps be pc-relative. Like, a straight up jump instruction to a fixed offset. So where the the room for a table like this?

(Unrelated, but since you brought it up: kbind is IMO not a very good mitigation. It seems that all you have to do to bypass it is leak a cookie and ROP to that one place in ld.so that is "blessed" and then you not only have the ability to scribble all over your read-only GOT but as far as I can tell you can overwrite any read-only memory, which means it opens up an extremely valuable exploit primitive…)

Re:Dynamic linking by spc476 on Saturday June 27, 2020 @04:52AM (#23660442)
When I participated in NaNoGenMo 2015 [1], I ended up having to emulate a very small subset of MS-DOS [2]. That meant loading in an MS-DOS `.EXE` file into memory and running it. I had a 32-bit Linux system, so I was able to use the `vm86()` system call to run the 16-bit code natively. The `.EXE` file had basically two sections---the first the actual binary code (and data and what have you). This was followed by another section that contained offsets into the code that was loaded that needed to be updated with the proper address, and it took all of five lines of code to implement [3]. Once used, that segment can be discarded. You don't need position independent code to implement address space layout randomization (it makes it easier), you just need a table to rework the absolute addresses (downside---it may take some time).

[1] National Novel Generation Month

[2] https://github.com/spc476/NaNoGenMo-2015, specifically, https://github.com/spc476/NaNoGenMo-2015/blob/master/C/msdos...

[3] lines 337 to 343 of `msdos.c` [2]

Re:Dynamic linking by saagarjha on Saturday June 27, 2020 @05:22AM (#23660545)
This isn’t my area of expertise, but I think on Windows relocations are actually handled quite similarly (as a table of locations that the loader uses to patch with).
Re:Dynamic linking by account42 on Monday June 29, 2020 @08:19AM (#23676882)
Relocation by patching code means you no can no longer share code sections between programs.
Re:Dynamic linking by wahern on Saturday June 27, 2020 @05:22AM (#23660548)
Turns out I was the confused one, not you. I thought it was at least possible to generate binaries with multiple segments, each with their own PLT, GOT, and .text sections, similar to putting .text and .data sections in separate segments. That way the relative position of all functions wouldn't be static. But it seems there's no way to generate binaries like this using the standard tools.