Skip to contentSkip to conversation

linux-user: Fix sched_getaffinity mask size

PATCH Superseded Samuel Thibault 3 participants 3 messages Jan 26, 2018 – Jan 27, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Fix sched_getaffinity mask size

We properly computed the capped mask size to be put to the application buffer, but didn't actually it. Also, we need to return the capped mask size instead of 0 on success.

---
 linux-user/syscall.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/syscall.c +6 -1
index 74378947f0..cf2369aac2 100644
@@ -10496,10 +10496,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                         ret = -TARGET_EINVAL;
                         break;
                     }
-                    ret = arg2;
+                } else if (arg2 > ret) {
+                    arg2 = ret;
                 }
 
                 ret = host_to_target_cpu_mask(mask, mask_size, arg3, arg2);
+
+                if (ret == 0) {
+                    ret = arg2;
+                }
             }
         }
         break;
Signature · 1 line
2.15.1
#1 lore raw

Le 26/01/2018 à 19:36, Samuel Thibault a écrit :

Quoted 21 lines

We properly computed the capped mask size to be put to the application buffer, but didn't actually it. Also, we need to return the capped mask size instead of 0 on success.

---
 linux-user/syscall.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/syscall.c +2 -1
index 74378947f0..cf2369aac2 100644
@@ -10496,10 +10496,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                         ret = -TARGET_EINVAL;
                         break;
                     }
-                    ret = arg2;
+                } else if (arg2 > ret) {
+                    arg2 = ret;

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

Quoted 10 lines
linux-user/syscall.c +4 -0
                 }
 
                 ret = host_to_target_cpu_mask(mask, mask_size, arg3, arg2);
+
+                if (ret == 0) {
+                    ret = arg2;
+                }
             }
         }
         break;

Modified code was:

    if (copy_to_user(arg3, mask, ret)) {
        goto efault;
    }

so the change should only be:

    if (host_to_target_cpu_mask(mask, mask_size, arg3, ret)) {
        goto efault;
    }

Thanks,
Laurent

#2 lore raw
Quoted 39 lines · Laurent Vivier, on ven. 26 janv. 2018 21:34:38 +0100, wrote:

Le 26/01/2018 à 19:36, Samuel Thibault a écrit :

Quoted 21 lines

We properly computed the capped mask size to be put to the application buffer, but didn't actually it. Also, we need to return the capped mask size instead of 0 on success.

---
 linux-user/syscall.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/syscall.c +2 -1
index 74378947f0..cf2369aac2 100644
@@ -10496,10 +10496,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                         ret = -TARGET_EINVAL;
                         break;
                     }
-                    ret = arg2;
+                } else if (arg2 > ret) {
+                    arg2 = ret;

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

Quoted 10 lines
linux-user/syscall.c +4 -0
                 }
 
                 ret = host_to_target_cpu_mask(mask, mask_size, arg3, arg2);
+
+                if (ret == 0) {
+                    ret = arg2;
+                }
             }
         }
         break;

Modified code was:

    if (copy_to_user(arg3, mask, ret)) {
        goto efault;
    }
Quoted 5 lines

so the change should only be:

    if (host_to_target_cpu_mask(mask, mask_size, arg3, ret)) {
        goto efault;
    }

That depends whether host_to_target_cpu_mask wants to return something else than -TARGET_EFAULT, but at some point I don't care about bikeshedding.

Samuel