Skip to contentSkip to conversation

linux-user: Implement fchmodat2 syscall

PATCH In review Peter Maydell 3 participants 6 messages Jul 10, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Implement fchmodat2 syscall

The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter.

---
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(+)
linux-user/syscall.c +13 -0
index fc37028597c..e1b1476936c 100644
@@ -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
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Peter Maydell

The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter.

---
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 :-)

Quoted 38 lines
---
 linux-user/syscall.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
linux-user/syscall.c +13 -1
index fc37028597c..e1b1476936c 100644
@@ -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

#2 lore raw
Quoted 6 lines · Peter Maydell
Quoted 4 lines · Peter Maydell

The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter.

Quoted 6 lines
Quoted 4 lines

---
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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter.

---
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 on v1 1/1
#4 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter.

---
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(+)

r~

Quoted 32 lines
linux-user/syscall.c +13 -0
index fc37028597c..e1b1476936c 100644
@@ -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