Skip to contentSkip to conversation

linux-user: Small fix for copy_file_range

PATCH Applied LemonBoy 2 participants 6 messages May 3, 2021 – May 15, 2021

lore
Share & tools
lore

LemonBoy

author
#0 lore raw

cover linux-user: Small fix for copy_file_range

From: Giuseppe Musacchio <[email protected]>

An unwanted sign-extension is currently making the host kernel return EOVERFLOW when calling copy_file_range with a count of 0xffffffff, despite the host being a 64bit platform.

The fix is only affecting 32bit targets on 64bit hosts, it's a no-op when the target bitness matches the host one.

As a bonus add a pretty-printer for copy_file_range syscall.

Giuseppe Musacchio (2):
linux-user: Add copy_file_range to strace.list
linux-user: Fix erroneous conversion in copy_file_range

 linux-user/strace.list | 3 +++
 linux-user/syscall.c   | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.30.2
author
#1 lore raw

PATCH 1/2 linux-user: Add copy_file_range to strace.list

From: Giuseppe Musacchio <[email protected]>

---
 linux-user/strace.list | 3 +++
 1 file changed, 3 insertions(+)
linux-user/strace.list +3 -0
index 084048ab96..b81f9964e3 100644
@@ -1665,3 +1665,6 @@
 #ifdef TARGET_NR_statx
 { TARGET_NR_statx, "statx", NULL, print_statx, NULL },
 #endif
+#ifdef TARGET_NR_copy_file_range
+{ TARGET_NR_copy_file_range, "copy_file_range", "%s(%d,%p,%d,%p,"TARGET_ABI_FMT_lu",%u)", NULL, NULL },
+#endif
Signature · 1 line
2.30.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] linux-user: Add copy_file_range to strace.list

Le 03/05/2021 à 19:41, LemonBoy a écrit :

Quoted 13 lines

From: Giuseppe Musacchio <[email protected]>

---
 linux-user/strace.list | 3 +++
 1 file changed, 3 insertions(+)
linux-user/strace.list +0 -0
index 084048ab96..b81f9964e3 100644

linux-user/strace.list line 1670

Quoted 6 lines
linux-user/strace.list +3 -0
@@ -1665,3 +1665,6 @@
 #ifdef TARGET_NR_statx
 { TARGET_NR_statx, "statx", NULL, print_statx, NULL },
 #endif
+#ifdef TARGET_NR_copy_file_range
+{ TARGET_NR_copy_file_range, "copy_file_range", "%s(%d,%p,%d,%p,"TARGET_ABI_FMT_lu",%u)", NULL, NULL },
+#endif
author
#3 lore raw

PATCH 2/2 linux-user: Fix erroneous conversion in copy_file_range

In reply to LemonBoy

From: Giuseppe Musacchio <[email protected]>

The implicit cast from abi_long to size_t may introduce an intermediate unwanted sign-extension of the value for 32bit targets running on 64bit hosts.

---
 linux-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/syscall.c +2 -1
index 95d79ddc43..c425dfa278 100644
@@ -13245,8 +13245,9 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
                 }
                 poutoff = &outoff;
             }
+            /* Do not sign-extend the count parameter. */
             ret = get_errno(safe_copy_file_range(arg1, pinoff, arg3, poutoff,
-                                                 arg5, arg6));
+                                                 (abi_ulong)arg5, arg6));
             if (!is_error(ret) && ret > 0) {
                 if (arg2) {
                     if (put_user_u64(inoff, arg2)) {
Signature · 1 line
2.30.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] linux-user: Fix erroneous conversion in copy_file_range

Le 03/05/2021 à 19:41, LemonBoy a écrit :

Quoted 17 lines

From: Giuseppe Musacchio <[email protected]>

The implicit cast from abi_long to size_t may introduce an intermediate unwanted sign-extension of the value for 32bit targets running on 64bit hosts.

---
 linux-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 95d79ddc43..c425dfa278 100644

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 13253

Quoted 10 lines
linux-user/syscall.c +2 -1
@@ -13245,8 +13245,9 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
                 }
                 poutoff = &outoff;
             }
+            /* Do not sign-extend the count parameter. */
             ret = get_errno(safe_copy_file_range(arg1, pinoff, arg3, poutoff,
-                                                 arg5, arg6));
+                                                 (abi_ulong)arg5, arg6));
             if (!is_error(ret) && ret > 0) {
                 if (arg2) {
                     if (put_user_u64(inoff, arg2)) {
#5 lore raw
In reply to LemonBoy

Le 03/05/2021 à 19:41, LemonBoy a écrit :

Quoted 11 lines

From: Giuseppe Musacchio <[email protected]>

An unwanted sign-extension is currently making the host kernel return EOVERFLOW when calling copy_file_range with a count of 0xffffffff, despite the host being a 64bit platform.

The fix is only affecting 32bit targets on 64bit hosts, it's a no-op when the target bitness matches the host one.

As a bonus add a pretty-printer for copy_file_range syscall.

Quoted 8 lines

Giuseppe Musacchio (2):
linux-user: Add copy_file_range to strace.list
linux-user: Fix erroneous conversion in copy_file_range

 linux-user/strace.list | 3 +++
 linux-user/syscall.c   | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

Applied to my linux-user-for-6.1 branch.

Thanks,
Laurent