[lld] [lld/ELF] Add --override-section-flags flag (PR #109454)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 12:15:40 PDT 2024


nico wrote:

> To make sure I understand, the desire is to have an area of the program that is mapped read-only by the dynamic-linker, ideally aligned on page boundaries.

Right.

> The application, presumably using some kind of linker generated _start and _stop will dynamically alter the permission to write to the section.

When the code wants to write to a variable in such protected memory, it does something like:

```
void* p = round_to_page_boundary(&my_variable);
mprotect(p, READWRITE);
my_variable = 42;
mprotect(p, READONLY);
```

> This sounds like it is almost exactly what you want

Kinda? We want to be able to write to the variable at any time during the program's execution.

The idea is for variables in this section to be regular variables, but since pages in this section are readonly most of the time, they're protected from heap spraying attacks (…most of the time).

> What flags are supported by the option

Currently 'a', 'w', 'x' as described in the help text :)

> If you support overwrite, what about modify? F

Might be nice for a follow-up.

> How does it interact with a PHDRS command that changes the flags like your example above?

You mean in a linker script? Or is it possible to change PHDRS without a linker script? (If not, I'd say just error out when seeing both this flag and a linker script, at least for starters.)

> If a section is marked read-only should the linker forbid dynamic relocations? I would expect so.

Can you say more about this?

---

In general, I'm trying to go for "simplest thing that could work" here. If there's desire to make this work in more cases in the future, to address additional use cases, we can always tweak it later :)

https://github.com/llvm/llvm-project/pull/109454


More information about the llvm-commits mailing list