News for hackers. Stuff that matters.
Re:On self-modifying executables in Rust by woodruffw on Friday January 28, 2022 @07:03PM (#30122246)
> All this happens on a copy of our program. Self-modifying programs were fine under MS-DOS, but modern operating systems won't let it fly. Renaming or overwriting is fine, since the original file is still unchanged.

This isn’t strictly true: Linux, for example, provides `process_vm_writev`, which can be used to dynamically poke the executable text at runtime. The Linux kernel itself even has a decent amount of SMC, although it doesn’t use that mechanism.

The `totally_safe_transmute` party trick[1] from last year uses a similar technique. Technically it’s on data and not code, but the effect is the same.

[1]: https://blog.yossarian.net/2021/03/16/totally_safe_transmute...

Re:On self-modifying executables in Rust by Hello71 on Friday January 28, 2022 @10:03PM (#30123379)
I don't think process_vm_writev can write to read-only memory, which executable memory is under modern operating systems. Doing that requires ptrace, which long predates Linux. According to the Linux man page, it is "CONFORMING TO: SVr4, 4.3BSD".
Re:On self-modifying executables in Rust by woodruffw on Friday January 28, 2022 @10:40PM (#30123552)
The ptrace APIs also can’t write to read only memory, at least not on modern Linux running on CPUs with modern MMUs. But SMC doesn’t require that, because you can always map (or remap) executable pages as writable.

Executable code is only read-only by default, you can always change that (or just not do it, in the case of a JIT).

Re:On self-modifying executables in Rust by comex on Saturday January 29, 2022 @01:58AM (#30124390)
> The ptrace APIs also can’t write to read only memory

Sure they can.

https://stackoverflow.com/questions/49442087/how-does-ptrace...

Re:On self-modifying executables in Rust by woodruffw on Saturday January 29, 2022 @02:33PM (#30129599)
Huh, this is news to me! I always thought that ptrace temporarily changed the page's permissions, rather than bypassing them entirely. My mistake.