Skip to contentSkip to conversation

syscall: fixed mincore(2) not failing with ENOMEM

PATCH Applied Franklin Snaipe Mathieu 4 participants 9 messages Feb 16, 2017 – Feb 28, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscall: fixed mincore(2) not failing with ENOMEM

From: "Franklin \"Snaipe\" Mathieu" <[email protected]>

The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid.

This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory.

---
 linux-user/syscall.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +8 -3
index 9be8e9530e..af0dd40631 100644
@@ -11061,11 +11061,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_mincore:
         {
             void *a;
+            ret = -TARGET_ENOMEM;
+            a = lock_user(VERIFY_READ, arg1, arg2, 0);
+            if (!a) {
+                goto fail;
+            }
             ret = -TARGET_EFAULT;
-            if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
-                goto efault;
-            if (!(p = lock_user_string(arg3)))
+            p = lock_user_string(arg3)
+            if (!p) {
                 goto mincore_fail;
+            }
             ret = get_errno(mincore(a, arg2, p));
             unlock_user(p, arg3, ret);
             mincore_fail:
Signature · 1 line
2.11.0
#1 lore raw

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

Quoted 2 lines · Franklin Snaipe Mathieu
linux-user/syscall.c +2 -0
+            p = lock_user_string(arg3)
+            if (!p) {

Please compile test at least, even if it is a trivial patch.

Fam

#2 lore raw

2017-02-17 0:50 GMT+00:00 Fam Zheng <[email protected]>:

Quoted 6 lines · Franklin Snaipe Mathieu

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

Quoted 2 lines
linux-user/syscall.c +2 -0
+            p = lock_user_string(arg3)
+            if (!p) {

Please compile test at least, even if it is a trivial patch.

Whoops, sorry, I forgot to re-compile after fixing the checkpatch issues.

Signature · 2 lines
Franklin "Snaipe" Mathieu
🝰 https://diacritic.io
#3 lore raw

PATCH 1/1 syscall: fixed mincore(2) not failing with ENOMEM

In reply to Franklin Snaipe Mathieu

From: "Franklin \"Snaipe\" Mathieu" <[email protected]>

The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid.

This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory.

---
 linux-user/syscall.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +8 -3
index 9be8e9530e..733e0009e1 100644
@@ -11061,11 +11061,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_mincore:
         {
             void *a;
+            ret = -TARGET_ENOMEM;
+            a = lock_user(VERIFY_READ, arg1, arg2, 0);
+            if (!a) {
+                goto fail;
+            }
             ret = -TARGET_EFAULT;
-            if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
-                goto efault;
-            if (!(p = lock_user_string(arg3)))
+            p = lock_user_string(arg3);
+            if (!p) {
                 goto mincore_fail;
+            }
             ret = get_errno(mincore(a, arg2, p));
             unlock_user(p, arg3, ret);
             mincore_fail:
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 1/1 syscall: fixed mincore(2) not failing with ENOMEM

From: "Franklin \"Snaipe\" Mathieu" <[email protected]>

The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid.

This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory.

---
 linux-user/syscall.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +8 -3
index 9be8e9530e..733e0009e1 100644
@@ -11061,11 +11061,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_mincore:
         {
             void *a;
+            ret = -TARGET_ENOMEM;
+            a = lock_user(VERIFY_READ, arg1, arg2, 0);
+            if (!a) {
+                goto fail;
+            }
             ret = -TARGET_EFAULT;
-            if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
-                goto efault;
-            if (!(p = lock_user_string(arg3)))
+            p = lock_user_string(arg3);
+            if (!p) {
                 goto mincore_fail;
+            }
             ret = get_errno(mincore(a, arg2, p));
             unlock_user(p, arg3, ret);
             mincore_fail:
Signature · 1 line
2.11.0
Reviewed-by on v2 1/1
#5 lore raw
Quoted 33 lines · Franklin Snaipe Mathieu

From: "Franklin \"Snaipe\" Mathieu" <[email protected]>

The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid.

This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory.

---
 linux-user/syscall.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +5 -0
index 9be8e9530e..733e0009e1 100644
@@ -11061,11 +11061,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_mincore:
         {
             void *a;
+            ret = -TARGET_ENOMEM;
+            a = lock_user(VERIFY_READ, arg1, arg2, 0);
+            if (!a) {
+                goto fail;
+            }
             ret = -TARGET_EFAULT;

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

Quoted 10 lines
linux-user/syscall.c +3 -3
-            if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
-                goto efault;
-            if (!(p = lock_user_string(arg3)))
+            p = lock_user_string(arg3);
+            if (!p) {
                 goto mincore_fail;
+            }
             ret = get_errno(mincore(a, arg2, p));
             unlock_user(p, arg3, ret);
             mincore_fail:
#6 lore raw
In reply to Franklin Snaipe Mathieu

Ignore this patch, this was sent again by mistake.

2017-02-17 8:57 GMT+00:00 Franklin Snaipe Mathieu <[email protected]>:

Quoted 45 lines

From: "Franklin \"Snaipe\" Mathieu" <[email protected]>

The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid.

This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory.

---
 linux-user/syscall.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +8 -4
index 9be8e9530e..733e0009e1 100644
@@ -11061,11 +11061,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_mincore:
         {
             void *a;
+            ret = -TARGET_ENOMEM;
+            a = lock_user(VERIFY_READ, arg1, arg2, 0);
+            if (!a) {
+                goto fail;
+            }
             ret = -TARGET_EFAULT;
-            if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0)))
-                goto efault;
-            if (!(p = lock_user_string(arg3)))
+            p = lock_user_string(arg3);
+            if (!p) {
                 goto mincore_fail;
+            }
             ret = get_errno(mincore(a, arg2, p));
             unlock_user(p, arg3, ret);
             mincore_fail:
--

2.11.0

Signature · 2 lines
Franklin "Snaipe" Mathieu
🝰 https://diacritic.io
#7 lore raw
Quoted 1 line · Franklin "Snaipe" Mathieu

Ignore this patch, this was sent again by mistake.

Hi Franklin, thanks for the re-submission. Next time please send consecutive versions as top-level threads instead of replies to previous versions, with proper 'v2", "v3" tags in the subject.

Fam

#8 lore raw
In reply to Franklin Snaipe Mathieu
Quoted 10 lines · Franklin Snaipe Mathieu

From: "Franklin \"Snaipe\" Mathieu" <[email protected]>

The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid.

This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory.

Applied to -trivial, thanks!

/mjt