|
| 1 | +# From e9b300e1579d456fd307659f86d8ac0373a25fea Mon Sep 17 00:00:00 2001 |
| 2 | +# From: David Rubin <david@vortan.dev> |
| 3 | +# Date: Wed, 5 Nov 2025 18:26:33 -0800 |
| 4 | +# Subject: [PATCH] explicit `PROT_WRITE` in `zero_bss` is redundant |
| 5 | +# |
| 6 | +# The `PAGE_WRITE` check already protects the `memset`. |
| 7 | +# |
| 8 | +# The Zig compiler uses `memsz` to reserve virtual address |
| 9 | +# space that can be used by future updates, including |
| 10 | +# in non-writable sections such as `.text`. |
| 11 | +# |
| 12 | +# However, it also aligns `filesz` to the target page size, |
| 13 | +# so partial zeroing is never necassary for these incremental |
| 14 | +# binaries. |
| 15 | +# |
| 16 | +# When the host page size is larger than the target page |
| 17 | +# size, a single host page can represent multiple target pages. |
| 18 | +# `page_get_flags` takes this into account and merges the permissions |
| 19 | +# across the target pages. Therefore, if just one page in the |
| 20 | +# list of pages represented by a host page is writable, the |
| 21 | +# entire page must be writable. |
| 22 | +# |
| 23 | +# Every section is either entirely bss, thus already target page |
| 24 | +# aligned, or if partially aligned then the non-bss part will |
| 25 | +# have been writable (because it's a data section) and will cause |
| 26 | +# at least of part of the current host page to be writable. |
| 27 | +# |
| 28 | +diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
| 29 | +index ea214105ff..bc529df298 100644 |
| 30 | +--- a/linux-user/elfload.c |
| 31 | ++++ b/linux-user/elfload.c |
| 32 | +@@ -2464,12 +2464,6 @@ static bool zero_bss(abi_ulong start_bss, abi_ulong end_bss, |
| 33 | + { |
| 34 | + abi_ulong align_bss; |
| 35 | + |
| 36 | +- /* We only expect writable bss; the code segment shouldn't need this. */ |
| 37 | +- if (!(prot & PROT_WRITE)) { |
| 38 | +- error_setg(errp, "PT_LOAD with non-writable bss"); |
| 39 | +- return false; |
| 40 | +- } |
| 41 | +- |
| 42 | + align_bss = TARGET_PAGE_ALIGN(start_bss); |
| 43 | + end_bss = TARGET_PAGE_ALIGN(end_bss); |
| 44 | + |
0 commit comments