fsdev: Don't ignore setfsuid/setfsgid return values
PATCH 1/1 fsdev: Don't ignore setfsuid/setfsgid return values
From: "M. Mohan Kumar" <[email protected]>
In current implementation of setfsuid/setfsgid there is no way to know if it failed by checking the return value. This patch assumes setfsuid/setfsgid returns -1 in case of error. Eventually kernel code needs to be fixed.
--- fsdev/virtfs-proxy-helper.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fsdev/virtfs-proxy-helper.c +6 -3
@@ -290,9 +290,12 @@ static int setfsugid(int uid, int gid) CAP_DAC_OVERRIDE, }; -setfsgid (gid); -setfsuid (uid); - +if (setfsgid (gid) <0 ) { +return -errno; + } +if (setfsuid (uid) <0 ) { +return -errno; + }if (uid !=0 || gid !=0 ) {return do_cap_set (cap_list,ARRAY_SIZE (cap_list),0 ); }
Signature · 1 line
1.7.11.4
Quoted 6 lines · M. Mohan Kumar
From: "M. Mohan Kumar" <[email protected]>
In current implementation of setfsuid/setfsgid there is no way to know if it failed by checking the return value. This patch assumes setfsuid/setfsgid returns -1 in case of error. Eventually kernel code needs to be fixed.
According to the Fedora 17 man page:
RETURN VALUE
On success, the previous value of fsuid is returned. On error,
the current value of fsuid is returned.
NOTES
When glibc determines that the argument is not a valid user ID, it
will return -1 and set errno to EINVAL without attempting the system call.
BUGS
No error messages of any kind are returned to the caller. At the
very least, EPERM should be returned when the call fails (because the
caller lacks the CAP_SETUID capability).
Eww - self-contradictory. I think the reason that F17 marked these functions warn_unused_return is because there HAS been an effort to make these functions return sane values that can be used to detect when errors have occurred.
Quoted 13 lines
Signed-off-by M. Mohan Kumar <[email protected]>--- fsdev/virtfs-proxy-helper.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)fsdev/virtfs-proxy-helper.c +0
-0@@ -290,9 +290,12 @@ static int setfsugid(int uid, int gid) CAP_DAC_OVERRIDE, };
fsdev/virtfs-proxy-helper.c static int setfsugid(int uid, int gid) · line 298
Quoted 10 lines
fsdev/virtfs-proxy-helper.c +6
-3-setfsgid (gid); -setfsuid (uid); - +if (setfsgid (gid) <0 ) { +return -errno; + } +if (setfsuid (uid) <0 ) { +return -errno; + }
At any rate, this silences the compiler warning I was hitting, so:
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org