summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-11-16 14:06:38 -0500
committerNick Mathewson <nickm@torproject.org>2017-11-16 14:06:38 -0500
commit2d3904aba67e79e57db1814033b1df3f77336065 (patch)
tree341c471dd31a12c964ca04c1bf2314902253407e /src/common
parentd2d6a1b082fa0eac8b6478889a0c28bf05e48073 (diff)
downloadtor-2d3904aba67e79e57db1814033b1df3f77336065.tar.gz
tor-2d3904aba67e79e57db1814033b1df3f77336065.zip
Check the libc version to decide whether to allow openat.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/sandbox.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/common/sandbox.c b/src/common/sandbox.c
index 417c1e3051..d0ead2caec 100644
--- a/src/common/sandbox.c
+++ b/src/common/sandbox.c
@@ -56,6 +56,9 @@
#include <time.h>
#include <poll.h>
+#ifdef HAVE_GNU_LIBC_VERSION_H
+#include <gnu/libc-version.h>
+#endif
#ifdef HAVE_LINUX_NETFILTER_IPV4_H
#include <linux/netfilter_ipv4.h>
#endif
@@ -424,6 +427,37 @@ sb_mmap2(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
}
#endif
+#ifdef HAVE_GNU_LIBC_VERSION_H
+#ifdef HAVE_GNU_GET_LIBC_VERSION
+#define CHECK_LIBC_VERSION
+#endif
+#endif
+
+/* Return true if we think we're running with a libc that always uses
+ * openat on linux. */
+static int
+libc_uses_openat_for_everything(void)
+{
+#ifdef CHECK_LIBC_VERSION
+ const char *version = gnu_get_libc_version();
+ if (version == NULL)
+ return 0;
+
+ int major = -1;
+ int minor = -1;
+
+ tor_sscanf(version, "%d.%d", &major, &minor);
+ if (major >= 3)
+ return 1;
+ else if (major == 2 && minor >= 26)
+ return 1;
+ else
+ return 0;
+#else
+ return 0;
+#endif
+}
+
/** Allow a single file to be opened. If <b>use_openat</b> is true,
* we're using a libc that remaps all the opens into openats. */
static int
@@ -449,13 +483,15 @@ sb_open(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
int rc;
sandbox_cfg_t *elem = NULL;
+ int use_openat = libc_uses_openat_for_everything();
+
// for each dynamic parameter filters
for (elem = filter; elem != NULL; elem = elem->next) {
smp_param_t *param = elem->param;
if (param != NULL && param->prot == 1 && param->syscall
== SCMP_SYS(open)) {
- rc = allow_file_open(ctx, 0 /* XXXX */, param->value);
+ rc = allow_file_open(ctx, use_openat, param->value);
if (rc != 0) {
log_err(LD_BUG,"(Sandbox) failed to add open syscall, received "
"libseccomp error %d", rc);