public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/, libsandbox/
@ 2012-03-05 21:22 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2012-03-05 21:22 UTC (permalink / raw
  To: gentoo-commits

commit:     5498907383c7f1654188b6a0d02d8b03112a28c3
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Mar  5 21:19:08 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Mar  5 21:21:47 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=54989073

libsandbox: push down constructor init

Since every consumer of sb_open gets a copy of the sbio_open data, push
the init of this into the .data section of the respective consumers to
avoid the runtime overhead.

This just leaves sandbox_lib setup in the constructor function, but that
is only needed by the execve wrapper, so push down init of that to the
existing sb_init logic which happens before our execve wrapper gets used.

URL: http://bugs.gentoo.org/404013
Reported-by: Mike Gilbert <floppym <AT> gentoo.org>
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 libsandbox/libsandbox.c |   43 ++++++-------------------------------------
 libsbutil/sb_open.c     |   11 -----------
 libsbutil/sbutil.h      |    2 +-
 src/sandbox.c           |    1 +
 4 files changed, 8 insertions(+), 49 deletions(-)

diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c
index 0fcbb65..a36e190 100644
--- a/libsandbox/libsandbox.c
+++ b/libsandbox/libsandbox.c
@@ -61,6 +61,7 @@ typedef struct {
 static char *cached_env_vars[MAX_DYN_PREFIXES];
 bool sandbox_on = true;
 static bool sb_init = false;
+int (*sbio_open)(const char *, int, mode_t) = sb_unwrapped_open;
 
 static char *resolve_path(const char *, int);
 static int check_prefixes(char **, int, const char *);
@@ -68,50 +69,15 @@ static void clean_env_entries(char ***, int *);
 static void init_context(sbcontext_t *);
 static void init_env_entries(char ***, int *, const char *, const char *, int);
 
-
-/*
- * Initialize the shabang
- */
-#if 0
-__attribute__((destructor))
-void libsb_fini(void)
-{
-	/* let the kernel reap our resources -- it's faster anyways */
-	int x;
-
-	sb_init = false;
-
-	for (x = 0; x < MAX_DYN_PREFIXES; ++x) {
-		if (NULL != cached_env_vars[x]) {
-			free(cached_env_vars[x]);
-			cached_env_vars[x] = NULL;
-		}
-	}
-
-	for (x = 0; x < MAX_DYN_PREFIXES; ++x)
-		clean_env_entries(&(sbcontext.prefixes[x]),
-				&(sbcontext.num_prefixes[x]));
-}
-#endif
-
+#ifdef SB_MEM_DEBUG
 __attribute__((constructor))
 void libsb_init(void)
 {
 	save_errno();
-
-#ifdef SB_MEM_DEBUG
 	mtrace();
-#endif
-
-	sb_set_open(sb_unwrapped_open);
-
-	/* Get the path and name to this library */
-	get_sandbox_lib(sandbox_lib);
-
-//	sb_init = true;
-
 	restore_errno();
 }
+#endif
 
 static const char *sb_get_fd_dir(void)
 {
@@ -1084,6 +1050,9 @@ bool before_syscall(int dirfd, int sb_nr, const char *func, const char *file, in
 	sb_lock();
 
 	if (!sb_init) {
+		/* Get the path and name to this library */
+		get_sandbox_lib(sandbox_lib);
+
 		init_context(&sbcontext);
 		sb_init = true;
 	}

diff --git a/libsbutil/sb_open.c b/libsbutil/sb_open.c
index 2e405c6..27dda9c 100644
--- a/libsbutil/sb_open.c
+++ b/libsbutil/sb_open.c
@@ -10,17 +10,6 @@
 #include "headers.h"
 #include "sbutil.h"
 
-static int (*sbio_open)(const char *, int, mode_t) = (void *)open;
-
-
-void sb_set_open(void *new_open)
-{
-	if (!check_ptr(new_open))
-		return;
-
-	sbio_open = new_open;
-}
-
 /* General purpose function to _reliably_ open a file
  *
  * Returns the file descriptor or -1 on error (and errno set)

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index e232b31..bdff33f 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -91,7 +91,7 @@ bool is_env_on (const char *);
 bool is_env_off (const char *);
 
 /* libsandbox need to use a wrapper for open */
-void sb_set_open(void *new_open);
+attribute_hidden extern int (*sbio_open)(const char *, int, mode_t);
 /* Convenience functions to reliably open, read and write to a file */
 int sb_open(const char *path, int flags, mode_t mode);
 size_t sb_read(int fd, void *buf, size_t count);

diff --git a/src/sandbox.c b/src/sandbox.c
index d36126e..a8e28fe 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -18,6 +18,7 @@
 static int print_debug = 0;
 #define dprintf(fmt, args...) do { if (print_debug) printf(fmt, ## args); } while (0)
 #define dputs(str) do { if (print_debug) puts(str); } while (0)
+int (*sbio_open)(const char *, int, mode_t) = (void *)open;
 
 volatile static int stop_called = 0;
 volatile static pid_t child_pid = 0;



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/, libsandbox/
@ 2012-12-24  5:23 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2012-12-24  5:23 UTC (permalink / raw
  To: gentoo-commits

commit:     fc0edcbe3114b885c5bcfe10cb00a68f9855c78d
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Dec  3 04:53:52 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Dec 24 05:23:50 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=fc0edcbe

sandbox: allow log files to fallback to tmpdir

Since non-root users typically do not have write access to /var/log,
allow it to fallback to standard tmpdirs.  This makes testing locally
a lot easier.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 libsandbox/libsandbox.c     |    4 ++--
 libsbutil/get_sandbox_log.c |   19 +++++++++++++------
 libsbutil/sbutil.h          |    4 ++--
 src/sandbox.c               |    4 ++--
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c
index 2096b06..184fc0b 100644
--- a/libsandbox/libsandbox.c
+++ b/libsandbox/libsandbox.c
@@ -940,8 +940,8 @@ bool before_syscall(int dirfd, int sb_nr, const char *func, const char *file, in
 		/* Get the path and name to this library */
 		get_sandbox_lib(sandbox_lib);
 
-		get_sandbox_log(log_path);
-		get_sandbox_debug_log(debug_log_path);
+		get_sandbox_log(log_path, NULL);
+		get_sandbox_debug_log(debug_log_path, NULL);
 
 		init_context(&sbcontext);
 		sb_init = true;

diff --git a/libsbutil/get_sandbox_log.c b/libsbutil/get_sandbox_log.c
index c300a24..947566a 100644
--- a/libsbutil/get_sandbox_log.c
+++ b/libsbutil/get_sandbox_log.c
@@ -13,7 +13,7 @@
 #include "headers.h"
 #include "sbutil.h"
 
-static void _get_sb_log(char *path, const char *env, const char *prefix)
+static void _get_sb_log(char *path, const char *tmpdir, const char *env, const char *prefix)
 {
 	char *sandbox_log_env = NULL;
 
@@ -32,8 +32,15 @@ static void _get_sb_log(char *path, const char *env, const char *prefix)
 		    (NULL != strchr(sandbox_log_env, '/')))
 		    sandbox_log_env = NULL;
 
+		/* If running as a user w/out write access to /var/log, don't
+		 * shit ourselves.
+		 */
+		const char *sb_log_dir = SANDBOX_LOG_LOCATION;
+		if (tmpdir && access(sb_log_dir, W_OK))
+			sb_log_dir = tmpdir;
+
 		snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
-			SANDBOX_LOG_LOCATION, prefix,
+			sb_log_dir, prefix,
 			(sandbox_log_env == NULL ? "" : sandbox_log_env),
 			(sandbox_log_env == NULL ? "" : "-"),
 			getpid(), LOG_FILE_EXT);
@@ -42,12 +49,12 @@ static void _get_sb_log(char *path, const char *env, const char *prefix)
 	restore_errno();
 }
 
-void get_sandbox_log(char *path)
+void get_sandbox_log(char *path, const char *tmpdir)
 {
-	_get_sb_log(path, ENV_SANDBOX_LOG, LOG_FILE_PREFIX);
+	_get_sb_log(path, tmpdir, ENV_SANDBOX_LOG, LOG_FILE_PREFIX);
 }
 
-void get_sandbox_debug_log(char *path)
+void get_sandbox_debug_log(char *path, const char *tmpdir)
 {
-	_get_sb_log(path, ENV_SANDBOX_DEBUG_LOG, DEBUG_LOG_FILE_PREFIX);
+	_get_sb_log(path, tmpdir, ENV_SANDBOX_DEBUG_LOG, DEBUG_LOG_FILE_PREFIX);
 }

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index f275514..c65c369 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -76,8 +76,8 @@ char *get_sandbox_conf(void);
 char *get_sandbox_confd(char *path);
 void get_sandbox_lib(char *path);
 void get_sandbox_rc(char *path);
-void get_sandbox_log(char *path);
-void get_sandbox_debug_log(char *path);
+void get_sandbox_log(char *path, const char *tmpdir);
+void get_sandbox_debug_log(char *path, const char *tmpdir);
 int get_tmp_dir(char *path);
 bool is_env_on (const char *);
 bool is_env_off (const char *);

diff --git a/src/sandbox.c b/src/sandbox.c
index 54fbb98..a5920c4 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -61,7 +61,7 @@ static int setup_sandbox(struct sandbox_info_t *sandbox_info, bool interactive)
 	get_sandbox_rc(sandbox_info->sandbox_rc);
 
 	/* Generate sandbox log full path */
-	get_sandbox_log(sandbox_info->sandbox_log);
+	get_sandbox_log(sandbox_info->sandbox_log, sandbox_info->tmp_dir);
 	if (rc_file_exists(sandbox_info->sandbox_log)) {
 		if (-1 == unlink(sandbox_info->sandbox_log)) {
 			sb_pwarn("could not unlink old log file: %s",
@@ -71,7 +71,7 @@ static int setup_sandbox(struct sandbox_info_t *sandbox_info, bool interactive)
 	}
 
 	/* Generate sandbox debug log full path */
-	get_sandbox_debug_log(sandbox_info->sandbox_debug_log);
+	get_sandbox_debug_log(sandbox_info->sandbox_debug_log, sandbox_info->tmp_dir);
 	if (rc_file_exists(sandbox_info->sandbox_debug_log)) {
 		if (-1 == unlink(sandbox_info->sandbox_debug_log)) {
 			sb_pwarn("could not unlink old debug log file: %s",


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/, libsandbox/
@ 2013-02-25  4:08 Mike Frysinger
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2013-02-25  4:08 UTC (permalink / raw
  To: gentoo-commits

commit:     265b974f15ecf119d07fea46a449988a6401392c
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 27 07:04:36 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Feb 25 04:05:05 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=265b974f

delete unused sandbox env vars

Nothing uses or cares about these vars, so punt them.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 libsandbox/libsandbox.c |    3 ---
 libsbutil/sbutil.h      |    7 -------
 src/environ.c           |    8 +-------
 src/sandbox.c           |    2 +-
 src/sandbox.h           |    2 +-
 5 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c
index bdef2d9..eaa5c7d 100644
--- a/libsandbox/libsandbox.c
+++ b/libsandbox/libsandbox.c
@@ -983,9 +983,6 @@ bool before_syscall(int dirfd, int sb_nr, const char *func, const char *file, in
 	sb_unlock();
 
 	if (0 == result) {
-		if ((NULL != getenv(ENV_SANDBOX_PID)) && (is_env_on(ENV_SANDBOX_ABORT)))
-			kill(atoi(getenv(ENV_SANDBOX_PID)), SIGUSR1);
-
 		/* FIXME: Should probably audit errno, and enable some other
 		 *        error to be returned (EINVAL for invalid mode for
 		 *        fopen() and co, ETOOLONG, etc). */

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index 6c90f35..90de815 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -30,7 +30,6 @@
 
 #define ENV_LD_PRELOAD         "LD_PRELOAD"
 
-#define ENV_EBUILD             "EBUILD"
 #define ENV_TMPDIR             "TMPDIR"
 #define ENV_PORTAGE_TMPDIR     "PORTAGE_TMPDIR"
 
@@ -56,15 +55,9 @@
 
 #define ENV_SANDBOX_ON         "SANDBOX_ON"
 
-#define ENV_SANDBOX_PID        "SANDBOX_PID"
-#define ENV_SANDBOX_ABORT      "SANDBOX_ABORT"
-#define ENV_SANDBOX_INTRACTV   "SANDBOX_INTRACTV"
-
 #define ENV_SANDBOX_ACTIVE     "SANDBOX_ACTIVE"
 #define SANDBOX_ACTIVE         "armedandready"
 
-#define SB_BUF_LEN             2048
-
 extern const char *colors[];
 #define COLOR_NORMAL           colors[0]
 #define COLOR_GREEN            colors[1]

diff --git a/src/environ.c b/src/environ.c
index 30ba003..727f10b 100644
--- a/src/environ.c
+++ b/src/environ.c
@@ -234,7 +234,7 @@ static void sb_setenv(char ***envp, const char *name, const char *val)
 
 /* We setup the environment child side only to prevent issues with
  * setting LD_PRELOAD parent side */
-char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
+char **setup_environ(struct sandbox_info_t *sandbox_info)
 {
 	int have_ld_preload = 0;
 
@@ -250,14 +250,12 @@ char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
 	/* Unset these, as its easier than replacing when setting up our
 	 * new environment below */
 	unsetenv(ENV_SANDBOX_ON);
-	unsetenv(ENV_SANDBOX_PID);
 	unsetenv(ENV_SANDBOX_LIB);
 	unsetenv(ENV_SANDBOX_BASHRC);
 	unsetenv(ENV_SANDBOX_LOG);
 	unsetenv(ENV_SANDBOX_DEBUG_LOG);
 	unsetenv(ENV_SANDBOX_WORKDIR);
 	unsetenv(ENV_SANDBOX_ACTIVE);
-	unsetenv(ENV_SANDBOX_INTRACTV);
 	unsetenv(ENV_BASH_ENV);
 
 	orig_ld_preload_envvar = getenv(ENV_LD_PRELOAD);
@@ -284,15 +282,11 @@ char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
 	/* First add our new variables to the beginning - this is due to some
 	 * weirdness that I cannot remember */
 	sb_setenv(&new_environ, ENV_SANDBOX_ON, "1");
-	sb_setenv(&new_environ, ENV_SANDBOX_PID, sb_pid);
 	sb_setenv(&new_environ, ENV_SANDBOX_LIB, sandbox_info->sandbox_lib);
 	sb_setenv(&new_environ, ENV_SANDBOX_BASHRC, sandbox_info->sandbox_rc);
 	sb_setenv(&new_environ, ENV_SANDBOX_LOG, sandbox_info->sandbox_log);
 	sb_setenv(&new_environ, ENV_SANDBOX_DEBUG_LOG,
 			sandbox_info->sandbox_debug_log);
-	/* Is this an interactive session? */
-	if (interactive)
-		sb_setenv(&new_environ, ENV_SANDBOX_INTRACTV, "1");
 	/* Just set the these if not already set so that is_env_on() work */
 	if (!getenv(ENV_SANDBOX_VERBOSE))
 		sb_setenv(&new_environ, ENV_SANDBOX_VERBOSE, "1");

diff --git a/src/sandbox.c b/src/sandbox.c
index a5920c4..aa957f6 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -264,7 +264,7 @@ int main(int argc, char **argv)
 
 	/* Setup the child environment stuff.
 	 * XXX:  We free this in spawn_shell(). */
-	sandbox_environ = setup_environ(&sandbox_info, print_debug);
+	sandbox_environ = setup_environ(&sandbox_info);
 	if (NULL == sandbox_environ)
 		goto oom_error;
 

diff --git a/src/sandbox.h b/src/sandbox.h
index e25a206..cc67753 100644
--- a/src/sandbox.h
+++ b/src/sandbox.h
@@ -23,7 +23,7 @@ struct sandbox_info_t {
 	char *home_dir;
 };
 
-extern char **setup_environ(struct sandbox_info_t *sandbox_info, bool interactive);
+extern char **setup_environ(struct sandbox_info_t *sandbox_info);
 
 #define sb_warn(fmt, args...)  fprintf(stderr, "%s:%s  " fmt "\n", "sandbox", __func__, ## args)
 #define sb_pwarn(fmt, args...) sb_warn(fmt ": %s\n", ## args, strerror(errno))


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-25  4:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-24  5:23 [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/, libsandbox/ Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2013-02-25  4:08 Mike Frysinger
2012-03-05 21:22 Mike Frysinger

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