aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-02-20 01:47:23 -0500
committerMike Frysinger <vapier@gentoo.org>2009-02-20 01:47:23 -0500
commit15c12529fc53816d514d56a34e810ee010130c0b (patch)
treeb61731316fdfb1ec48675808d0a7e8213604b854
parentscripts: disable wrappers for weak __XXX symbols (diff)
downloadsandbox-1.3.8.tar.gz
sandbox-1.3.8.tar.bz2
sandbox-1.3.8.zip
libsandbox: add wrappers for _FORTIFY_SOURCE funcsv1.3.8
When glibc is compiled with optimization and higher _FORTIFY_SOURCE levels, the headers redirect dynamic calls to the open*() functions to the __open*_2() functions. The latter provides runtime checking. But this means we also need to wrap the latter forms in order to get sandbox checking on the open() functions. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--libsandbox/symbols.h.in4
-rw-r--r--libsandbox/wrapper-funcs/__open64_2.c10
-rw-r--r--libsandbox/wrapper-funcs/__open_2.c11
-rw-r--r--libsandbox/wrapper-funcs/__openat64_2.c10
-rw-r--r--libsandbox/wrapper-funcs/__openat_2.c44
5 files changed, 79 insertions, 0 deletions
diff --git a/libsandbox/symbols.h.in b/libsandbox/symbols.h.in
index deb7b60..df352c0 100644
--- a/libsandbox/symbols.h.in
+++ b/libsandbox/symbols.h.in
@@ -11,7 +11,9 @@ fchmodat
chown
fchownat
open
+__open_2
openat
+__openat_2
creat
fopen
lchown
@@ -39,7 +41,9 @@ unlink
unlinkat
getcwd
open64
+__open64_2
openat64
+__openat64_2
creat64
fopen64
truncate64
diff --git a/libsandbox/wrapper-funcs/__open64_2.c b/libsandbox/wrapper-funcs/__open64_2.c
new file mode 100644
index 0000000..bdbd5d8
--- /dev/null
+++ b/libsandbox/wrapper-funcs/__open64_2.c
@@ -0,0 +1,10 @@
+/*
+ * __open64_2() wrapper (_FORTIFY_SOURCE).
+ *
+ * Copyright 1999-2009 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#include "__64_pre.h"
+#include "__open_2.c"
+#include "__64_post.h"
diff --git a/libsandbox/wrapper-funcs/__open_2.c b/libsandbox/wrapper-funcs/__open_2.c
new file mode 100644
index 0000000..a49bab5
--- /dev/null
+++ b/libsandbox/wrapper-funcs/__open_2.c
@@ -0,0 +1,11 @@
+/*
+ * __open_2() wrapper (_FORTIFY_SOURCE).
+ *
+ * Copyright 1999-2009 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#define WRAPPER_ARGS_PROTO const char *pathname, int flags
+#define WRAPPER_ARGS pathname, flags
+#define WRAPPER_SAFE() FUNCTION_SANDBOX_SAFE_OPEN_INT(pathname, flags)
+#include "__openat_2.c"
diff --git a/libsandbox/wrapper-funcs/__openat64_2.c b/libsandbox/wrapper-funcs/__openat64_2.c
new file mode 100644
index 0000000..445164a
--- /dev/null
+++ b/libsandbox/wrapper-funcs/__openat64_2.c
@@ -0,0 +1,10 @@
+/*
+ * __openat64_2() wrapper (_FORTIFY_SOURCE).
+ *
+ * Copyright 1999-2009 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#include "__64_pre.h"
+#include "__openat_2.c"
+#include "__64_post.h"
diff --git a/libsandbox/wrapper-funcs/__openat_2.c b/libsandbox/wrapper-funcs/__openat_2.c
new file mode 100644
index 0000000..3384b93
--- /dev/null
+++ b/libsandbox/wrapper-funcs/__openat_2.c
@@ -0,0 +1,44 @@
+/*
+ * __openat_2() wrapper (_FORTIFY_SOURCE).
+ *
+ * Copyright 1999-2009 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#ifndef WRAPPER_ARGS_PROTO /* let open() use us */
+# define WRAPPER_ARGS_PROTO int dirfd, const char *pathname, int flags
+# define WRAPPER_ARGS dirfd, pathname, flags
+# define WRAPPER_SAFE() FUNCTION_SANDBOX_SAFE_OPEN_INT_AT(dirfd, pathname, flags)
+# define USE_AT 1
+#else
+# define USE_AT 0
+#endif
+
+#ifndef PRE_CHECK_FUNC
+# define _PRE_CHECK_FUNC(x) sb_##x##_pre_check
+# define PRE_CHECK_FUNC(x) _PRE_CHECK_FUNC(x)
+#endif
+static inline bool PRE_CHECK_FUNC(WRAPPER_NAME)(WRAPPER_ARGS_PROTO)
+{
+ if (!(flags & O_CREAT)) {
+ save_errno();
+
+ /* If we're not trying to create, fail normally if
+ * file does not stat
+ */
+ struct stat st;
+#if USE_AT
+ if (dirfd == AT_FDCWD || pathname[0] == '/')
+#endif
+#undef USE_AT
+ if (-1 == stat(pathname, &st))
+ return false;
+
+ restore_errno();
+ }
+
+ return true;
+}
+#define WRAPPER_PRE_CHECKS() PRE_CHECK_FUNC(WRAPPER_NAME)(WRAPPER_ARGS)
+
+#include "__wrapper_simple.c"