]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[riscv] Allow for poisoning .bss section before early initialisation
authorMichael Brown <mcb30@ipxe.org>
Wed, 30 Jul 2025 10:11:00 +0000 (11:11 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 30 Jul 2025 11:31:15 +0000 (12:31 +0100)
commit5bda1727b4eac1bdb6a34c5c2288cd0bbf699c5b
treed9158c71cff10c2fdfd2feba3287ada59e968ca0
parente3a6e9230c4e513e6a529427d71a714849b6f788
[riscv] Allow for poisoning .bss section before early initialisation

On startup, we may be running from read-only memory, and therefore
cannot zero the .bss section (or write to the .data section) until we
have parsed the system memory map and relocated ourselves to somewhere
suitable in RAM.  The code that runs during this early initialisation
stage must be carefully written to avoid writing to the .data section
and to avoid reading from or writing to the .bss section.

Detecting code that erroneously writes to the .data or .bss sections
is relatively easy since running from read-only memory (e.g. via
QEMU's -pflash option) will immediately reveal the bug.  Detecting
code that erroneously reads from the .bss section is harder, since in
a freshly powered-on machine (or in a virtual machine) there is a high
probability that the contents of the memory will be zero even before
we explicitly zero out the section.

Add the ability to fill the .bss section with an invalid non-zero
value to expose bugs in early initialisation code that erroneously
relies upon variables in .bss before the section has been zeroed.  We
use the value 0xeb55eb55eb55eb55 ("EBSS") since this is immediately
recognisable as a value in a crash dump, and will trigger a page fault
if dereferenced since the address is in a non-canonical form.

Poisoning the .bss can be done only when the image is known to already
reside in writable memory.  It will overwrite the relocation records,
and so can be done only on a system where relocation is known to be
unnecessary (e.g. because paging is supported).  We therefore do not
enable this behaviour by default, but leave it as a configurable
option via the config/fault.h header.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/riscv/prefix/libprefix.S
src/config/fault.h