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

Side by Side Diff: sandbox/linux/suid/sandbox.c

Issue 569533002: Remove --find-inode-switch hack from chrome-sandbox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert API number bump and merge remainder of linux_util.h into sandbox.h Created 6 years, 3 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
« no previous file with comments | « sandbox/linux/suid/linux_util.c ('k') | no next file » | 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 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox 5 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox
6 6
7 #include "sandbox/linux/suid/common/sandbox.h" 7 #include "sandbox/linux/suid/common/sandbox.h"
8 8
9 #define _GNU_SOURCE 9 #define _GNU_SOURCE
10 #include <asm/unistd.h> 10 #include <asm/unistd.h>
(...skipping 12 matching lines...) Expand all
23 #include <sys/resource.h> 23 #include <sys/resource.h>
24 #include <sys/socket.h> 24 #include <sys/socket.h>
25 #include <sys/stat.h> 25 #include <sys/stat.h>
26 #include <sys/time.h> 26 #include <sys/time.h>
27 #include <sys/types.h> 27 #include <sys/types.h>
28 #include <sys/vfs.h> 28 #include <sys/vfs.h>
29 #include <sys/wait.h> 29 #include <sys/wait.h>
30 #include <unistd.h> 30 #include <unistd.h>
31 31
32 #include "sandbox/linux/suid/common/suid_unsafe_environment_variables.h" 32 #include "sandbox/linux/suid/common/suid_unsafe_environment_variables.h"
33 #include "sandbox/linux/suid/linux_util.h"
34 #include "sandbox/linux/suid/process_util.h" 33 #include "sandbox/linux/suid/process_util.h"
35 34
36 #if !defined(CLONE_NEWPID) 35 #if !defined(CLONE_NEWPID)
37 #define CLONE_NEWPID 0x20000000 36 #define CLONE_NEWPID 0x20000000
38 #endif 37 #endif
39 #if !defined(CLONE_NEWNET) 38 #if !defined(CLONE_NEWNET)
40 #define CLONE_NEWNET 0x40000000 39 #define CLONE_NEWNET 0x40000000
41 #endif 40 #endif
42 41
43 static bool DropRoot(); 42 static bool DropRoot();
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 fprintf(stderr, "Usage: %s <renderer process> <args...>\n", argv[0]); 425 fprintf(stderr, "Usage: %s <renderer process> <args...>\n", argv[0]);
427 return 1; 426 return 1;
428 } 427 }
429 428
430 // Allow someone to query our API version 429 // Allow someone to query our API version
431 if (argc == 2 && 0 == strcmp(argv[1], kSuidSandboxGetApiSwitch)) { 430 if (argc == 2 && 0 == strcmp(argv[1], kSuidSandboxGetApiSwitch)) {
432 printf("%ld\n", kSUIDSandboxApiNumber); 431 printf("%ld\n", kSUIDSandboxApiNumber);
433 return 0; 432 return 0;
434 } 433 }
435 434
436 // In the SUID sandbox, if we succeed in calling MoveToNewNamespaces() 435 // We cannot adjust /proc/pid/oom_adj for sandboxed renderers
437 // below, then the zygote and all the renderers are in an alternate PID 436 // because those files are owned by root. So we need a helper here.
438 // namespace and do not know their real PIDs. As such, they report the wrong
439 // PIDs to the task manager.
440 //
441 // To fix this, when the zygote spawns a new renderer, it gives the renderer
442 // a dummy socket, which has a unique inode number. Then it asks the sandbox
443 // host to find the PID of the process holding that fd by searching /proc.
444 //
445 // Since the zygote and renderers are all spawned by this setuid executable,
446 // their entries in /proc are owned by root and only readable by root. In
447 // order to search /proc for the fd we want, this setuid executable has to
448 // double as a helper and perform the search. The code block below does this
449 // when you call it with --find-inode INODE_NUMBER.
450 if (argc == 3 && (0 == strcmp(argv[1], kFindInodeSwitch))) {
451 pid_t pid;
452 char* endptr = NULL;
453 errno = 0;
454 ino_t inode = strtoull(argv[2], &endptr, 10);
455 if (inode == ULLONG_MAX || !endptr || *endptr || errno != 0)
456 return 1;
457 if (!FindProcessHoldingSocket(&pid, inode))
458 return 1;
459 printf("%d\n", pid);
460 return 0;
461 }
462 // Likewise, we cannot adjust /proc/pid/oom_adj for sandboxed renderers
463 // because those files are owned by root. So we need another helper here.
464 if (argc == 4 && (0 == strcmp(argv[1], kAdjustOOMScoreSwitch))) { 437 if (argc == 4 && (0 == strcmp(argv[1], kAdjustOOMScoreSwitch))) {
465 char* endptr = NULL; 438 char* endptr = NULL;
466 long score; 439 long score;
467 errno = 0; 440 errno = 0;
468 unsigned long pid_ul = strtoul(argv[2], &endptr, 10); 441 unsigned long pid_ul = strtoul(argv[2], &endptr, 10);
469 if (pid_ul == ULONG_MAX || !endptr || *endptr || errno != 0) 442 if (pid_ul == ULONG_MAX || !endptr || *endptr || errno != 0)
470 return 1; 443 return 1;
471 pid_t pid = pid_ul; 444 pid_t pid = pid_ul;
472 endptr = NULL; 445 endptr = NULL;
473 errno = 0; 446 errno = 0;
(...skipping 24 matching lines...) Expand all
498 if (!DropRoot()) 471 if (!DropRoot())
499 return 1; 472 return 1;
500 if (!SetupChildEnvironment()) 473 if (!SetupChildEnvironment())
501 return 1; 474 return 1;
502 475
503 execv(argv[1], &argv[1]); 476 execv(argv[1], &argv[1]);
504 FatalError("execv failed"); 477 FatalError("execv failed");
505 478
506 return 1; 479 return 1;
507 } 480 }
OLDNEW
« no previous file with comments | « sandbox/linux/suid/linux_util.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698