From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/9] sandbox: use native setjmp/longjmp/initjmp implementation by default
Date: Mon, 25 Nov 2024 16:35:19 +0100 [thread overview]
Message-ID: <20241125153523.1411849-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241125153523.1411849-1-a.fatoum@pengutronix.de>
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@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
next prev parent reply other threads:[~2024-11-25 15:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 15:35 [PATCH 0/9] " Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 1/9] sandbox: asm: support inclusion from sandbox os support code Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 2/9] test: self: setjmp: add simple initial testcase Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 3/9] sandbox: source/invoke um Makefiles provided by host architecture Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 4/9] sandbox: setjmp: mark C version as __weak Ahmad Fatoum
2024-11-25 15:35 ` Ahmad Fatoum [this message]
2024-11-25 15:35 ` [PATCH 6/9] sandbox: retire HAVE_ARCH_ASAN Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 7/9] bthread: move asan fiber API into header Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 8/9] test: self: setjmp: make compatible with ASAN Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 9/9] bthread: fix use of ASAN fiber stack switch API Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241125153523.1411849-6-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox