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

Side by Side Diff: system_utils.cc

Issue 3493012: Security patches: RestartJob ignores pid, argv[0]; kill runs as child UID (Closed) Base URL: http://git.chromium.org/git/login_manager.git
Patch Set: added comments, using -1 as suid in setresuid() calls Created 10 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 | Annotate | Revision Log
« no previous file with comments | « system_utils.h ('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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 #include "login_manager/system_utils.h" 5 #include "login_manager/system_utils.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <sys/wait.h> 9 #include <sys/wait.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 11
12 #include <limits> 12 #include <limits>
13 13
14 #include <base/basictypes.h> 14 #include <base/basictypes.h>
15 #include <base/file_path.h> 15 #include <base/file_path.h>
16 #include <base/file_util.h> 16 #include <base/file_util.h>
17 #include <base/logging.h> 17 #include <base/logging.h>
18 #include "base/scoped_temp_dir.h" 18 #include "base/scoped_temp_dir.h"
19 #include <base/time.h> 19 #include <base/time.h>
20 20
21 namespace login_manager { 21 namespace login_manager {
22 22
23 SystemUtils::SystemUtils() {} 23 SystemUtils::SystemUtils() {}
24 SystemUtils::~SystemUtils() {} 24 SystemUtils::~SystemUtils() {}
25 25
26 int SystemUtils::kill(pid_t pid, int signal) { 26 int SystemUtils::kill(pid_t pid, uid_t owner, int signal) {
27 LOG(INFO) << "Sending " << signal << " to " << pid; 27 LOG(INFO) << "Sending " << signal << " to " << pid << " as " << owner;
28 return ::kill(pid, signal); 28 uid_t uid, euid, suid;
29 getresuid(&uid, &euid, &suid);
30 if (setresuid(owner, owner, -1)) {
31 PLOG(ERROR) << "Couldn't assume uid " << owner;
32 return -1;
33 }
34 int ret = ::kill(pid, signal);
35 if (setresuid(uid, euid, -1)) {
36 PLOG(ERROR) << "Couldn't return to root";
37 return -1;
38 }
39 return ret;
29 } 40 }
30 41
31 bool SystemUtils::ChildIsGone(pid_t child_spec, int timeout) { 42 bool SystemUtils::ChildIsGone(pid_t child_spec, int timeout) {
32 base::Time start = base::Time::Now(); 43 base::Time start = base::Time::Now();
33 base::TimeDelta max_elapsed = base::TimeDelta::FromSeconds(timeout); 44 base::TimeDelta max_elapsed = base::TimeDelta::FromSeconds(timeout);
34 base::TimeDelta elapsed; 45 base::TimeDelta elapsed;
35 int ret; 46 int ret;
36 47
37 alarm(timeout); 48 alarm(timeout);
38 do { 49 do {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (!file_util::CreateTemporaryFileInDir(filename.DirName(), &scratch_file)) 88 if (!file_util::CreateTemporaryFileInDir(filename.DirName(), &scratch_file))
78 return false; 89 return false;
79 if (file_util::WriteFile(scratch_file, data, size) != size) 90 if (file_util::WriteFile(scratch_file, data, size) != size)
80 return false; 91 return false;
81 92
82 return (file_util::ReplaceFile(scratch_file, filename) && 93 return (file_util::ReplaceFile(scratch_file, filename) &&
83 chmod(filename.value().c_str(), (S_IRUSR | S_IWUSR | S_IROTH)) == 0); 94 chmod(filename.value().c_str(), (S_IRUSR | S_IWUSR | S_IROTH)) == 0);
84 } 95 }
85 96
86 } // namespace login_manager 97 } // namespace login_manager
OLDNEW
« no previous file with comments | « system_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698