[PATCH v3] linux-user: allow null `pathname` for statx()/fstatat()

Jean-Christian CÎRSTEA posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251229121416.2209295-1-jean.christian.cirstea@gmail.com
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/syscall.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
[PATCH v3] linux-user: allow null `pathname` for statx()/fstatat()
Posted by Jean-Christian CÎRSTEA 1 month, 1 week ago
Since Linux 6.11, the path argument may be NULL.

Before this patch, qemu-*-linux-user failed with EFAULT when `pathname` was
specified as NULL, even for Linux kernel hosts > 6.10. This patch fixes this
issue by checking whether `arg2` is 0. If so, don't return EFAULT, but instead
perform the appropiate syscall and let the host's kernel handle null `pathname`.

Changelog v3:

1. Don't call `lock_user_string()` when arg2 is NULL.

Changelog v2:

1. Removed cover letter

Signed-off-by: Jean-Christian CÎRSTEA <jean.christian.cirstea@gmail.com>
---
 linux-user/syscall.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2060e561a2..ee7c34027e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -12141,9 +12141,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
             int dirfd = arg1;
             int flags = arg3;
 
-            p = lock_user_string(arg2);
-            if (p == NULL) {
-                return -TARGET_EFAULT;
+            p = NULL;
+            /* Since Linux 6.11, the path argument may be NULL */
+            if (arg2 != 0) {
+                p = lock_user_string(arg2);
+                if (p == NULL) {
+                    return -TARGET_EFAULT;
+                }
             }
 #if defined(__NR_statx)
             {
-- 
2.51.0


Re: [PATCH v3] linux-user: allow null `pathname` for statx()/fstatat()
Posted by Richard Henderson 1 month ago
On 12/29/25 23:14, Jean-Christian CÎRSTEA wrote:
> Since Linux 6.11, the path argument may be NULL.
> 
> Before this patch, qemu-*-linux-user failed with EFAULT when `pathname` was
> specified as NULL, even for Linux kernel hosts > 6.10. This patch fixes this
> issue by checking whether `arg2` is 0. If so, don't return EFAULT, but instead
> perform the appropiate syscall and let the host's kernel handle null `pathname`.

Queued, thanks.

r~

Re: [PATCH v3] linux-user: allow null `pathname` for statx()/fstatat()
Posted by Richard Henderson 1 month ago
On 12/29/25 23:14, Jean-Christian CÎRSTEA wrote:
> Since Linux 6.11, the path argument may be NULL.
> 
> Before this patch, qemu-*-linux-user failed with EFAULT when `pathname` was
> specified as NULL, even for Linux kernel hosts > 6.10. This patch fixes this
> issue by checking whether `arg2` is 0. If so, don't return EFAULT, but instead
> perform the appropiate syscall and let the host's kernel handle null `pathname`.
> 
> Changelog v3:
> 
> 1. Don't call `lock_user_string()` when arg2 is NULL.
> 
> Changelog v2:
> 
> 1. Removed cover letter
> 
> Signed-off-by: Jean-Christian CÎRSTEA<jean.christian.cirstea@gmail.com>
> ---
>   linux-user/syscall.c | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~