diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-02 05:16:33 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-02 05:16:33 +0000 |
| commit | e4f898c4a6b9900553c64b9804889b5fdae3e55f (patch) | |
| tree | 31d8f96e419abe35464c23d15185e9f8d8188077 | |
| parent | 12752bc0f9441ef9f929ee652eeb5d92b9dda4a5 (diff) | |
build: keep the stack non-executable, whoever links this
RandomX links jit_compiler_x86_static.S, a hand-written assembly stub with
no .note.GNU-stack marker. binutils reads a missing marker as a request for
an executable stack, and older linkers grant it for the whole binary: NX off,
process-wide, for a node that parses attacker-supplied blocks and messages.
The same source therefore produced different security properties depending on
where it was built. Ubuntu 26.04 gave GNU_STACK RW; Debian 12 -- the build
target for the deploy image, because it is the oldest glibc we ship to and the
last Debian that still packages the Berkeley DB C++ binding -- gave RWE. The
only announcement was a linker warning in the middle of an otherwise clean
build.
-z noexecstack settles it in the tree instead of in the toolchain. RandomX's
JIT maps its own W^X pages and never executes from the stack, so nothing that
works today stops working. Both link lines take it, GUI and headless.
Verify: readelf -lW bitflash-node | grep -A1 GNU_STACK # expect RW
| -rw-r--r-- | src/Makefile | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile index b068376..1bc3ae8 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -100,7 +100,7 @@ obj/imgui_impl_opengl3.o: $(IMGUI_DIR)/imgui_impl_opengl3.cpp | |||
| 100 | $(CXX) -c $(CXXFLAGS) -o $@ $< | 100 | $(CXX) -c $(CXXFLAGS) -o $@ $< |
| 101 | 101 | ||
| 102 | bitflash: $(IMGUI_OBJS) $(NODE_OBJS) $(GUI_OBJS) | 102 | bitflash: $(IMGUI_OBJS) $(NODE_OBJS) $(GUI_OBJS) |
| 103 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) | 103 | $(CXX) $(CXXFLAGS) $(LDHARDFLAGS) -o $@ $^ $(LIBS) |
| 104 | @echo "Built: bitflash" | 104 | @echo "Built: bitflash" |
| 105 | 105 | ||
| 106 | # ---- headless node --------------------------------------------------------- | 106 | # ---- headless node --------------------------------------------------------- |
| @@ -114,6 +114,20 @@ bitflash: $(IMGUI_OBJS) $(NODE_OBJS) $(GUI_OBJS) | |||
| 114 | # Objects go to obj-node/ because main_gui.cpp is compiled twice, with and | 114 | # Objects go to obj-node/ because main_gui.cpp is compiled twice, with and |
| 115 | # without -DBITFLASH_NO_GUI, and the two must not overwrite each other. | 115 | # without -DBITFLASH_NO_GUI, and the two must not overwrite each other. |
| 116 | 116 | ||
| 117 | # RandomX links a hand-written assembly JIT stub, jit_compiler_x86_static.S, | ||
| 118 | # which carries no .note.GNU-stack marker. Older binutils -- Debian 12's, which | ||
| 119 | # is what builds against the oldest glibc we ship to -- reads a missing marker | ||
| 120 | # as "this object wants an executable stack" and marks the whole binary RWE, | ||
| 121 | # switching NX off for the process. Newer toolchains default the other way, so | ||
| 122 | # identical source produced GNU_STACK RW on Ubuntu 26.04 and RWE on bookworm, | ||
| 123 | # announced by nothing louder than a linker warning in the middle of the build. | ||
| 124 | # | ||
| 125 | # Assert it here rather than inherit whichever default the build host happens | ||
| 126 | # to carry. The JIT maps its own W^X pages and never executes from the stack, | ||
| 127 | # so nothing needs the permission this takes away. Check with: | ||
| 128 | # readelf -lW bitflash-node | grep -A1 GNU_STACK # expect RW, not RWE | ||
| 129 | LDHARDFLAGS = -Wl,-z,noexecstack | ||
| 130 | |||
| 117 | NODE_LIBS = -L$(SECP_LIB) -lsecp256k1 \ | 131 | NODE_LIBS = -L$(SECP_LIB) -lsecp256k1 \ |
| 118 | -L$(RANDOMX_DIR)/build -lrandomx \ | 132 | -L$(RANDOMX_DIR)/build -lrandomx \ |
| 119 | -lsodium -lssl -lcrypto -ldb_cxx -lpthread | 133 | -lsodium -lssl -lcrypto -ldb_cxx -lpthread |
| @@ -134,7 +148,7 @@ obj-node/sha.o: sha.cpp sha.h | |||
| 134 | $(CXX) -c $(CXXFLAGS) -DBITFLASH_NO_GUI -O3 -o $@ $< | 148 | $(CXX) -c $(CXXFLAGS) -DBITFLASH_NO_GUI -O3 -o $@ $< |
| 135 | 149 | ||
| 136 | bitflash-node: $(NODE_ONLY_OBJS) | 150 | bitflash-node: $(NODE_ONLY_OBJS) |
| 137 | $(CXX) $(CXXFLAGS) -o $@ $^ $(NODE_LIBS) | 151 | $(CXX) $(CXXFLAGS) $(LDHARDFLAGS) -o $@ $^ $(NODE_LIBS) |
| 138 | @echo "Built: bitflash-node (headless, no libGL needed)" | 152 | @echo "Built: bitflash-node (headless, no libGL needed)" |
| 139 | 153 | ||
| 140 | obj-fuzz/%.o: %.cpp $(HEADERS) | 154 | obj-fuzz/%.o: %.cpp $(HEADERS) |