commit: 2f6a725d660c61230de21748effa685ee9b3cdaa
Author: Mike Frysinger gentoo org>
AuthorDate: Fri Oct 22 02:38:12 2021 +
Commit: Mike Frysinger gentoo org>
CommitDate: Fri Oct 22 02:47:38 2021 +
URL:https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=2f6a725d
libsandbox: add renameat2 wrapper
It's basically renameat at this point as we don't care about the flags.
Signed-off-by: Mike Frysinger gentoo.org>
configure.ac | 1 +
libsandbox/libsandbox.c | 2 ++
libsandbox/symbols.h.in | 1 +
libsandbox/trace.c | 2 ++
libsandbox/wrapper-funcs/renameat2.c | 11 +++
tests/Makefile.am| 1 +
tests/renameat2-0.c | 22 ++
tests/renameat2-1.sh | 8
tests/renameat2.at | 3 +++
9 files changed, 51 insertions(+)
diff --git a/configure.ac b/configure.ac
index f68cf90..e16892f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -211,6 +211,7 @@ AC_CHECK_FUNCS_ONCE(m4_flatten([
realpath
remove
renameat
+ renameat2
rmdir
setenv
strcasecmp
diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c
index b084daa..c00c92c 100644
--- a/libsandbox/libsandbox.c
+++ b/libsandbox/libsandbox.c
@@ -682,6 +682,7 @@ static bool symlink_func(int sb_nr, int flags, const char
*abs_path)
sb_nr == SB_NR_REMOVE ||
sb_nr == SB_NR_RENAME ||
sb_nr == SB_NR_RENAMEAT ||
+ sb_nr == SB_NR_RENAMEAT2||
sb_nr == SB_NR_RMDIR||
sb_nr == SB_NR_SYMLINK ||
sb_nr == SB_NR_SYMLINKAT))
@@ -795,6 +796,7 @@ static int check_access(sbcontext_t *sbcontext, int sb_nr,
const char *func,
sb_nr == SB_NR_REMOVE ||
sb_nr == SB_NR_RENAME ||
sb_nr == SB_NR_RENAMEAT||
+ sb_nr == SB_NR_RENAMEAT2 ||
sb_nr == SB_NR_RMDIR ||
sb_nr == SB_NR_SYMLINK ||
sb_nr == SB_NR_SYMLINKAT ||
diff --git a/libsandbox/symbols.h.in b/libsandbox/symbols.h.in
index 0154c2a..954d5ae 100644
--- a/libsandbox/symbols.h.in
+++ b/libsandbox/symbols.h.in
@@ -34,6 +34,7 @@ faccessat
remove
rename
renameat
+renameat2
rmdir
symlink
symlinkat
diff --git a/libsandbox/trace.c b/libsandbox/trace.c
index 4d145a3..77991e1 100644
--- a/libsandbox/trace.c
+++ b/libsandbox/trace.c
@@ -323,6 +323,8 @@ static bool trace_check_syscall(const struct syscall_entry
*se, void *regs)
else if (nr == SB_NR_MKNODAT) return trace_check_syscall_DC (&state);
else if (nr == SB_NR_RENAME)return trace_check_syscall_C (&state)
&&
_trace_check_syscall_C (&state,
2);
+ else if (nr == SB_NR_RENAMEAT2) return trace_check_syscall_DC (&state)
&&
+ _trace_check_syscall_DC (&state,
3);
else if (nr == SB_NR_RENAMEAT) return trace_check_syscall_DC (&state)
&&
_trace_check_syscall_DC (&state,
3);
else if (nr == SB_NR_RMDIR) return trace_check_syscall_C (&state);
diff --git a/libsandbox/wrapper-funcs/renameat2.c
b/libsandbox/wrapper-funcs/renameat2.c
new file mode 100644
index 000..4a2e29b
--- /dev/null
+++ b/libsandbox/wrapper-funcs/renameat2.c
@@ -0,0 +1,11 @@
+/*
+ * renameat2() wrapper.
+ *
+ * Copyright 1999-2021 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#define WRAPPER_ARGS_PROTO int olddirfd, const char *oldpath, int newdirfd,
const char *newpath, unsigned int flags
+#define WRAPPER_ARGS olddirfd, oldpath, newdirfd, newpath, flags
+#define WRAPPER_SAFE() (SB_SAFE_AT(olddirfd, oldpath, 0) &&
SB_SAFE_AT(newdirfd, newpath, 0))
+#include "__wrapper_simple.c"
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c899603..e47c996 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@ check_PROGRAMS = \
remove-0 \
rename-0 \
renameat-0 \
+ renameat2-0 \
rmdir-0 \
signal_static-0 \
symlink-0 \
diff --git a/tests/renameat2-0.c b/tests/renameat2-0.c
new file mode 100644
index 000..6041d69
--- /dev/null
+++ b/tests/renameat2-0.c
@@ -0,0 +1,22 @@
+#define CONFIG HAVE_RENAMEAT2
+#define FUNC renameat2
+#define SFUNC "renameat2"
+#define FUNC_STR "%i, \"%s\", %i, \"%s\", %i"
+#define FUNC_IMP olddirfd, oldpath, newdirfd, newpath, 0
+#define ARG_CNT 4
+#define ARG_USE "(old) (old) (new) (new)"
+
+#define process_args() \
+ s = argv[i++]; \
+ int olddirfd = at_get_fd(s); \
+ \
+ s = argv[i++]; \
+ char *oldpath = s; \
+ \
+ s = argv[i++]; \
+ int newdirfd = at_get_fd(s); \
+ \
+ s = argv[i++]; \
+ char *newpath = s;
+
+#include "test-skel-0.c"
diff --git a/tests/renameat2-1.sh b/tests/renameat2