diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2011-07-09 10:22:07 +0100 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2011-07-12 21:41:29 +0000 |
commit | 49248515095c4602fb3eb3c0bdb434c0f7d81b22 (patch) | |
tree | 3ab1a05e9b21edfbae7aa0235336537bd5468925 /os-posix.c | |
parent | b1041a24e7beed162b9c05284bebdbef372190bb (diff) | |
download | qemu-49248515095c4602fb3eb3c0bdb434c0f7d81b22.tar.gz qemu-49248515095c4602fb3eb3c0bdb434c0f7d81b22.tar.bz2 qemu-49248515095c4602fb3eb3c0bdb434c0f7d81b22.zip |
os-posix: set groups properly for -runas
Andrew Griffiths reports that -runas does not set supplementary group
IDs. This means that gid 0 (root) is not dropped when switching to an
unprivileged user.
Add an initgroups(3) call to use the -runas user's /etc/groups
membership to update the supplementary group IDs.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Acked-by: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'os-posix.c')
-rw-r--r-- | os-posix.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/os-posix.c b/os-posix.c index 7dfb27836b..6f8d4886ea 100644 --- a/os-posix.c +++ b/os-posix.c @@ -31,6 +31,7 @@ /*needed for MAP_POPULATE before including qemu-options.h */ #include <sys/mman.h> #include <pwd.h> +#include <grp.h> #include <libgen.h> /* Needed early for CONFIG_BSD etc. */ @@ -199,6 +200,11 @@ static void change_process_uid(void) fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid); exit(1); } + if (initgroups(user_pwd->pw_name, user_pwd->pw_gid) < 0) { + fprintf(stderr, "Failed to initgroups(\"%s\", %d)\n", + user_pwd->pw_name, user_pwd->pw_gid); + exit(1); + } if (setuid(user_pwd->pw_uid) < 0) { fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid); exit(1); |