Skip to contentSkip to conversation

openposix: mq_close/2-1: Fix failure on v7.3+

PATCH Applied Avinesh Kumar via ltp 3 participants 9 messages Oct 18 – Oct 21

lore
Share & tools
lore
#0 lore raw

cover openposix: mq_close/2-1: Fix failure on v7.3+

Linux commit 1184f5e82009 ("mqueue: reject mq_notify with signo 0"), merged in v7.3-rc1, makes mq_notify() with SIGEV_SIGNAL fail with EINVAL if sigev_signo is 0. mq_close/2-1 passes signo 0 in the child's last mq_notify() call, so it fails on v7.3+.

Patch 1 fixes that failure by using a valid signal number.

Patch 2 fixes the same problem for the child's first mq_notify() call. It never sets sigev_signo, so it is rejected with EINVAL instead of failing with EBUSY as intended. The test only checked that the call failed, so it kept passing. The patch sets sigev_signo and requires EBUSY.

Avinesh Kumar (2):
openposix: mq_close/2-1: Use a valid signal number for mq_notify()
openposix: mq_close/2-1: Initialize sigev_signo and check for EBUSY

 .../conformance/interfaces/mq_close/2-1.c              | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Signature · 5 lines
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/2 openposix: mq_close/2-1: Use a valid signal number for mq_notify()

From: Avinesh Kumar <[email protected]>

Linux commit 1184f5e82009 ("mqueue: reject mq_notify with signo 0") in v7.3-rc1, makes mq_notify() with SIGEV_SIGNAL fail with EINVAL if sigev_signo is 0.

In mq_close/2-1 test, the child registers its notification with signo 0 after the parent's mq_close(), so the call is now rejected before the queue state is checked and the test fails on v7.3+.

Use SIGUSR1 as a valid signal.

---
 .../open_posix_testsuite/conformance/interfaces/mq_close/2-1.c  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_close/2-1.c +1 -1
index 6e704158a575..971278aee730 100644
@@ -193,7 +193,7 @@ static int child_process(char *qname, int read_pipe, int write_pipe)
 	}
 	// try notify after parent closed queue - should succeed
 	se.sigev_notify = SIGEV_SIGNAL;
-	se.sigev_signo = 0;
+	se.sigev_signo = SIGUSR1;
 	rval = mq_notify(queue, &se);
 
 	// send 'd' for success and 'e' for failure
Signature · 5 lines
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] openposix: mq_close/2-1: Use a valid signal number for mq_notify()

Hi Avinesh,

Quoted 2 lines · Avinesh Kumar

openposix: mq_close/2-1: Use a valid signal number for mq_notify()
openposix: mq_close/2-1: Initialize sigev_signo and check for EBUSY

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH 2/2 openposix: mq_close/2-1: Initialize sigev_signo and check for EBUSY

In reply to Avinesh Kumar via ltp

From: Avinesh Kumar <[email protected]>

The first mq_notify() call in the child is expected to fail with EBUSY, because the parent still has a notification registered on the queue. But sigev_signo is never set for this call, so the kernel gets whatever is left on the stack. That is often 0, depending on compiler flags and stack layout.

This used to be harmless, since do_mq_notify() accepted signo 0 and the call reached the EBUSY check. Since Linux commit 1184f5e82009 ("mqueue:
reject mq_notify with signo 0"), merged in v7.3-rc1, it fails with EINVAL before the queue state is checked. The test only checks that the call failed, not why, so it still passes without exercising the EBUSY case. Trace on v7.3+ with the previous patch (which fixed the child's second mq_notify() call) applied:

  # strace -f -e trace=mq_notify ./mq_close_2-1.run-test
  strace: Process 32289 attached
  [pid 32288] mq_notify(4, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  [pid 32289] mq_notify(3, {sigev_signo=0, sigev_notify=SIGEV_SIGNAL}) = -1 EINVAL (Invalid argument)
  [pid 32289] mq_notify(3, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  Test PASSED
  [pid 32289] +++ exited with 0 +++

Set sigev_signo to SIGUSR1 and verify the call fails with EBUSY, so an unexpected errno is reported as failure instead of passing silently:

  # strace -f -e trace=mq_notify ./mq_close_2-1.run-test
  strace: Process 32535 attached
  [pid 32534] mq_notify(4, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  [pid 32535] mq_notify(3, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = -1 EBUSY (Device or resource busy)
  [pid 32535] mq_notify(3, {sigev_signo=SIGUSR1, sigev_notify=SIGEV_SIGNAL}) = 0
  Test PASSED
  [pid 32535] +++ exited with 0 +++
---
 .../conformance/interfaces/mq_close/2-1.c                 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/open_posix_testsuite/conformance/interfaces/mq_close/2-1.c +7 -1
index 971278aee730..48f80a1ee430 100644
@@ -175,12 +175,18 @@ static int child_process(char *qname, int read_pipe, int write_pipe)
 	if (queue == (mqd_t) - 1) {
 		return PTS_UNRESOLVED;
 	}
-	// try notify while parent still has queue open - should fail
+	// try notify while parent still has queue open - should fail with EBUSY
 	se.sigev_notify = SIGEV_SIGNAL;
+	se.sigev_signo = SIGUSR1;
 	if (!mq_notify(queue, &se)) {
 		puts(ERROR_PREFIX "mq_notify (2): " "should have failed");
 		return PTS_UNRESOLVED;
 	}
+	if (errno != EBUSY) {
+		perror(ERROR_PREFIX "mq_notify (2): expected EBUSY");
+		return PTS_UNRESOLVED;
+	}
+
 	// send 'b' - signal parent to close queue
 	rval = send_receive(read_pipe, write_pipe, 'b', &reply);
 	if (rval) {
Signature · 5 lines
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp