Skip to contentSkip to conversation

Fix emulation of splice syscall

PATCH In review Andreas Schwab 2 participants 6 messages Feb 4, 2015 – Feb 5, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix emulation of splice syscall

The second and fourth argument are in/out parameters, store them back after the syscall. Also, the fourth argument was mishandled, and EFAULT handling was missing.

---
 linux-user/syscall.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
linux-user/syscall.c +13 -3
index d4398b9..db2f5c7 100644
@@ -9345,14 +9345,24 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             loff_t loff_in, loff_out;
             loff_t *ploff_in = NULL, *ploff_out = NULL;
             if(arg2) {
-                get_user_u64(loff_in, arg2);
+                if (get_user_u64(loff_in, arg2))
+                    goto efault;
                 ploff_in = &loff_in;
             }
-            if(arg4) {
-                get_user_u64(loff_out, arg2);
+            if (arg4) {
+                if (get_user_u64(loff_out, arg4))
+                    goto efault;
                 ploff_out = &loff_out;
             }
             ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
+            if (arg2) {
+                if (put_user_u64(loff_in, arg2))
+                    goto efault;
+            }
+            if (arg4) {
+                if (put_user_u64(loff_out, arg4))
+                    goto efault;
+	    }
         }
         break;
 #endif
Signature · 6 lines
2.2.2

-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Andreas Schwab

The second and fourth argument are in/out parameters, store them back after the syscall. Also, the fourth argument was mishandled, and EFAULT handling was missing.

---
 linux-user/syscall.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
linux-user/syscall.c +0 -0
index d4398b9..db2f5c7 100644

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 9349

Quoted 6 lines
linux-user/syscall.c +2 -1
@@ -9345,14 +9345,24 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             loff_t loff_in, loff_out;
             loff_t *ploff_in = NULL, *ploff_out = NULL;
             if(arg2) {
-                get_user_u64(loff_in, arg2);
+                if (get_user_u64(loff_in, arg2))
+                    goto efault;

Coding style demands braces for all these if statements. Otherwise

-- PMM

#2 lore raw
Quoted 1 line · Peter Maydell

Coding style demands braces for all these if statements.

That must be a recent change.

Andreas.

Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#3 lore raw
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Peter Maydell

Coding style demands braces for all these if statements.

That must be a recent change.

It's been documented in CODING_STYLE since we first wrote down our style choices in 2009...

There is of course still a fair amount of older code which doesn't follow the style, but we try to follow it for new code that gets added.

-- PMM

#4 lore raw

PATCH 1/1 Fix emulation of splice syscall

In reply to Andreas Schwab

The second and fourth argument are in/out parameters, store them back after the syscall. Also, the fourth argument was mishandled, and EFAULT handling was missing.

---
 linux-user/syscall.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
linux-user/syscall.c +18 -4
index d4398b9..550aafe 100644
@@ -9344,15 +9344,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             loff_t loff_in, loff_out;
             loff_t *ploff_in = NULL, *ploff_out = NULL;
-            if(arg2) {
-                get_user_u64(loff_in, arg2);
+            if (arg2) {
+                if (get_user_u64(loff_in, arg2)) {
+                    goto efault;
+                }
                 ploff_in = &loff_in;
             }
-            if(arg4) {
-                get_user_u64(loff_out, arg2);
+            if (arg4) {
+                if (get_user_u64(loff_out, arg4)) {
+                    goto efault;
+                }
                 ploff_out = &loff_out;
             }
             ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
+            if (arg2) {
+                if (put_user_u64(loff_in, arg2)) {
+                    goto efault;
+                }
+            }
+            if (arg4) {
+                if (put_user_u64(loff_out, arg4)) {
+                    goto efault;
+                }
+            }
         }
         break;
 #endif
Signature · 7 lines
2.2.2


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reviewed-by on v1 1/1
#5 lore raw
Quoted 5 lines · Andreas Schwab

The second and fourth argument are in/out parameters, store them back after the syscall. Also, the fourth argument was mishandled, and EFAULT handling was missing.

and cc'ing Riku as linux-user maintainer.

-- PMM

Quoted 45 lines
---
 linux-user/syscall.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
linux-user/syscall.c +18 -5
index d4398b9..550aafe 100644
@@ -9344,15 +9344,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             loff_t loff_in, loff_out;
             loff_t *ploff_in = NULL, *ploff_out = NULL;
-            if(arg2) {
-                get_user_u64(loff_in, arg2);
+            if (arg2) {
+                if (get_user_u64(loff_in, arg2)) {
+                    goto efault;
+                }
                 ploff_in = &loff_in;
             }
-            if(arg4) {
-                get_user_u64(loff_out, arg2);
+            if (arg4) {
+                if (get_user_u64(loff_out, arg4)) {
+                    goto efault;
+                }
                 ploff_out = &loff_out;
             }
             ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
+            if (arg2) {
+                if (put_user_u64(loff_in, arg2)) {
+                    goto efault;
+                }
+            }
+            if (arg4) {
+                if (put_user_u64(loff_out, arg4)) {
+                    goto efault;
+                }
+            }
         }
         break;
 #endif
--

2.2.2