From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TM0UT-0003NN-O7 for qemu-devel@nongnu.org; Wed, 10 Oct 2012 13:54:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TM0UO-0006vb-4l for qemu-devel@nongnu.org; Wed, 10 Oct 2012 13:54:41 -0400 Message-ID: <5075A9B4.4080407@redhat.com> Date: Wed, 10 Oct 2012 19:00:36 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1349868762-10021-1-git-send-email-pbonzini@redhat.com> <50759EEC.8070308@weilnetz.de> <50759F9E.3060800@redhat.com> <5075A0FF.3080904@weilnetz.de> <5075A420.10003@redhat.com> <5075A843.8020107@weilnetz.de> In-Reply-To: <5075A843.8020107@weilnetz.de> Content-Type: text/plain; charset=UTF-8 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: Stefan Weil Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org Il 10/10/2012 18:54, Stefan Weil ha scritto: >> >> if (setfsuid(uid) < 0 || setfsuid(uid) != uid) { >> return -1; >> } >> >> but it seems wasteful to do four syscalls instead of two. > > I added a local variable in my example to avoid those extra > syscalls. Note that the two setfsuid() calls are different. The first checks the "-1" error from glibc. The second says "if the first call succeeded, the second call should see "uid" as the current fsuid and the second call will be a no-op; if not, the first call must have failed". > The functions have an additional problem: they don't set > errno (see manpages). I tested this, and here the manpages > are correct. The code in virtfs-proxy-helper expects that > errno was set, so the patch must set errno = EPERM or > something like that. So it would be if (setfsuid(uid) < 0) { return -1; } if (setfsuid(uid) != uid) { errno = EPERM; return -1; } I still prefer my v2 (v1 is wrong). The return path seems to be dead, but it's not worse than before... Paolo