Skip to contentSkip to conversation

syscalls/shmctl05: Remove shm segment only when created

PATCH New Cyril Hrubis 2 participants 2 messages Sep 15, 2021 – Sep 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/shmctl05: Remove shm segment only when created

We cannot remove the shm segment unconditionally. On kernels without SysV IPC support compiled in the test fails with following:

shmctl05.c:50: TCONF: syscall(396) __NR_shmctl not supported shmctl05.c:96: TWARN: shmget(61455, 4096, 0) failed: ENOENT (2) shmctl05.c:97: TWARN: shmctl(-1, 0, (nil)) failed: EINVAL (22)

Fixes 48d382e8daf2 (syscalls/shmctl05.c: Fix leak of shared memory segment)
CC Yang Xu <[email protected]>
---
 testcases/kernel/syscalls/ipc/shmctl/shmctl05.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmctl/shmctl05.c +9 -1
index ea7eef6f1..8569322dc 100644
@@ -92,8 +92,16 @@ static void do_test(void)
 static void cleanup(void)
 {
 	int id;
+
 	tst_fzsync_pair_cleanup(&fzsync_pair);
-	id = SAFE_SHMGET(0xF00F, 4096, 0);
+
+	id = shmget(0xF00F, 4096, 0);
+	if (id == -1) {
+		if (errno != ENOENT)
+			tst_res(TWARN | TERRNO, "shmget()");
+		return;
+	}
+
 	SAFE_SHMCTL(id, IPC_RMID, NULL);
 }
 
Signature · 5 lines
2.32.0


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

PATCH 1/1 syscalls/shmctl05: Remove shm segment only when created

Hi Cyril
Thanks for this fix, merged.

Best Regards
Yang Xu

Quoted 36 lines

We cannot remove the shm segment unconditionally. On kernels without SysV IPC support compiled in the test fails with following:

shmctl05.c:50: TCONF: syscall(396) __NR_shmctl not supported shmctl05.c:96: TWARN: shmget(61455, 4096, 0) failed: ENOENT (2) shmctl05.c:97: TWARN: shmctl(-1, 0, (nil)) failed: EINVAL (22)

Fixes 48d382e8daf2 (syscalls/shmctl05.c: Fix leak of shared memory segment)
CC Yang Xu<[email protected]>
---
  testcases/kernel/syscalls/ipc/shmctl/shmctl05.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmctl/shmctl05.c +9 -1
index ea7eef6f1..8569322dc 100644
@@ -92,8 +92,16 @@ static void do_test(void)
  static void cleanup(void)
  {
  	int id;
+
  	tst_fzsync_pair_cleanup(&fzsync_pair);
-	id = SAFE_SHMGET(0xF00F, 4096, 0);
+
+	id = shmget(0xF00F, 4096, 0);
+	if (id == -1) {
+		if (errno != ENOENT)
+			tst_res(TWARN | TERRNO, "shmget()");
+		return;
+	}
+
  	SAFE_SHMCTL(id, IPC_RMID, NULL);
  }