Skip to contentSkip to conversation

Fix stack smashing when handling PR_GET_PDEATHSIG

PATCH Applied Stephen Long 2 participants 5 messages May 7, 2020 – Sep 26, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Fix stack smashing when handling PR_GET_PDEATHSIG

The bug was triggered by the following code on aarch64-linux-user:

#include <signal.h>
#include <sys/prctl.h>

int main(void)
{
int PDeathSig = 0;
if (prctl(PR_GET_PDEATHSIG, &PDeathSig) == 0 && PDeathSig == SIGKILL)

    prctl(PR_GET_PDEATHSIG, 0);

return (PDeathSig == SIGKILL);
}

---

I fixed the incorrect subject line. PR_GETDEATHSIG should be PR_GET_PDEATHSIG. Is there a test folder where I can include the code that triggered the bug? Also, I thought "int" can be 2 bytes on some machines.

 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index 05f03919ff..91f91147ba 100644
@@ -10256,7 +10256,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             int deathsig;
             ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
             if (!is_error(ret) && arg2
-                && put_user_ual(deathsig, arg2)) {
+                && put_user_s32(deathsig, arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw

Le 07/05/2020 à 15:03, Stephen Long a écrit :

Quoted 13 lines

The bug was triggered by the following code on aarch64-linux-user:

#include <signal.h>
#include <sys/prctl.h>

int main(void)
{
int PDeathSig = 0;
if (prctl(PR_GET_PDEATHSIG, &PDeathSig) == 0 && PDeathSig == SIGKILL)

    prctl(PR_GET_PDEATHSIG, 0);

return (PDeathSig == SIGKILL);
}

Quoted 6 lines

---

I fixed the incorrect subject line. PR_GETDEATHSIG should be PR_GET_PDEATHSIG. Is there a test folder where I can include the code that triggered the bug?

Perhaps Alex Bennée knows?

Quoted 1 line

Also, I thought "int" can be 2 bytes on some machines.

According to my K&R, 4th edition, it could be on 16bit systems, like PDP-11, but we don't support them ;)

Quoted 18 lines
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index 05f03919ff..91f91147ba 100644
@@ -10256,7 +10256,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             int deathsig;
             ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
             if (!is_error(ret) && arg2
-                && put_user_ual(deathsig, arg2)) {
+                && put_user_s32(deathsig, arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;
#2 lore raw
In reply to Stephen Long
Quoted 16 lines
Quoted 8 lines
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 05f0391..91f9114 100644

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 10262

Quoted 8 lines
linux-user/syscall.c +1 -1
@@ -10256,7 +10256,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             int deathsig;
             ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
             if (!is_error(ret) && arg2
-                && put_user_ual(deathsig, arg2)) {
+                && put_user_s32(deathsig, arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;

Hi Laurent, is it possible to get this patch into master?

#3 lore raw

Le 26/09/2020 à 03:56, Stephen Long a écrit :

Quoted 19 lines
Quoted 16 lines
Quoted 8 lines
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 05f0391..91f9114 100644

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 10262

Quoted 8 lines
linux-user/syscall.c +1 -1
@@ -10256,7 +10256,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             int deathsig;
             ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
             if (!is_error(ret) && arg2
-                && put_user_ual(deathsig, arg2)) {
+                && put_user_s32(deathsig, arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;

Hi Laurent, is it possible to get this patch into master?

Applied to my linux-user-for-5.2 branch.

Thanks,
Laurent

Reviewed-by on v2 1/1
#4 lore raw
In reply to Stephen Long

Le 07/05/2020 à 15:03, Stephen Long a écrit :

Quoted 30 lines

The bug was triggered by the following code on aarch64-linux-user:

#include <signal.h>
#include <sys/prctl.h>

int main(void)
{
int PDeathSig = 0;
if (prctl(PR_GET_PDEATHSIG, &PDeathSig) == 0 && PDeathSig == SIGKILL)

    prctl(PR_GET_PDEATHSIG, 0);

return (PDeathSig == SIGKILL);
}

---

I fixed the incorrect subject line. PR_GETDEATHSIG should be PR_GET_PDEATHSIG. Is there a test folder where I can include the code that triggered the bug? Also, I thought "int" can be 2 bytes on some machines.

 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 05f03919ff..91f91147ba 100644

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 10262

Quoted 8 lines
linux-user/syscall.c +1 -1
@@ -10256,7 +10256,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
             int deathsig;
             ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5));
             if (!is_error(ret) && arg2
-                && put_user_ual(deathsig, arg2)) {
+                && put_user_s32(deathsig, arg2)) {
                 return -TARGET_EFAULT;
             }
             return ret;