[Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length

Andreas Schwab posted 1 patch 7 years, 1 month ago
Failed in applying to current master (apply log)
linux-user/syscall.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
[Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
Posted by Andreas Schwab 7 years, 1 month ago
A zero-length read still needs to do the usual checks, thus it may return
errors like EBADF.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 linux-user/syscall.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 643b8833de..202d3c287d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7930,18 +7930,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_NR_read:
-        if (arg3 == 0)
-            ret = 0;
-        else {
-            if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
-                goto efault;
-            ret = get_errno(safe_read(arg1, p, arg3));
-            if (ret >= 0 &&
-                fd_trans_host_to_target_data(arg1)) {
-                ret = fd_trans_host_to_target_data(arg1)(p, ret);
-            }
-            unlock_user(p, arg2, ret);
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+            goto efault;
+        ret = get_errno(safe_read(arg1, p, arg3));
+        if (ret >= 0 &&
+            fd_trans_host_to_target_data(arg1)) {
+            ret = fd_trans_host_to_target_data(arg1)(p, ret);
         }
+        unlock_user(p, arg2, ret);
         break;
     case TARGET_NR_write:
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
-- 
2.18.0

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

Re: [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
Posted by Richard Henderson 7 years, 1 month ago
On 09/11/2018 05:03 AM, Andreas Schwab wrote:
> +        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
> +            goto efault;

The goto should not compile on head, after 2852aafd9d05.


r~