[PATCH v8 01/14] libbb: mask xvfork to xfork on MMU targets
Nadav Tasher
tashernadav at gmail.com
Sun Mar 9 23:55:23 UTC 2025
Using xfork() instead of xvfork() on MMU targets improves
security and stability.
Memory efficiency differences are negligable since most
kernels implement fork() with CoW.
Signed-off-by: Nadav Tasher <tashernadav at gmail.com>
---
include/libbb.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/libbb.h b/include/libbb.h
index 4d6193795..17ca36760 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1247,6 +1247,7 @@ int BB_EXECVP(const char *file, char *const argv[]) FAST_FUNC;
#endif
void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
+#if !BB_MMU
/* xvfork() can't be a _function_, return after vfork in child mangles stack
* in the parent. It must be a macro. */
#define xvfork() \
@@ -1256,8 +1257,13 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
bb_simple_perror_msg_and_die("vfork"); \
bb__xvfork_pid; \
})
-#if BB_MMU
+#else
pid_t xfork(void) FAST_FUNC;
+
+/* fork() is compliant with vfork().
+ * using fork instead of vfork on MMU-enabled targets makes the entire program
+ * a little safer. */
+#define xvfork() xfork()
#endif
void xvfork_parent_waits_and_exits(void) FAST_FUNC;
--
2.43.0
More information about the busybox
mailing list