Skip to content

Commit 5643f67

Browse files
committed
patch: explicit PROT_WRITE in zero_bss is redundant
1 parent 2a0154c commit 5643f67

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

command/base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ QEMU_REV="10.1.2"
1313
QEMU_GIT_COMMIT=""
1414

1515
# reset to blank when QEMU_REV/GIT_COMMIT bumps, otherwise begin count from 1
16-
QEMU_REV_ZIG_SERIAL=1
16+
QEMU_REV_ZIG_SERIAL=2
1717

1818
if [ -n "$QEMU_GIT_COMMIT" ]; then
1919
QEMU_SRC_BASENAME="${QEMU_NAME}-${QEMU_REV}-${QEMU_GIT_COMMIT}"

command/patch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ RUN patch -p1 -i "${WORK_ROOT}/patch/linux-user__syscall.diff"
1010
RUN patch -p1 -i "${WORK_ROOT}/patch/linux-user__mlugg1.diff"
1111
RUN patch -p1 -i "${WORK_ROOT}/patch/linux-user__mlugg2.diff"
1212
RUN patch -p1 -i "${WORK_ROOT}/patch/linux-user__mlugg3.diff"
13+
RUN patch -p1 -i "${WORK_ROOT}/patch/linux-user__elfload.diff"

patch/linux-user__elfload.diff

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)