Skip to contentSkip to conversation

linux-user: Let sigaction query SIGKILL/SIGSTOP

PATCH Applied Ilya Leoshkevich 2 participants 7 messages Jun 1, 2021 – Jun 20, 2021

lore
Share & tools
lore
#0 lore raw

cover linux-user: Let sigaction query SIGKILL/SIGSTOP

valgrind fails to start under linux-user, one of the reasons being that it tries to query all the sigactions, which qemu (unlike the real kernel) doesn't allow for SIGKILL/SIGSTOP.

Patch 1 lifts this restriction, patch 2 adds a test.

Ilya Leoshkevich (2):
linux-user: Let sigaction query SIGKILL/SIGSTOP tests/tcg/linux-test: Check that sigaction can query SIGKILL/SIGSTOP

 linux-user/signal.c              | 6 +++++-
 tests/tcg/multiarch/linux-test.c | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 linux-user: Let sigaction query SIGKILL/SIGSTOP

The kernel allows doing this, so let's allow this in qemu as well. Valgrind relies on this.

---
 linux-user/signal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
linux-user/signal.c +5 -1
index 9016896dcd..bc3431708f 100644
@@ -851,7 +851,11 @@ int do_sigaction(int sig, const struct target_sigaction *act,
 
     trace_signal_do_sigaction_guest(sig, TARGET_NSIG);
 
-    if (sig < 1 || sig > TARGET_NSIG || sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP) {
+    if (sig < 1 || sig > TARGET_NSIG) {
+        return -TARGET_EINVAL;
+    }
+
+    if (act && (sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP)) {
         return -TARGET_EINVAL;
     }
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/2
#2 lore raw

Le 01/06/2021 à 16:55, Ilya Leoshkevich a écrit :

Quoted 16 lines

The kernel allows doing this, so let's allow this in qemu as well. Valgrind relies on this.

---
 linux-user/signal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
linux-user/signal.c +0 -0
index 9016896dcd..bc3431708f 100644
@@ -851,7 +851,11 @@ int do_sigaction(int sig, const struct target_sigaction *act,
 
     trace_signal_do_sigaction_guest(sig, TARGET_NSIG);

linux-user/signal.c int do_sigaction(int sig, const struct target_sigaction *act, · line 861

Quoted 10 lines
linux-user/signal.c +5 -1
 
-    if (sig < 1 || sig > TARGET_NSIG || sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP) {
+    if (sig < 1 || sig > TARGET_NSIG) {
+        return -TARGET_EINVAL;
+    }
+
+    if (act && (sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP)) {
         return -TARGET_EINVAL;
     }
 
#3 lore raw
In reply to Ilya Leoshkevich

Le 01/06/2021 à 16:55, Ilya Leoshkevich a écrit :

Quoted 16 lines

The kernel allows doing this, so let's allow this in qemu as well. Valgrind relies on this.

---
 linux-user/signal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
linux-user/signal.c +0 -0
index 9016896dcd..bc3431708f 100644
@@ -851,7 +851,11 @@ int do_sigaction(int sig, const struct target_sigaction *act,
 
     trace_signal_do_sigaction_guest(sig, TARGET_NSIG);

linux-user/signal.c int do_sigaction(int sig, const struct target_sigaction *act, · line 861

Quoted 10 lines
linux-user/signal.c +5 -1
 
-    if (sig < 1 || sig > TARGET_NSIG || sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP) {
+    if (sig < 1 || sig > TARGET_NSIG) {
+        return -TARGET_EINVAL;
+    }
+
+    if (act && (sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP)) {
         return -TARGET_EINVAL;
     }
 

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

Thanks,
Laurent

#4 lore raw

PATCH 2/2 tests/tcg/linux-test: Check that sigaction can query SIGKILL/SIGSTOP

In reply to Ilya Leoshkevich

Verify that querying is allowed, but making changes isn't.

---
 tests/tcg/multiarch/linux-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tests/tcg/multiarch/linux-test.c +9 -0
index ce033c21c7..cd9d8159bc 100644
@@ -496,6 +496,15 @@ static void test_signal(void)
     sigemptyset(&act.sa_mask);
     act.sa_flags = 0;
     chk_error(sigaction(SIGSEGV, &act, NULL));
+
+    if (sigaction(SIGKILL, &act, NULL) == 0) {
+        error("sigaction(SIGKILL, &act, NULL) must not succeed");
+    }
+    if (sigaction(SIGSTOP, &act, NULL) == 0) {
+        error("sigaction(SIGSTOP, &act, NULL) must not succeed");
+    }
+    chk_error(sigaction(SIGKILL, NULL, &act));
+    chk_error(sigaction(SIGSTOP, NULL, &act));
 }
 
 #define SHM_SIZE 32768
Signature · 1 line
2.31.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] tests/tcg/linux-test: Check that sigaction can query SIGKILL/SIGSTOP

Le 01/06/2021 à 16:56, Ilya Leoshkevich a écrit :

Quoted 18 lines

Verify that querying is allowed, but making changes isn't.

---
 tests/tcg/multiarch/linux-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tests/tcg/multiarch/linux-test.c +2 -0
index ce033c21c7..cd9d8159bc 100644
@@ -496,6 +496,15 @@ static void test_signal(void)
     sigemptyset(&act.sa_mask);
     act.sa_flags = 0;
     chk_error(sigaction(SIGSEGV, &act, NULL));
+
+    if (sigaction(SIGKILL, &act, NULL) == 0) {

tests/tcg/multiarch/linux-test.c static void test_signal(void) · line 510

Quoted 10 lines
tests/tcg/multiarch/linux-test.c +7 -0
+        error("sigaction(SIGKILL, &act, NULL) must not succeed");
+    }
+    if (sigaction(SIGSTOP, &act, NULL) == 0) {
+        error("sigaction(SIGSTOP, &act, NULL) must not succeed");
+    }
+    chk_error(sigaction(SIGKILL, NULL, &act));
+    chk_error(sigaction(SIGSTOP, NULL, &act));
 }
 
 #define SHM_SIZE 32768

Alex, I will merge this via linux-user, is it ok for you?

Thanks,
Laurent

#6 lore raw

Re: [PATCH 2/2] tests/tcg/linux-test: Check that sigaction can query SIGKILL/SIGSTOP

In reply to Ilya Leoshkevich

Le 01/06/2021 à 16:56, Ilya Leoshkevich a écrit :

Quoted 18 lines

Verify that querying is allowed, but making changes isn't.

---
 tests/tcg/multiarch/linux-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tests/tcg/multiarch/linux-test.c +2 -0
index ce033c21c7..cd9d8159bc 100644
@@ -496,6 +496,15 @@ static void test_signal(void)
     sigemptyset(&act.sa_mask);
     act.sa_flags = 0;
     chk_error(sigaction(SIGSEGV, &act, NULL));
+
+    if (sigaction(SIGKILL, &act, NULL) == 0) {

tests/tcg/multiarch/linux-test.c static void test_signal(void) · line 510

Quoted 10 lines
tests/tcg/multiarch/linux-test.c +7 -0
+        error("sigaction(SIGKILL, &act, NULL) must not succeed");
+    }
+    if (sigaction(SIGSTOP, &act, NULL) == 0) {
+        error("sigaction(SIGSTOP, &act, NULL) must not succeed");
+    }
+    chk_error(sigaction(SIGKILL, NULL, &act));
+    chk_error(sigaction(SIGSTOP, NULL, &act));
 }
 
 #define SHM_SIZE 32768

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

Thanks,
Laurent