Received: from eggs.gnu.org ([208.118.235.92]:34966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLz4N-0002Ox-QL for qemu-devel@nongnu.org; Wed, 10 Oct 2012 12:23:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLz4E-0006vf-6e for qemu-devel@nongnu.org; Wed, 10 Oct 2012 12:23:39 -0400 Message-ID: <5075A0FF.3080904@weilnetz.de> Date: Wed, 10 Oct 2012 18:23:27 +0200 From: Stefan Weil MIME-Version: 1.0 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 Subject: Re: [Qemu-devel] [PATCH] virtfs-proxy-helper: check return code of setfsgid/setfsuid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org 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; }