All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: fix mq_getsetattr implementation
@ 2018-03-31 16:23 Max Filippov
  2018-03-31 16:57 ` Laurent Vivier
  0 siblings, 1 reply; 3+ messages in thread
From: Max Filippov @ 2018-03-31 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Max Filippov, Lionel Landwerlin, Kirill A . Shutemov, Riku Voipio,
	Aurelien Jarno, Laurent Vivier

mq_getsetattr implementation does not set errno correctly in case of
error. Also in the presence of both 2nd and 3rd arguments it calls both
mq_getattr and mq_setattr, whereas only the latter call would suffice.

Don't call mq_getattr in the presence of the 3rd argument. Use get_errno
to set errno value.

This fixes test rt/tst-mqueue2 from the glibc testsuite.

Cc: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Riku Voipio <riku.voipio@iki.fi>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 linux-user/syscall.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 18ea79140f16..8b364551c311 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -12092,15 +12092,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
             ret = 0;
-            if (arg3 != 0) {
-                ret = mq_getattr(arg1, &posix_mq_attr_out);
-                copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
-            }
             if (arg2 != 0) {
                 copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
-                ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+                ret = mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
+            } else if (arg3 != 0) {
+                ret = mq_getattr(arg1, &posix_mq_attr_out);
             }
-
+            if (arg3 != 0) {
+                copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
+            }
+            ret = get_errno(ret);
         }
         break;
 #endif
-- 
2.11.0

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

* Re: [Qemu-devel] [PATCH] linux-user: fix mq_getsetattr implementation
  2018-03-31 16:23 [Qemu-devel] [PATCH] linux-user: fix mq_getsetattr implementation Max Filippov
@ 2018-03-31 16:57 ` Laurent Vivier
  2018-03-31 17:03   ` Laurent Vivier
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Vivier @ 2018-03-31 16:57 UTC (permalink / raw)
  To: Max Filippov, qemu-devel
  Cc: Lionel Landwerlin, Kirill A . Shutemov, Riku Voipio,
	Aurelien Jarno

Le 31/03/2018 à 18:23, Max Filippov a écrit :
> mq_getsetattr implementation does not set errno correctly in case of
> error. Also in the presence of both 2nd and 3rd arguments it calls both
> mq_getattr and mq_setattr, whereas only the latter call would suffice.
> 
> Don't call mq_getattr in the presence of the 3rd argument. Use get_errno
> to set errno value.
> 
> This fixes test rt/tst-mqueue2 from the glibc testsuite.
> 
> Cc: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Riku Voipio <riku.voipio@iki.fi>
> Cc: Aurelien Jarno <aurelien@aurel32.net>
> Cc: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
> ---
>  linux-user/syscall.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 18ea79140f16..8b364551c311 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -12092,15 +12092,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          {
>              struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
>              ret = 0;

you can remove this line

> -            if (arg3 != 0) {
> -                ret = mq_getattr(arg1, &posix_mq_attr_out);
> -                copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
> -            }
>              if (arg2 != 0) {
>                  copy_from_user_mq_attr(&posix_mq_attr_in, arg2);
> -                ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);
> +                ret = mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out);

you can call get_errno(mq_setattr(..)) here...

> +            } else if (arg3 != 0) {
> +                ret = mq_getattr(arg1, &posix_mq_attr_out);

and get_errno(q_getattr(..)) here.

>              }
> -
> +            if (arg3 != 0) {

you should also check ret < 0 before copying to arg3

> +                copy_to_user_mq_attr(arg3, &posix_mq_attr_out);
> +            }
> +            ret = get_errno(ret);

you can remove this line if you call get_errno() directly before.


>          }
>          break;
>  #endif
> 

Thanks,
Laurent

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

* Re: [Qemu-devel] [PATCH] linux-user: fix mq_getsetattr implementation
  2018-03-31 16:57 ` Laurent Vivier
@ 2018-03-31 17:03   ` Laurent Vivier
  0 siblings, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2018-03-31 17:03 UTC (permalink / raw)
  To: Max Filippov, qemu-devel; +Cc: Kirill A . Shutemov, Riku Voipio, Aurelien Jarno

Le 31/03/2018 à 18:57, Laurent Vivier a écrit :
> Le 31/03/2018 à 18:23, Max Filippov a écrit :
>> mq_getsetattr implementation does not set errno correctly in case of
>> error. Also in the presence of both 2nd and 3rd arguments it calls both
>> mq_getattr and mq_setattr, whereas only the latter call would suffice.
>>
>> Don't call mq_getattr in the presence of the 3rd argument. Use get_errno
>> to set errno value.
>>
>> This fixes test rt/tst-mqueue2 from the glibc testsuite.
>>
>> Cc: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
>> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>> Cc: Riku Voipio <riku.voipio@iki.fi>
>> Cc: Aurelien Jarno <aurelien@aurel32.net>
>> Cc: Laurent Vivier <laurent@vivier.eu>
>> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
>> ---
>>  linux-user/syscall.c | 13 +++++++------
>>  1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index 18ea79140f16..8b364551c311 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -12092,15 +12092,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>>          {
>>              struct mq_attr posix_mq_attr_in, posix_mq_attr_out;
>>              ret = 0;
> 
> you can remove this line

in fact, you must keep this line because ret is not update if arg2 ==
NULL and arg3 == NULL.

Thanks,
Laurent

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

end of thread, other threads:[~2018-03-31 17:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-31 16:23 [Qemu-devel] [PATCH] linux-user: fix mq_getsetattr implementation Max Filippov
2018-03-31 16:57 ` Laurent Vivier
2018-03-31 17:03   ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.