diff options
author | smitsohu <smitsohu@gmail.com> | 2019-03-16 19:05:27 +0100 |
---|---|---|
committer | smitsohu <smitsohu@gmail.com> | 2019-03-16 19:05:27 +0100 |
commit | 63b16db2a9555db0e9c4bdc1f9fc0a1d73f42b9d (patch) | |
tree | df985285a5171ef680e882487ea3bc722455d665 /src/firejail/no_sandbox.c | |
parent | Fix assogiate's private-bin (#2603) (diff) | |
download | firejail-63b16db2a9555db0e9c4bdc1f9fc0a1d73f42b9d.tar.gz firejail-63b16db2a9555db0e9c4bdc1f9fc0a1d73f42b9d.tar.zst firejail-63b16db2a9555db0e9c4bdc1f9fc0a1d73f42b9d.zip |
hardening: replace setuid/setgid calls with setresuid/setresgid
when nesting containers and sandboxes, it is possible setuid() fails
silently to reset the saved uid, which is then cleared only by
the next execve. This is solved by replacing setuid() with more
robust setresuid() function calls.
Also add code to drop privileges when entering the run_no_sandbox()
function (along with some minor tidy up).
Diffstat (limited to 'src/firejail/no_sandbox.c')
-rw-r--r-- | src/firejail/no_sandbox.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/firejail/no_sandbox.c b/src/firejail/no_sandbox.c index 9ad4e8ba1..096f34cc5 100644 --- a/src/firejail/no_sandbox.c +++ b/src/firejail/no_sandbox.c | |||
@@ -161,32 +161,31 @@ int check_kernel_procs(void) { | |||
161 | 161 | ||
162 | void run_no_sandbox(int argc, char **argv) { | 162 | void run_no_sandbox(int argc, char **argv) { |
163 | EUID_ASSERT(); | 163 | EUID_ASSERT(); |
164 | // drop privileges | ||
165 | gid_t gid = getgid(); | ||
166 | uid_t uid = getuid(); | ||
167 | if (setresgid(gid, gid, gid) != 0) | ||
168 | errExit("setresgid"); | ||
169 | if (setresuid(uid, uid, uid) != 0) | ||
170 | errExit("setresuid"); | ||
164 | 171 | ||
165 | // process limited subset of options | 172 | // process limited subset of options |
166 | int i; | 173 | int i; |
167 | for (i = 0; i < argc; i++) { | 174 | for (i = 0; i < argc; i++) { |
168 | if (strcmp(argv[i], "--debug") == 0) | 175 | if (strcmp(argv[i], "--debug") == 0) |
169 | arg_debug = 1; | 176 | arg_debug = 1; |
170 | else if (strcmp(argv[i], "--shell=none") == 0 || | 177 | else if (strncmp(argv[i], "--shell=", 8) == 0) |
171 | strncmp(argv[i], "--shell=", 8) == 0) | ||
172 | fwarning("shell-related command line options are disregarded - using SHELL environment variable\n"); | 178 | fwarning("shell-related command line options are disregarded - using SHELL environment variable\n"); |
173 | } | 179 | } |
174 | 180 | ||
175 | // use $SHELL to get shell used in sandbox | 181 | // use $SHELL to get shell used in sandbox, guess shell otherwise |
176 | char *shell = getenv("SHELL"); | 182 | cfg.shell = guess_shell(); |
177 | if (shell && access(shell, R_OK) == 0) | ||
178 | cfg.shell = shell; | ||
179 | |||
180 | // guess shell otherwise | ||
181 | if (!cfg.shell) { | ||
182 | cfg.shell = guess_shell(); | ||
183 | if (arg_debug) | ||
184 | printf("Autoselecting %s as shell\n", cfg.shell); | ||
185 | } | ||
186 | if (!cfg.shell) { | 183 | if (!cfg.shell) { |
187 | fprintf(stderr, "Error: unable to guess your shell, please set SHELL environment variable\n"); | 184 | fprintf(stderr, "Error: unable to guess your shell, please set SHELL environment variable\n"); |
188 | exit(1); | 185 | exit(1); |
189 | } | 186 | } |
187 | else if (arg_debug) | ||
188 | printf("Selecting %s as shell\n", cfg.shell); | ||
190 | 189 | ||
191 | int prog_index = 0; | 190 | int prog_index = 0; |
192 | // find first non option arg: | 191 | // find first non option arg: |