From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1TLz4j-0003M6-DC for mharc-qemu-trivial@gnu.org; Wed, 10 Oct 2012 12:24:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLz4d-00032l-Ih for qemu-trivial@nongnu.org; Wed, 10 Oct 2012 12:23:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLz4V-000704-RU for qemu-trivial@nongnu.org; Wed, 10 Oct 2012 12:23:55 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:41204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLz4D-0006vK-Vy; Wed, 10 Oct 2012 12:23:30 -0400 Received: from localhost (v220110690675601.yourvserver.net.local [127.0.0.1]) by v220110690675601.yourvserver.net (Postfix) with ESMTP id 7A2AB7280041; Wed, 10 Oct 2012 18:23:28 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at weilnetz.de Received: from v220110690675601.yourvserver.net ([127.0.0.1]) by localhost (v220110690675601.yourvserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LEsaPEfDQYdD; Wed, 10 Oct 2012 18:23:28 +0200 (CEST) Received: from [192.168.178.20] (p5086E9D6.dip.t-dialin.net [80.134.233.214]) by v220110690675601.yourvserver.net (Postfix) with ESMTPSA id E9DF3728003D; Wed, 10 Oct 2012 18:23:27 +0200 (CEST) Message-ID: <5075A0FF.3080904@weilnetz.de> Date: Wed, 10 Oct 2012 18:23:27 +0200 From: Stefan Weil User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1 MIME-Version: 1.0 To: Paolo Bonzini References: <1349868762-10021-1-git-send-email-pbonzini@redhat.com> <50759EEC.8070308@weilnetz.de> <50759F9E.3060800@redhat.com> In-Reply-To: <50759F9E.3060800@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 78.47.199.172 Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] virtfs-proxy-helper: check return code of setfsgid/setfsuid X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Oct 2012 16:24:00 -0000 Am 10.10.2012 18:17, schrieb Paolo Bonzini: > Il 10/10/2012 18:14, Stefan Weil ha scritto: >>> >>> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c >>> index f9a8270..b34a84a 100644 >>> --- a/fsdev/virtfs-proxy-helper.c >>> +++ b/fsdev/virtfs-proxy-helper.c >>> @@ -290,8 +290,12 @@ static int setfsugid(int uid, int gid) >>> CAP_DAC_OVERRIDE, >>> }; >>> - setfsgid(gid); >>> - setfsuid(uid); >>> + if (setfsgid(gid) != 0) { >>> + return -1; >>> + } >> Wouldn't setfsgid(gid) == gid be also ok? > Of course, it should be < 0. I have no idea how to test this thing... > > Paolo < 0 would be wrong because it looks like both functions never return negative values. I just wrote a small test program (see below) and called it with different uids with and without root rights. This pattern should be fine: new_uid = setfsuid(uid); if (new_uid != 0 && new_uid != uid) { return -1; } Stefan #include #include #include /* glibc uses */ #include int main(int argc, char *argv[]) { uid_t fsuid = strtoul(argv[1], 0, 0); int r = setfsuid(fsuid); printf("setfsuid(%u) returned %u\n", fsuid, r); return 0; }