qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
@ 2018-09-11 12:03 Andreas Schwab
  2018-09-12 17:22 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2018-09-11 12:03 UTC (permalink / raw)
  To: qemu-devel

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
  2018-09-11 12:03 Andreas Schwab
@ 2018-09-12 17:22 ` Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2018-09-12 17:22 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel

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~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
@ 2019-03-05 16:45 Andreas Schwab
  2019-03-05 17:31 ` Laurent Vivier
  2019-03-06 13:11 ` Laurent Vivier
  0 siblings, 2 replies; 5+ messages in thread
From: Andreas Schwab @ 2019-03-05 16:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier

A zero-length read still needs to do the usual checks, thus it may return
errors like EBADF.  This makes the read syscall emulation consistent with
the pread64 syscall emulation.

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

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ff912e89e1..7fac8e318f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7047,8 +7047,8 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
         _exit(arg1);
         return 0; /* avoid warning */
     case TARGET_NR_read:
-        if (arg3 == 0) {
-            return 0;
+        if (arg2 == 0 && arg3 == 0) {
+            return get_errno(safe_read(arg1, 0, 0));
         } else {
             if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
                 return -TARGET_EFAULT;
-- 
2.21.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."

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
  2019-03-05 16:45 [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length Andreas Schwab
@ 2019-03-05 17:31 ` Laurent Vivier
  2019-03-06 13:11 ` Laurent Vivier
  1 sibling, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2019-03-05 17:31 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel; +Cc: Riku Voipio

Le 05/03/2019 à 17:45, Andreas Schwab a écrit :
> A zero-length read still needs to do the usual checks, thus it may return
> errors like EBADF.  This makes the read syscall emulation consistent with
> the pread64 syscall emulation.
> 
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  linux-user/syscall.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index ff912e89e1..7fac8e318f 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7047,8 +7047,8 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          _exit(arg1);
>          return 0; /* avoid warning */
>      case TARGET_NR_read:
> -        if (arg3 == 0) {
> -            return 0;
> +        if (arg2 == 0 && arg3 == 0) {
> +            return get_errno(safe_read(arg1, 0, 0));
>          } else {
>              if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
>                  return -TARGET_EFAULT;
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
  2019-03-05 16:45 [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length Andreas Schwab
  2019-03-05 17:31 ` Laurent Vivier
@ 2019-03-06 13:11 ` Laurent Vivier
  1 sibling, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2019-03-06 13:11 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel; +Cc: Riku Voipio

On 05/03/2019 17:45, Andreas Schwab wrote:
> A zero-length read still needs to do the usual checks, thus it may return
> errors like EBADF.  This makes the read syscall emulation consistent with
> the pread64 syscall emulation.
> 
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  linux-user/syscall.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index ff912e89e1..7fac8e318f 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7047,8 +7047,8 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>          _exit(arg1);
>          return 0; /* avoid warning */
>      case TARGET_NR_read:
> -        if (arg3 == 0) {
> -            return 0;
> +        if (arg2 == 0 && arg3 == 0) {
> +            return get_errno(safe_read(arg1, 0, 0));
>          } else {
>              if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
>                  return -TARGET_EFAULT;
> 

Applied to my linux-user branch.

Thanks,
Laurent

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-06 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-05 16:45 [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length Andreas Schwab
2019-03-05 17:31 ` Laurent Vivier
2019-03-06 13:11 ` Laurent Vivier
  -- strict thread matches above, loose matches on Subject: below --
2018-09-11 12:03 Andreas Schwab
2018-09-12 17:22 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).