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

Unified Diff: src/platform/minijail/env.cc

Issue 561069: Make minijail respect the groups of the uid provided on the command line. (Closed)
Patch Set: add !entry check, allow unknown UID' Created 10 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/minijail/env.cc
diff --git a/src/platform/minijail/env.cc b/src/platform/minijail/env.cc
index 3ea4c18c5d240e7c627cce1c0317da10ab1cf244..5ee0667515663f988bf5e51f8f54ce419e57e200 100644
--- a/src/platform/minijail/env.cc
+++ b/src/platform/minijail/env.cc
@@ -11,6 +11,7 @@
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
+#include <pwd.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
@@ -82,8 +83,15 @@ bool Env::DisableDefaultRootPrivileges() const {
bool Env::ChangeUser(uid_t uid, gid_t gid) const {
// TODO(wad) support supplemental groups
DLOG(INFO) << "Dropping root...";
- if (setgroups(0, NULL)) {
- PLOG(FATAL) << "Failed to drop supplementary groups";
+ struct passwd* entry = getpwuid(uid);
+ endpwent();
+ if (!entry) {
+ LOG(INFO) << "UID is unknown. Clearing all supplemental groups";
+ PLOG_IF(FATAL, setgroups(0, NULL))
+ << "Failed to clear supplementary groups";
+ } else {
+ PLOG_IF(FATAL, initgroups(entry->pw_name, entry->pw_gid))
+ << "Failed to set supplementary groups";
}
if (setresgid(gid, gid, gid)) {
PLOG(FATAL) << "Failed to change to gid " << gid;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698