* [PATCH] linux-user: Implement fchmodat2 syscall
@ 2025-07-08 16:10 Peter Maydell
2025-07-09 13:55 ` Richard Henderson
0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2025-07-08 16:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
The fchmodat2 syscall is new from Linux 6.6; it is like the
existing fchmodat syscall except that it takes a flags parameter.
If we have the host fchmodat2 syscall, we implement it as a
direct passthrough call; if we do not, then we can fall back
to using the libc fchmodat() function. The fallback can
handle the AT_SYMLINK_NOFOLLOW flag but won't be able to
do anything about AT_EMPTY_PATH.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Tested very lightly (ran an fchmodat2 test from the
Linux Test Project test suite).
You could argue that the fallback-to-libc-fchmodat here isn't
worth bothering with, I guess.
linux-user/syscall.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fc37028597c..827b432bb31 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -790,6 +790,10 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, loff_t *, pinoff,
int, outfd, loff_t *, poutoff, size_t, length,
unsigned int, flags)
#endif
+#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
+safe_syscall4(int, fchmodat2, int, dfd, const char *, filename,
+ unsigned short, mode, unsigned int, flags)
+#endif
/* We do ioctl like this rather than via safe_syscall3 to preserve the
* "third argument might be integer or pointer or not present" behaviour of
@@ -10713,6 +10717,22 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
ret = get_errno(fchmodat(arg1, p, arg3, 0));
unlock_user(p, arg2, 0);
return ret;
+#endif
+#if defined(TARGET_NR_fchmodat2)
+ case TARGET_NR_fchmodat2:
+ if (!(p = lock_user_string(arg2)))
+ return -TARGET_EFAULT;
+#if defined(__NR_fchmodat2)
+ ret = get_errno(safe_fchmodat2(arg1, p, arg3, arg4));
+#else
+ /*
+ * fall back to using libc function: this will work for
+ * flag AT_SYMLINK_NOFOLLOW but not AT_EMPTY_PATH.
+ */
+ ret = get_errno(fchmodat(arg1, p, arg3, arg4));
+#endif
+ unlock_user(p, arg2, 0);
+ return ret;
#endif
case TARGET_NR_getpriority:
/* Note that negative values are valid for getpriority, so we must
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] linux-user: Implement fchmodat2 syscall
2025-07-08 16:10 Peter Maydell
@ 2025-07-09 13:55 ` Richard Henderson
0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2025-07-09 13:55 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Laurent Vivier
On 7/8/25 10:10, Peter Maydell wrote:
> You could argue that the fallback-to-libc-fchmodat here isn't
> worth bothering with, I guess.
Indeed not. Support for fchmodat2 is at least 2 years old already.
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] linux-user: Implement fchmodat2 syscall
@ 2025-07-10 11:31 Peter Maydell
2025-07-10 11:36 ` [PATCH v2] " Peter Maydell
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Peter Maydell @ 2025-07-10 11:31 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Richard Henderson
The fchmodat2 syscall is new from Linux 6.6; it is like the
existing fchmodat syscall except that it takes a flags parameter.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
v1->v2: don't bother with trying to fall back to libc fchmodat();
add missing braces for if()
---
linux-user/syscall.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fc37028597c..e1b1476936c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -790,6 +790,10 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, loff_t *, pinoff,
int, outfd, loff_t *, poutoff, size_t, length,
unsigned int, flags)
#endif
+#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
+safe_syscall4(int, fchmodat2, int, dfd, const char *, filename,
+ unsigned short, mode, unsigned int, flags)
+#endif
/* We do ioctl like this rather than via safe_syscall3 to preserve the
* "third argument might be integer or pointer or not present" behaviour of
@@ -10713,6 +10717,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
ret = get_errno(fchmodat(arg1, p, arg3, 0));
unlock_user(p, arg2, 0);
return ret;
+#endif
+#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
+ case TARGET_NR_fchmodat2:
+ if (!(p = lock_user_string(arg2))) {
+ return -TARGET_EFAULT;
+ }
+ ret = get_errno(safe_fchmodat2(arg1, p, arg3, arg4));
+ unlock_user(p, arg2, 0);
+ return ret;
#endif
case TARGET_NR_getpriority:
/* Note that negative values are valid for getpriority, so we must
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2] linux-user: Implement fchmodat2 syscall
2025-07-10 11:31 [PATCH] linux-user: Implement fchmodat2 syscall Peter Maydell
@ 2025-07-10 11:36 ` Peter Maydell
2025-07-10 11:39 ` Peter Maydell
2025-07-10 13:58 ` [PATCH] " Philippe Mathieu-Daudé
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2025-07-10 11:36 UTC (permalink / raw)
To: QEMU Developers; +Cc: Laurent Vivier, Richard Henderson
On Thu, 10 Jul 2025 at 12:31, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> The fchmodat2 syscall is new from Linux 6.6; it is like the
> existing fchmodat syscall except that it takes a flags parameter.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> v1->v2: don't bother with trying to fall back to libc fchmodat();
> add missing braces for if()
I forgot to put 'v2' in the subject, but this is indeed version 2 :-)
> ---
> linux-user/syscall.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index fc37028597c..e1b1476936c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -790,6 +790,10 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, loff_t *, pinoff,
> int, outfd, loff_t *, poutoff, size_t, length,
> unsigned int, flags)
> #endif
> +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
> +safe_syscall4(int, fchmodat2, int, dfd, const char *, filename,
> + unsigned short, mode, unsigned int, flags)
> +#endif
>
> /* We do ioctl like this rather than via safe_syscall3 to preserve the
> * "third argument might be integer or pointer or not present" behaviour of
> @@ -10713,6 +10717,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> ret = get_errno(fchmodat(arg1, p, arg3, 0));
> unlock_user(p, arg2, 0);
> return ret;
> +#endif
> +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
> + case TARGET_NR_fchmodat2:
> + if (!(p = lock_user_string(arg2))) {
> + return -TARGET_EFAULT;
> + }
> + ret = get_errno(safe_fchmodat2(arg1, p, arg3, arg4));
> + unlock_user(p, arg2, 0);
> + return ret;
> #endif
> case TARGET_NR_getpriority:
> /* Note that negative values are valid for getpriority, so we must
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2] linux-user: Implement fchmodat2 syscall
2025-07-10 11:36 ` [PATCH v2] " Peter Maydell
@ 2025-07-10 11:39 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2025-07-10 11:39 UTC (permalink / raw)
To: QEMU Developers; +Cc: Laurent Vivier, Richard Henderson
On Thu, 10 Jul 2025 at 12:36, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Thu, 10 Jul 2025 at 12:31, Peter Maydell <peter.maydell@linaro.org> wrote:
> >
> > The fchmodat2 syscall is new from Linux 6.6; it is like the
> > existing fchmodat syscall except that it takes a flags parameter.
> >
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > ---
> > v1->v2: don't bother with trying to fall back to libc fchmodat();
> > add missing braces for if()
>
> I forgot to put 'v2' in the subject, but this is indeed version 2 :-)
Oh, and also
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3019
thanks
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] linux-user: Implement fchmodat2 syscall
2025-07-10 11:31 [PATCH] linux-user: Implement fchmodat2 syscall Peter Maydell
2025-07-10 11:36 ` [PATCH v2] " Peter Maydell
@ 2025-07-10 13:58 ` Philippe Mathieu-Daudé
2025-07-10 16:20 ` Richard Henderson
2025-07-10 17:54 ` Richard Henderson
3 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-10 13:58 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Laurent Vivier, Richard Henderson
On 10/7/25 13:31, Peter Maydell wrote:
> The fchmodat2 syscall is new from Linux 6.6; it is like the
> existing fchmodat syscall except that it takes a flags parameter.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> v1->v2: don't bother with trying to fall back to libc fchmodat();
> add missing braces for if()
> ---
> linux-user/syscall.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] linux-user: Implement fchmodat2 syscall
2025-07-10 11:31 [PATCH] linux-user: Implement fchmodat2 syscall Peter Maydell
2025-07-10 11:36 ` [PATCH v2] " Peter Maydell
2025-07-10 13:58 ` [PATCH] " Philippe Mathieu-Daudé
@ 2025-07-10 16:20 ` Richard Henderson
2025-07-10 17:54 ` Richard Henderson
3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2025-07-10 16:20 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Laurent Vivier
On 7/10/25 05:31, Peter Maydell wrote:
> The fchmodat2 syscall is new from Linux 6.6; it is like the
> existing fchmodat syscall except that it takes a flags parameter.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> v1->v2: don't bother with trying to fall back to libc fchmodat();
> add missing braces for if()
> ---
> linux-user/syscall.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index fc37028597c..e1b1476936c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -790,6 +790,10 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, loff_t *, pinoff,
> int, outfd, loff_t *, poutoff, size_t, length,
> unsigned int, flags)
> #endif
> +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
> +safe_syscall4(int, fchmodat2, int, dfd, const char *, filename,
> + unsigned short, mode, unsigned int, flags)
> +#endif
>
> /* We do ioctl like this rather than via safe_syscall3 to preserve the
> * "third argument might be integer or pointer or not present" behaviour of
> @@ -10713,6 +10717,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
> ret = get_errno(fchmodat(arg1, p, arg3, 0));
> unlock_user(p, arg2, 0);
> return ret;
> +#endif
> +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2)
> + case TARGET_NR_fchmodat2:
> + if (!(p = lock_user_string(arg2))) {
> + return -TARGET_EFAULT;
> + }
> + ret = get_errno(safe_fchmodat2(arg1, p, arg3, arg4));
> + unlock_user(p, arg2, 0);
> + return ret;
> #endif
> case TARGET_NR_getpriority:
> /* Note that negative values are valid for getpriority, so we must
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] linux-user: Implement fchmodat2 syscall
2025-07-10 11:31 [PATCH] linux-user: Implement fchmodat2 syscall Peter Maydell
` (2 preceding siblings ...)
2025-07-10 16:20 ` Richard Henderson
@ 2025-07-10 17:54 ` Richard Henderson
3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2025-07-10 17:54 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Laurent Vivier
On 7/10/25 05:31, Peter Maydell wrote:
> The fchmodat2 syscall is new from Linux 6.6; it is like the
> existing fchmodat syscall except that it takes a flags parameter.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> v1->v2: don't bother with trying to fall back to libc fchmodat();
> add missing braces for if()
Queued.
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-07-10 18:36 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-10 11:31 [PATCH] linux-user: Implement fchmodat2 syscall Peter Maydell
2025-07-10 11:36 ` [PATCH v2] " Peter Maydell
2025-07-10 11:39 ` Peter Maydell
2025-07-10 13:58 ` [PATCH] " Philippe Mathieu-Daudé
2025-07-10 16:20 ` Richard Henderson
2025-07-10 17:54 ` Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
2025-07-08 16:10 Peter Maydell
2025-07-09 13:55 ` 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).