* [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls
@ 2024-11-05 15:15 Helge Deller
2024-11-05 15:59 ` Ilya Leoshkevich
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Helge Deller @ 2024-11-05 15:15 UTC (permalink / raw)
To: Laurent Vivier, Peter Maydell, Riku Voipio, qemu-devel
The commit fd6f7798ac30 ("linux-user: Use direct syscalls for setuid(),
etc") added direct syscall wrappers for setuid(), setgid(), etc since the
system calls have different semantics than the libc functions.
Add and use the corresponding wrappers for setreuid and setregid which
were missed in that commit.
This fixes the build of the debian package of the uid_wrapper library
(https://cwrap.org/uid_wrapper.html) when running linux-user.
Signed-off-by: Helge Deller <deller@gmx.de>
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 59b2080b98..0279f23576 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7233,12 +7233,24 @@ static inline int tswapid(int id)
#else
#define __NR_sys_setgroups __NR_setgroups
#endif
+#ifdef __NR_sys_setreuid32
+#define __NR_sys_setreuid __NR_setreuid32
+#else
+#define __NR_sys_setreuid __NR_setreuid
+#endif
+#ifdef __NR_sys_setregid32
+#define __NR_sys_setregid __NR_setregid32
+#else
+#define __NR_sys_setregid __NR_setregid
+#endif
_syscall1(int, sys_setuid, uid_t, uid)
_syscall1(int, sys_setgid, gid_t, gid)
_syscall3(int, sys_setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
_syscall3(int, sys_setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
_syscall2(int, sys_setgroups, int, size, gid_t *, grouplist)
+_syscall2(int, sys_setreuid, uid_t, ruid, uid_t, euid);
+_syscall2(int, sys_setregid, gid_t, rgid, gid_t, egid);
void syscall_init(void)
{
@@ -11932,9 +11944,9 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
return get_errno(high2lowgid(getegid()));
#endif
case TARGET_NR_setreuid:
- return get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
+ return get_errno(sys_setreuid(low2highuid(arg1), low2highuid(arg2)));
case TARGET_NR_setregid:
- return get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
+ return get_errno(sys_setregid(low2highgid(arg1), low2highgid(arg2)));
case TARGET_NR_getgroups:
{ /* the same code as for TARGET_NR_getgroups32 */
int gidsetsize = arg1;
@@ -12264,11 +12276,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
#endif
#ifdef TARGET_NR_setreuid32
case TARGET_NR_setreuid32:
- return get_errno(setreuid(arg1, arg2));
+ return get_errno(sys_setreuid(arg1, arg2));
#endif
#ifdef TARGET_NR_setregid32
case TARGET_NR_setregid32:
- return get_errno(setregid(arg1, arg2));
+ return get_errno(sys_setregid(arg1, arg2));
#endif
#ifdef TARGET_NR_getgroups32
case TARGET_NR_getgroups32:
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls
2024-11-05 15:15 [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls Helge Deller
@ 2024-11-05 15:59 ` Ilya Leoshkevich
2024-11-06 9:58 ` Richard Henderson
2024-11-06 10:12 ` Richard Henderson
2 siblings, 0 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2024-11-05 15:59 UTC (permalink / raw)
To: Helge Deller, Laurent Vivier, Peter Maydell, Riku Voipio,
qemu-devel
On Tue, 2024-11-05 at 16:15 +0100, Helge Deller wrote:
> The commit fd6f7798ac30 ("linux-user: Use direct syscalls for
> setuid(),
> etc") added direct syscall wrappers for setuid(), setgid(), etc since
> the
> system calls have different semantics than the libc functions.
>
> Add and use the corresponding wrappers for setreuid and setregid
> which
> were missed in that commit.
>
> This fixes the build of the debian package of the uid_wrapper library
> (https://cwrap.org/uid_wrapper.html) when running linux-user.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
I should've checked the other syscalls when fixing setgroups recently.
Seems like with this patch, linux-user will no longer call glibc
functions that use INLINE_SETXID_SYSCALL().
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls
2024-11-05 15:15 [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls Helge Deller
2024-11-05 15:59 ` Ilya Leoshkevich
@ 2024-11-06 9:58 ` Richard Henderson
2024-11-06 10:12 ` Richard Henderson
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2024-11-06 9:58 UTC (permalink / raw)
To: Helge Deller, Laurent Vivier, Peter Maydell, Riku Voipio,
qemu-devel
On 11/5/24 15:15, Helge Deller wrote:
> The commit fd6f7798ac30 ("linux-user: Use direct syscalls for setuid(),
> etc") added direct syscall wrappers for setuid(), setgid(), etc since the
> system calls have different semantics than the libc functions.
>
> Add and use the corresponding wrappers for setreuid and setregid which
> were missed in that commit.
>
> This fixes the build of the debian package of the uid_wrapper library
> (https://cwrap.org/uid_wrapper.html) when running linux-user.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls
2024-11-05 15:15 [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls Helge Deller
2024-11-05 15:59 ` Ilya Leoshkevich
2024-11-06 9:58 ` Richard Henderson
@ 2024-11-06 10:12 ` Richard Henderson
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2024-11-06 10:12 UTC (permalink / raw)
To: Helge Deller, Laurent Vivier, Peter Maydell, Riku Voipio,
qemu-devel
On 11/5/24 15:15, Helge Deller wrote:
> The commit fd6f7798ac30 ("linux-user: Use direct syscalls for setuid(),
> etc") added direct syscall wrappers for setuid(), setgid(), etc since the
> system calls have different semantics than the libc functions.
>
> Add and use the corresponding wrappers for setreuid and setregid which
> were missed in that commit.
>
> This fixes the build of the debian package of the uid_wrapper library
> (https://cwrap.org/uid_wrapper.html) when running linux-user.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 59b2080b98..0279f23576 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7233,12 +7233,24 @@ static inline int tswapid(int id)
> #else
> #define __NR_sys_setgroups __NR_setgroups
> #endif
> +#ifdef __NR_sys_setreuid32
> +#define __NR_sys_setreuid __NR_setreuid32
> +#else
> +#define __NR_sys_setreuid __NR_setreuid
> +#endif
> +#ifdef __NR_sys_setregid32
> +#define __NR_sys_setregid __NR_setregid32
> +#else
> +#define __NR_sys_setregid __NR_setregid
> +#endif
>
> _syscall1(int, sys_setuid, uid_t, uid)
> _syscall1(int, sys_setgid, gid_t, gid)
> _syscall3(int, sys_setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
> _syscall3(int, sys_setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
> _syscall2(int, sys_setgroups, int, size, gid_t *, grouplist)
> +_syscall2(int, sys_setreuid, uid_t, ruid, uid_t, euid);
> +_syscall2(int, sys_setregid, gid_t, rgid, gid_t, egid);
>
> void syscall_init(void)
> {
> @@ -11932,9 +11944,9 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> return get_errno(high2lowgid(getegid()));
> #endif
> case TARGET_NR_setreuid:
> - return get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
> + return get_errno(sys_setreuid(low2highuid(arg1), low2highuid(arg2)));
> case TARGET_NR_setregid:
> - return get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
> + return get_errno(sys_setregid(low2highgid(arg1), low2highgid(arg2)));
> case TARGET_NR_getgroups:
> { /* the same code as for TARGET_NR_getgroups32 */
> int gidsetsize = arg1;
> @@ -12264,11 +12276,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> #endif
> #ifdef TARGET_NR_setreuid32
> case TARGET_NR_setreuid32:
> - return get_errno(setreuid(arg1, arg2));
> + return get_errno(sys_setreuid(arg1, arg2));
> #endif
> #ifdef TARGET_NR_setregid32
> case TARGET_NR_setregid32:
> - return get_errno(setregid(arg1, arg2));
> + return get_errno(sys_setregid(arg1, arg2));
> #endif
> #ifdef TARGET_NR_getgroups32
> case TARGET_NR_getgroups32:
>
Queued, thanks.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-06 10:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05 15:15 [PATCH] linux-user: Fix setreuid and setregid to use direct syscalls Helge Deller
2024-11-05 15:59 ` Ilya Leoshkevich
2024-11-06 9:58 ` Richard Henderson
2024-11-06 10:12 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).