aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-10-28 06:33:00 -0400
committerMike Frysinger <vapier@gentoo.org>2021-10-28 06:33:00 -0400
commit04a58bcbdf1002ccaddeb03bb13505350baeb996 (patch)
treeeaa45ef51961895659241f8da8fc7d5248cb9f5d /libsandbox
parentbuild: create libsandbox for trace_syscalls.h too (diff)
downloadsandbox-04a58bcbdf1002ccaddeb03bb13505350baeb996.tar.gz
sandbox-04a58bcbdf1002ccaddeb03bb13505350baeb996.tar.bz2
sandbox-04a58bcbdf1002ccaddeb03bb13505350baeb996.zip
libsandbox: hoist the *at pre-check functions up a level
The reason we put these in wrapper-funcs/ is because we normally dynamically include them when the corresponding symbol is available. For example, if the C library supports symbol foo, and there is a wrapper-funcs/foo_pre_check.c, we'll automatically include it based on the assumption that wrapper-funcs/foo.c needs it. But if the C library doesn't have a symbol foo, we won't include foo.c or the foo_pre_check.c file at all. Sounds fine. The *at family of functions is a bit different because we end up using them both in the wrapper-funcs/ files, and in the trace code, the latter of which we use unconditionally. This lead to a build issue early on (see commit b27df46f349e850067ae388fe067b043abf3aecb ("libsandbox: fix missing *at pre_checks")) whereby we hacked in these *at pre-check symbols all the time. At which point, having them be in wrapper-funcs/ was more out of convention with how we manage all our other APIs. We want to support running ptrace from the sandbox binary directly which requires linking (most of) libsandbox into it, and to that end, hoist these pre-check functions out of wrapper-funcs. This makes it a bit clearer that we always want to compile these. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox')
-rw-r--r--libsandbox/local.mk5
-rw-r--r--libsandbox/pre_check_at.c (renamed from libsandbox/wrapper-funcs/__pre_at_check.c)5
-rw-r--r--libsandbox/pre_check_mkdirat.c (renamed from libsandbox/wrapper-funcs/mkdirat_pre_check.c)5
-rw-r--r--libsandbox/pre_check_openat.c (renamed from libsandbox/wrapper-funcs/openat_pre_check.c)5
-rw-r--r--libsandbox/pre_check_openat64.c17
-rw-r--r--libsandbox/pre_check_unlinkat.c (renamed from libsandbox/wrapper-funcs/unlinkat_pre_check.c)5
-rw-r--r--libsandbox/wrapper-funcs/__pre_check.c24
-rw-r--r--libsandbox/wrapper-funcs/openat64_pre_check.c12
8 files changed, 42 insertions, 36 deletions
diff --git a/libsandbox/local.mk b/libsandbox/local.mk
index 131bcd8..50bc54d 100644
--- a/libsandbox/local.mk
+++ b/libsandbox/local.mk
@@ -27,6 +27,11 @@ libsbutil/.libs/libsbutil.a: libsbutil/libsbutil.la
%D%/libsandbox.c \
%D%/lock.c \
%D%/memory.c \
+ %D%/pre_check_at.c \
+ %D%/pre_check_mkdirat.c \
+ %D%/pre_check_openat64.c \
+ %D%/pre_check_openat.c \
+ %D%/pre_check_unlinkat.c \
%D%/trace.c \
%D%/wrappers.h \
%D%/wrappers.c \
diff --git a/libsandbox/wrapper-funcs/__pre_at_check.c b/libsandbox/pre_check_at.c
index f72c40c..be6e634 100644
--- a/libsandbox/wrapper-funcs/__pre_at_check.c
+++ b/libsandbox/pre_check_at.c
@@ -5,6 +5,11 @@
* Licensed under the GPL-2
*/
+#include "headers.h"
+#include "sbutil.h"
+#include "libsandbox.h"
+#include "wrappers.h"
+
/* We assume the parent has nested use with save/restore errno */
bool sb_common_at_pre_check(const char *func, const char **pathname, int dirfd,
char *dirfd_path, size_t dirfd_path_len)
diff --git a/libsandbox/wrapper-funcs/mkdirat_pre_check.c b/libsandbox/pre_check_mkdirat.c
index 0b48d1f..8fb38bb 100644
--- a/libsandbox/wrapper-funcs/mkdirat_pre_check.c
+++ b/libsandbox/pre_check_mkdirat.c
@@ -5,6 +5,11 @@
* Licensed under the GPL-2
*/
+#include "headers.h"
+#include "sbutil.h"
+#include "libsandbox.h"
+#include "wrappers.h"
+
bool sb_mkdirat_pre_check(const char *func, const char *pathname, int dirfd)
{
char canonic[SB_PATH_MAX];
diff --git a/libsandbox/wrapper-funcs/openat_pre_check.c b/libsandbox/pre_check_openat.c
index 5fd5eaa..8cf8133 100644
--- a/libsandbox/wrapper-funcs/openat_pre_check.c
+++ b/libsandbox/pre_check_openat.c
@@ -5,6 +5,11 @@
* Licensed under the GPL-2
*/
+#include "headers.h"
+#include "sbutil.h"
+#include "libsandbox.h"
+#include "wrappers.h"
+
bool sb_openat_pre_check(const char *func, const char *pathname, int dirfd, int flags)
{
/* If we're not trying to create, fail normally if
diff --git a/libsandbox/pre_check_openat64.c b/libsandbox/pre_check_openat64.c
new file mode 100644
index 0000000..9420c98
--- /dev/null
+++ b/libsandbox/pre_check_openat64.c
@@ -0,0 +1,17 @@
+/*
+ * open*64*() pre-check.
+ *
+ * Copyright 1999-2009 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#include "headers.h"
+#include "sbutil.h"
+#include "libsandbox.h"
+#include "wrappers.h"
+
+#include "wrapper-funcs/__64_pre.h"
+#define sb_openat_pre_check sb_openat64_pre_check
+#include "pre_check_openat.c"
+#undef sb_openat_pre_check
+#include "wrapper-funcs/__64_post.h"
diff --git a/libsandbox/wrapper-funcs/unlinkat_pre_check.c b/libsandbox/pre_check_unlinkat.c
index c004d15..93a0dd9 100644
--- a/libsandbox/wrapper-funcs/unlinkat_pre_check.c
+++ b/libsandbox/pre_check_unlinkat.c
@@ -5,6 +5,11 @@
* Licensed under the GPL-2
*/
+#include "headers.h"
+#include "sbutil.h"
+#include "libsandbox.h"
+#include "wrappers.h"
+
bool sb_unlinkat_pre_check(const char *func, const char *pathname, int dirfd)
{
char canonic[SB_PATH_MAX];
diff --git a/libsandbox/wrapper-funcs/__pre_check.c b/libsandbox/wrapper-funcs/__pre_check.c
deleted file mode 100644
index e7db0a2..0000000
--- a/libsandbox/wrapper-funcs/__pre_check.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * make sure some pre-checks are pulled in when needed
- *
- * Copyright 1999-2009 Gentoo Foundation
- * Licensed under the GPL-2
- */
-
-#if SB_NR_IS_DEFINED(SB_NR_MKDIR) && !SB_NR_IS_DEFINED(SB_NR_MKDIRAT)
-# include "mkdirat_pre_check.c"
-#endif
-
-#if SB_NR_IS_DEFINED(SB_NR_OPEN) && !SB_NR_IS_DEFINED(SB_NR_OPENAT)
-# include "openat_pre_check.c"
-#endif
-
-#if SB_NR_IS_DEFINED(SB_NR_OPEN64) && !SB_NR_IS_DEFINED(SB_NR_OPENAT64)
-# include "openat64_pre_check.c"
-#endif
-
-#if SB_NR_IS_DEFINED(SB_NR_UNLINK) && !SB_NR_IS_DEFINED(SB_NR_UNLINKAT)
-# include "unlinkat_pre_check.c"
-#endif
-
-#include "__pre_at_check.c"
diff --git a/libsandbox/wrapper-funcs/openat64_pre_check.c b/libsandbox/wrapper-funcs/openat64_pre_check.c
deleted file mode 100644
index 67dc0dc..0000000
--- a/libsandbox/wrapper-funcs/openat64_pre_check.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * open*64*() pre-check.
- *
- * Copyright 1999-2009 Gentoo Foundation
- * Licensed under the GPL-2
- */
-
-#include "__64_pre.h"
-#define sb_openat_pre_check sb_openat64_pre_check
-#include "openat_pre_check.c"
-#undef sb_openat_pre_check
-#include "__64_post.h"