From patchwork Sat Jul 9 09:22:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 103963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3F8AA1007D4 for ; Sat, 9 Jul 2011 19:24:55 +1000 (EST) Received: from localhost ([::1]:60209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfTmO-00049c-2I for incoming@patchwork.ozlabs.org; Sat, 09 Jul 2011 05:24:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfTjv-00049H-3I for qemu-devel@nongnu.org; Sat, 09 Jul 2011 05:22:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QfTjt-00034q-L9 for qemu-devel@nongnu.org; Sat, 09 Jul 2011 05:22:18 -0400 Received: from mtagate1.uk.ibm.com ([194.196.100.161]:55104) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfTjt-00034c-5S for qemu-devel@nongnu.org; Sat, 09 Jul 2011 05:22:17 -0400 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p699MELR013984 for ; Sat, 9 Jul 2011 09:22:14 GMT Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p699MDIk2511084 for ; Sat, 9 Jul 2011 10:22:14 +0100 Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p699MD6S013527 for ; Sat, 9 Jul 2011 03:22:13 -0600 Received: from stefanha-thinkpad.ibm.com (gbv82902-009146169041.uk.ibm.com [9.146.169.41]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p699MDt7013512; Sat, 9 Jul 2011 03:22:13 -0600 From: Stefan Hajnoczi To: Date: Sat, 9 Jul 2011 10:22:07 +0100 Message-Id: <1310203327-27069-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.161 Cc: Bug 807893 <807893@bugs.launchpad.net>, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] os-posix: set groups properly for -runas X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Acked-by: Chris Wright --- Note this needs compile testing on various POSIX host platforms. Tested on Linux. Should work on BSD and Solaris. initgroups(3) is SVr4/BSD but not in POSIX. os-posix.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/os-posix.c b/os-posix.c index 7dfb278..6f8d488 100644 --- a/os-posix.c +++ b/os-posix.c @@ -31,6 +31,7 @@ /*needed for MAP_POPULATE before including qemu-options.h */ #include #include +#include #include /* 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);