Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: sandbox/linux/suid/common/suid_unsafe_environment_variables.h

Issue 10807059: Refactor the setuid sandbox client code to its own class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer's comments and other minor nits. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/suid/common/sandbox.h ('k') | sandbox/linux/suid/sandbox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is a list of environment variables which the ELF loader unsets when 5 // This is a list of environment variables which the ELF loader unsets when
6 // loading a SUID binary. Because they are unset rather than just ignored, they 6 // loading a SUID binary. Because they are unset rather than just ignored, they
7 // aren't passed to child processes of SUID processes either. 7 // aren't passed to child processes of SUID processes either.
8 // 8 //
9 // We need to save these environment variables before running a SUID sandbox 9 // We need to save these environment variables before running a SUID sandbox
10 // and restore them before running child processes (but after dropping root). 10 // and restore them before running child processes (but after dropping root).
11 // 11 //
12 // List gathered from glibc sources (00ebd7ed58df389a78e41dece058048725cb585e): 12 // List gathered from glibc sources (00ebd7ed58df389a78e41dece058048725cb585e):
13 // sysdeps/unix/sysv/linux/i386/dl-librecon.h 13 // sysdeps/unix/sysv/linux/i386/dl-librecon.h
14 // sysdeps/generic/unsecvars.h 14 // sysdeps/generic/unsecvars.h
15 15
16 #ifndef SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_ 16 #ifndef SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_
17 #define SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_ 17 #define SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_
18 18
19 #if defined(__cplusplus)
20 #include <limits>
21 #define SIZE_MAX std::numeric_limits<size_t>::max()
22 #endif
23
24 #include <stdlib.h> // malloc
25 #include <string.h> // memcpy
26
19 static const char* kSUIDUnsafeEnvironmentVariables[] = { 27 static const char* kSUIDUnsafeEnvironmentVariables[] = {
20 "LD_AOUT_LIBRARY_PATH", 28 "LD_AOUT_LIBRARY_PATH",
21 "LD_AOUT_PRELOAD", 29 "LD_AOUT_PRELOAD",
22 "GCONV_PATH", 30 "GCONV_PATH",
23 "GETCONF_DIR", 31 "GETCONF_DIR",
24 "HOSTALIASES", 32 "HOSTALIASES",
25 "LD_AUDIT", 33 "LD_AUDIT",
26 "LD_DEBUG", 34 "LD_DEBUG",
27 "LD_DEBUG_OUTPUT", 35 "LD_DEBUG_OUTPUT",
28 "LD_DYNAMIC_WEAK", 36 "LD_DYNAMIC_WEAK",
(...skipping 12 matching lines...) Expand all
41 "RES_OPTIONS", 49 "RES_OPTIONS",
42 "TMPDIR", 50 "TMPDIR",
43 "TZDIR", 51 "TZDIR",
44 NULL, 52 NULL,
45 }; 53 };
46 54
47 // Return a malloc allocated string containing the 'saved' environment variable 55 // Return a malloc allocated string containing the 'saved' environment variable
48 // name for a given environment variable. 56 // name for a given environment variable.
49 static inline char* SandboxSavedEnvironmentVariable(const char* envvar) { 57 static inline char* SandboxSavedEnvironmentVariable(const char* envvar) {
50 const size_t envvar_len = strlen(envvar); 58 const size_t envvar_len = strlen(envvar);
59
60 if (envvar_len > SIZE_MAX - 1 -8)
61 return NULL;
62
51 const size_t saved_envvarlen = envvar_len + 1 /* NUL terminator */ + 63 const size_t saved_envvarlen = envvar_len + 1 /* NUL terminator */ +
52 8 /* strlen("SANDBOX_") */; 64 8 /* strlen("SANDBOX_") */;
53 char* const saved_envvar = (char*) malloc(saved_envvarlen); 65 char* const saved_envvar = (char*) malloc(saved_envvarlen);
54 if (!saved_envvar) 66 if (!saved_envvar)
55 return NULL; 67 return NULL;
56 68
57 memcpy(saved_envvar, "SANDBOX_", 8); 69 memcpy(saved_envvar, "SANDBOX_", 8);
58 memcpy(saved_envvar + 8, envvar, envvar_len); 70 memcpy(saved_envvar + 8, envvar, envvar_len);
59 saved_envvar[8 + envvar_len] = 0; 71 saved_envvar[8 + envvar_len] = 0;
60 72
61 return saved_envvar; 73 return saved_envvar;
62 } 74 }
63 75
76 #if defined(__cplusplus)
77 #undef SIZE_MAX
78 #endif
79
64 #endif // SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_ 80 #endif // SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_
OLDNEW
« no previous file with comments | « sandbox/linux/suid/common/sandbox.h ('k') | sandbox/linux/suid/sandbox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698