[PATCH 5/9] sandbox: use native setjmp/longjmp/initjmp implementation by default
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Nov 25 07:35:19 PST 2024
In order to implement initjmp, we have two ways with available
functionality: The sigaltstack we are currently using and
makecontext/swapcontext. makecontext/swapcontext are unfortunately
deprecated in favor of POSIX threads and the sigaltstack runs afoul of
AddressSanitizer.
Let's therefore use the assembly version if we are using ASAN.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
arch/arm/um/Makefile | 12 ++++++++++++
arch/kvx/um/Makefile | 6 ++++++
arch/mips/um/Makefile | 6 ++++++
arch/openrisc/um/Makefile | 6 ++++++
arch/powerpc/um/Makefile | 6 ++++++
arch/riscv/um/Makefile | 6 ++++++
arch/sandbox/Kconfig | 8 ++++++++
arch/x86/um/Makefile | 12 ++++++++++++
8 files changed, 62 insertions(+)
create mode 100644 arch/arm/um/Makefile
create mode 100644 arch/kvx/um/Makefile
create mode 100644 arch/mips/um/Makefile
create mode 100644 arch/openrisc/um/Makefile
create mode 100644 arch/powerpc/um/Makefile
create mode 100644 arch/riscv/um/Makefile
create mode 100644 arch/x86/um/Makefile
diff --git a/arch/arm/um/Makefile b/arch/arm/um/Makefile
new file mode 100644
index 000000000000..380f59fdade2
--- /dev/null
+++ b/arch/arm/um/Makefile
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+ifeq ($(CONFIG_32BIT),y)
+ BITS := 32
+else
+ BITS := 64
+endif
+
+AFLAGS_../lib$(BITS)/setjmp.pbl.o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+pbl-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib$(BITS)/setjmp.o
diff --git a/arch/kvx/um/Makefile b/arch/kvx/um/Makefile
new file mode 100644
index 000000000000..367946d33ac3
--- /dev/null
+++ b/arch/kvx/um/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+AFLAGS_../lib/setjmp.pbl.o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+pbl-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib/setjmp.o
diff --git a/arch/mips/um/Makefile b/arch/mips/um/Makefile
new file mode 100644
index 000000000000..367946d33ac3
--- /dev/null
+++ b/arch/mips/um/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+AFLAGS_../lib/setjmp.pbl.o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+pbl-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib/setjmp.o
diff --git a/arch/openrisc/um/Makefile b/arch/openrisc/um/Makefile
new file mode 100644
index 000000000000..367946d33ac3
--- /dev/null
+++ b/arch/openrisc/um/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+AFLAGS_../lib/setjmp.pbl.o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+pbl-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib/setjmp.o
diff --git a/arch/powerpc/um/Makefile b/arch/powerpc/um/Makefile
new file mode 100644
index 000000000000..367946d33ac3
--- /dev/null
+++ b/arch/powerpc/um/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+AFLAGS_../lib/setjmp.pbl.o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+pbl-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib/setjmp.o
diff --git a/arch/riscv/um/Makefile b/arch/riscv/um/Makefile
new file mode 100644
index 000000000000..367946d33ac3
--- /dev/null
+++ b/arch/riscv/um/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+AFLAGS_../lib/setjmp.pbl.o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+pbl-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib/setjmp.o
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index caff3a138fea..4cc3b201c399 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -65,6 +65,14 @@ config CMD_SANDBOX_CPUINFO
help
Say yes here to get a dummy cpuinfo command.
+config SANDBOX_SJLJ_ASM
+ bool "use setjmp/longjmp/initjmp implemented in assembly" if COMPILE_TEST
+ default y
+ help
+ sandbox has a C implementation of initjmp, which can run afoul of code
+ hardening measures like ASAN. The assembly version isn't immune to these
+ issues, but it's easier to reason about than the sigaltstack hack.
+
config SDL
bool
diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile
new file mode 100644
index 000000000000..d3764221a4c6
--- /dev/null
+++ b/arch/x86/um/Makefile
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj- := __dummy__.o
+
+ifeq ($(CONFIG_32BIT),y)
+ BITS := 32
+else
+ BITS := 64
+endif
+
+AFLAGS_../lib/setjmp_$(BITS).o := -Dsetjmp=barebox_setjmp -Dlongjmp=barebox_longjmp
+obj-$(CONFIG_SANDBOX_SJLJ_ASM) += ../lib/setjmp_$(BITS).o
--
2.39.5
More information about the barebox
mailing list