public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/sandbox:master commit in: libsandbox/, /, tests/, libsandbox/wrapper-funcs/
@ 2021-10-22  2:48 Mike Frysinger
  0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2021-10-22  2:48 UTC (permalink / raw
  To: gentoo-commits

commit:     2f6a725d660c61230de21748effa685ee9b3cdaa
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 22 02:38:12 2021 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Oct 22 02:47:38 2021 +0000
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 <vapier <AT> 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 0000000..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 0000000..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 "<dirfd>(old) <path>(old) <dirfd>(new) <path>(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-1.sh
new file mode 100755
index 0000000..9f91c05
--- /dev/null
+++ b/tests/renameat2-1.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+# basic functionality check
+
+addwrite $PWD
+
+touch old || exit 1
+renameat2-0 0 AT_FDCWD old AT_FDCWD new || exit 1
+[ ! -e old -a -e new ]

diff --git a/tests/renameat2.at b/tests/renameat2.at
new file mode 100644
index 0000000..eec4638
--- /dev/null
+++ b/tests/renameat2.at
@@ -0,0 +1,3 @@
+SB_CHECK(1)
+SB_CHECK(2)
+SB_CHECK(3)


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-22  2:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-22  2:48 [gentoo-commits] proj/sandbox:master commit in: libsandbox/, /, tests/, libsandbox/wrapper-funcs/ Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox