1 |
commit: d8b21b35fd536af8411975ad05eab85f89e84a2e |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Feb 23 03:03:08 2013 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 25 04:17:28 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=d8b21b35 |
7 |
|
8 |
libsandbox: fix early var init |
9 |
|
10 |
In commit 5498907383c7f1654188b6a0d02d8b03112a28c3, we tried to fix |
11 |
handling of ELFs that had their own constructors. Unfortunately, |
12 |
this broke use cases like `env -i` that screw with the environment |
13 |
before we get a chance to extract our settings. |
14 |
|
15 |
URL: http://bugs.gentoo.org/404013 |
16 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
17 |
|
18 |
--- |
19 |
TODO | 2 ++ |
20 |
libsandbox/libsandbox.c | 33 +++++++++++++++++++++++++-------- |
21 |
2 files changed, 27 insertions(+), 8 deletions(-) |
22 |
|
23 |
diff --git a/TODO b/TODO |
24 |
index e8d1d14..6470621 100644 |
25 |
--- a/TODO |
26 |
+++ b/TODO |
27 |
@@ -25,3 +25,5 @@ handle multiple processing writing to log simultaneously |
28 |
|
29 |
doesnt seem to work quite right: |
30 |
echo $(./vfork-0 ./mkdir_static-0 2>&1) |
31 |
+ |
32 |
+handle env var modification inside of traced apps |
33 |
|
34 |
diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c |
35 |
index 0ec5fe1..5d9a796 100644 |
36 |
--- a/libsandbox/libsandbox.c |
37 |
+++ b/libsandbox/libsandbox.c |
38 |
@@ -50,6 +50,7 @@ static char debug_log_path[SB_PATH_MAX]; |
39 |
static char message_path[SB_PATH_MAX]; |
40 |
bool sandbox_on = true; |
41 |
static bool sb_init = false; |
42 |
+static bool sb_env_init = false; |
43 |
int (*sbio_open)(const char *, int, mode_t) = sb_unwrapped_open; |
44 |
FILE *(*sbio_popen)(const char *, const char *) = sb_unwrapped_popen; |
45 |
|
46 |
@@ -62,6 +63,29 @@ static void init_env_entries(char ***, int *, const char *, const char *, int); |
47 |
const char *sbio_message_path; |
48 |
const char sbio_fallback_path[] = "/dev/tty"; |
49 |
|
50 |
+/* We need to initialize these vars before main(). This is to handle programs |
51 |
+ * (like `env`) that will clear the environment before making any syscalls |
52 |
+ * other than execve(). At that point, trying to get the settings is too late. |
53 |
+ * However, we might still need to init the env vars in the syscall wrapper for |
54 |
+ * programs that have their own constructors. #404013 |
55 |
+ */ |
56 |
+__attribute__((constructor)) |
57 |
+void libsb_init(void) |
58 |
+{ |
59 |
+ if (sb_env_init) |
60 |
+ /* Ah, we already saw a syscall */ |
61 |
+ return; |
62 |
+ sb_env_init = true; |
63 |
+ |
64 |
+ /* Get the path and name to this library */ |
65 |
+ get_sandbox_lib(sandbox_lib); |
66 |
+ |
67 |
+ get_sandbox_log(log_path, NULL); |
68 |
+ get_sandbox_debug_log(debug_log_path, NULL); |
69 |
+ get_sandbox_message_path(message_path); |
70 |
+ sbio_message_path = message_path; |
71 |
+} |
72 |
+ |
73 |
/* resolve_dirfd_path - get the path relative to a dirfd |
74 |
* |
75 |
* return value: |
76 |
@@ -937,14 +961,7 @@ bool before_syscall(int dirfd, int sb_nr, const char *func, const char *file, in |
77 |
sb_lock(); |
78 |
|
79 |
if (!sb_init) { |
80 |
- /* Get the path and name to this library */ |
81 |
- get_sandbox_lib(sandbox_lib); |
82 |
- |
83 |
- get_sandbox_log(log_path, NULL); |
84 |
- get_sandbox_debug_log(debug_log_path, NULL); |
85 |
- get_sandbox_message_path(message_path); |
86 |
- sbio_message_path = message_path; |
87 |
- |
88 |
+ libsb_init(); |
89 |
init_context(&sbcontext); |
90 |
sb_init = true; |
91 |
} |