Skip to contentSkip to conversation

shmget02: reduce the shmmax test value in compat mode

PATCH Superseded Li Wang 2 participants 6 messages May 30, 2023 – Jun 2, 2023

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 shmget02: reduce the shmmax test value in compat mode

As Arnd Bergmann pointed out that SHMMAX being defined as (ULONG_MAX - (1UL << 24)), so the kernel would likely use a large 64-bit value, while the 32-bit user space uses a much smaller limit.

It finally results in ENOMEM failure:
shmget02.c:95: TFAIL: shmget(1644199826, 4278190080, 1536)
expected EINVAL: ENOMEM (12)

With suggest by Manfred Spraul we could reduce the value of '/proc/sys/kernel/shmmax' in compat mode and only test the overflow behavior with default+1.

---
 testcases/kernel/syscalls/ipc/shmget/shmget02.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
testcases/kernel/syscalls/ipc/shmget/shmget02.c +10 -0
index 7989ef33e..faf633ad4 100644
@@ -56,7 +56,11 @@ static struct tcase {
 	{&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
 	{&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
 	{&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#ifdef TST_ABI32
+	{&shmkey1, 8192 + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#else
 	{&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#endif
 	{&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
 	{&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
 	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},
@@ -149,4 +153,10 @@ static struct tst_test test = {
 	.test = do_test,
 	.tcnt = ARRAY_SIZE(tcases),
 	.hugepages = {TST_NO_HUGEPAGES},
+#ifdef TST_ABI32
+	.save_restore = (const struct tst_path_val[]) {
+		{"/proc/sys/kernel/shmmax", "8192", TST_SR_TBROK},
+		{}
+	},
+#endif
 };
Signature · 5 lines
2.40.1


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

Hi,

Quoted 39 lines · Li Wang

As Arnd Bergmann pointed out that SHMMAX being defined as (ULONG_MAX - (1UL << 24)), so the kernel would likely use a large 64-bit value, while the 32-bit user space uses a much smaller limit.

It finally results in ENOMEM failure:
shmget02.c:95: TFAIL: shmget(1644199826, 4278190080, 1536)
expected EINVAL: ENOMEM (12)

With suggest by Manfred Spraul we could reduce the value of '/proc/sys/kernel/shmmax' in compat mode and only test the overflow behavior with default+1.

---
  testcases/kernel/syscalls/ipc/shmget/shmget02.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
testcases/kernel/syscalls/ipc/shmget/shmget02.c +4 -0
index 7989ef33e..faf633ad4 100644
@@ -56,7 +56,11 @@ static struct tcase {
  	{&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
  	{&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
  	{&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#ifdef TST_ABI32
+	{&shmkey1, 8192 + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#else
  	{&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#endif
  	{&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
  	{&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
  	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},

testcases/kernel/syscalls/ipc/shmget/shmget02.c static struct tst_test test = { · line 162

Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +6 -0
@@ -149,4 +153,10 @@ static struct tst_test test = {
  	.test = do_test,
  	.tcnt = ARRAY_SIZE(tcases),
  	.hugepages = {TST_NO_HUGEPAGES},
+#ifdef TST_ABI32
+	.save_restore = (const struct tst_path_val[]) {
+		{"/proc/sys/kernel/shmmax", "8192", TST_SR_TBROK},
+		{}
+	},
+#endif
  };

Could this be done without the conditional compilation? For example change the testcase to custom shmmax limit unconditionally or read the actual kernel limit from /proc/sys/kernel/shmmax in setup().

Signature · 11 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw
Quoted 49 lines · Martin Doucha

Hi,

Quoted 18 lines · Li Wang

As Arnd Bergmann pointed out that SHMMAX being defined as (ULONG_MAX - (1UL << 24)), so the kernel would likely use a large 64-bit value, while the 32-bit user space uses a much smaller limit.

It finally results in ENOMEM failure:
shmget02.c:95: TFAIL: shmget(1644199826, 4278190080, 1536)
expected EINVAL: ENOMEM (12)

With suggest by Manfred Spraul we could reduce the value of '/proc/sys/kernel/shmmax' in compat mode and only test the overflow behavior with default+1.

Review

Quoted 5 lines
---
  testcases/kernel/syscalls/ipc/shmget/shmget02.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
(quoted diff) +0 -0

b/testcases/kernel/syscalls/ipc/shmget/shmget02.c

Quoted 22 lines

index 7989ef33e..faf633ad4 100644

testcases/kernel/syscalls/ipc/shmget/shmget02.c +7 -0
@@ -56,7 +56,11 @@ static struct tcase {
      {&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
      {&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
      {&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#ifdef TST_ABI32
+     {&shmkey1, 8192 + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#else
      {&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+#endif
      {&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
      {&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
      {&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},
@@ -149,4 +153,10 @@ static struct tst_test test = {
      .test = do_test,
      .tcnt = ARRAY_SIZE(tcases),
      .hugepages = {TST_NO_HUGEPAGES},
+#ifdef TST_ABI32
+     .save_restore = (const struct tst_path_val[]) {
+             {"/proc/sys/kernel/shmmax", "8192", TST_SR_TBROK},
Quoted 9 lines

testcases/kernel/syscalls/ipc/shmget/shmget02.c static struct tst_test test = { · line 162

Quoted 4 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +3 -0
+             {}
+     },
+#endif
  };

Could this be done without the conditional compilation? For example change the testcase to custom shmmax limit unconditionally or read the actual kernel limit from /proc/sys/kernel/shmmax in setup().

That could work as well, but I thought that might a bit complicated to reassign a new value to the two-level pointer 'tc->size'.

Signature · 5 lines
Regards,
Li Wang

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

PATCH v2 1/1 shmget02: reduce the shmmax test value in compat mode

In reply to Martin Doucha

As Arnd Bergmann pointed out that SHMMAX being defined as (ULONG_MAX - (1UL << 24)), so the kernel would likely use a large 64-bit value, while the 32-bit user space uses a much smaller limit.

It finally results in ENOMEM failure:
shmget02.c:95: TFAIL: shmget(1644199826, 4278190080, 1536)
expected EINVAL: ENOMEM (12)

With suggest by Manfred Spraul we could reduce the value of '/proc/sys/kernel/shmmax' in compat mode and only test the overflow behavior with default+1.

---

Notes:
v1 --> v2
* remove the conditional compilation for 32bit

 testcases/kernel/syscalls/ipc/shmget/shmget02.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmget/shmget02.c +5 -1
index 7989ef33e..e053b98d2 100644
@@ -56,7 +56,7 @@ static struct tcase {
 	{&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
 	{&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
 	{&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
-	{&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+	{&shmkey1, 8192 + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
 	{&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
 	{&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
 	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},
@@ -149,4 +149,8 @@ static struct tst_test test = {
 	.test = do_test,
 	.tcnt = ARRAY_SIZE(tcases),
 	.hugepages = {TST_NO_HUGEPAGES},
+	.save_restore = (const struct tst_path_val[]) {
+		{"/proc/sys/kernel/shmmax", "8192", TST_SR_TBROK},
+		{}
+	},
 };
Signature · 5 lines
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/1
#4 lore raw

Hi,
this looks good, just one minor note at the end.

Quoted 41 lines · Li Wang

As Arnd Bergmann pointed out that SHMMAX being defined as (ULONG_MAX - (1UL << 24)), so the kernel would likely use a large 64-bit value, while the 32-bit user space uses a much smaller limit.

It finally results in ENOMEM failure:
shmget02.c:95: TFAIL: shmget(1644199826, 4278190080, 1536)
expected EINVAL: ENOMEM (12)

With suggest by Manfred Spraul we could reduce the value of '/proc/sys/kernel/shmmax' in compat mode and only test the overflow behavior with default+1.

---

Notes:
v1 --> v2
* remove the conditional compilation for 32bit

  testcases/kernel/syscalls/ipc/shmget/shmget02.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmget/shmget02.c +1 -1
index 7989ef33e..e053b98d2 100644
@@ -56,7 +56,7 @@ static struct tcase {
  	{&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
  	{&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
  	{&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
-	{&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+	{&shmkey1, 8192 + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
  	{&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
  	{&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
  	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},

testcases/kernel/syscalls/ipc/shmget/shmget02.c static struct tst_test test = { · line 156

Quoted 8 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +4 -0
@@ -149,4 +149,8 @@ static struct tst_test test = {
  	.test = do_test,
  	.tcnt = ARRAY_SIZE(tcases),
  	.hugepages = {TST_NO_HUGEPAGES},
+	.save_restore = (const struct tst_path_val[]) {
+		{"/proc/sys/kernel/shmmax", "8192", TST_SR_TBROK},
+		{}
+	},
  };

/proc/sys/kernel/shmmax can be disabled by CONFIG_SYSVIPC_SYSCTL, although that would be rare. I think the save_restore flags should be TST_SR_TCONF_MISSING | TST_SR_TBROK_RO. This can be changed during merge.

Signature · 11 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#5 lore raw
Quoted 52 lines · Martin Doucha

Hi,
this looks good, just one minor note at the end.

Quoted 20 lines · Li Wang

As Arnd Bergmann pointed out that SHMMAX being defined as (ULONG_MAX - (1UL << 24)), so the kernel would likely use a large 64-bit value, while the 32-bit user space uses a much smaller limit.

It finally results in ENOMEM failure:
shmget02.c:95: TFAIL: shmget(1644199826, 4278190080, 1536)
expected EINVAL: ENOMEM (12)

With suggest by Manfred Spraul we could reduce the value of '/proc/sys/kernel/shmmax' in compat mode and only test the overflow behavior with default+1.

---

Review

Quoted 8 lines

Notes:
v1 --> v2
* remove the conditional compilation for 32bit

  testcases/kernel/syscalls/ipc/shmget/shmget02.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/testcases/kernel/syscalls/ipc/shmget/shmget02.c

Quoted 17 lines

index 7989ef33e..e053b98d2 100644

testcases/kernel/syscalls/ipc/shmget/shmget02.c +2 -1
@@ -56,7 +56,7 @@ static struct tcase {
      {&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
      {&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
      {&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
-     {&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+     {&shmkey1, 8192 + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
      {&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
      {&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
      {&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},
@@ -149,4 +149,8 @@ static struct tst_test test = {
      .test = do_test,
      .tcnt = ARRAY_SIZE(tcases),
      .hugepages = {TST_NO_HUGEPAGES},
+     .save_restore = (const struct tst_path_val[]) {
Quoted 9 lines

testcases/kernel/syscalls/ipc/shmget/shmget02.c static struct tst_test test = { · line 156

Quoted 4 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +3 -0
+             {"/proc/sys/kernel/shmmax", "8192", TST_SR_TBROK},
+             {}
+     },
  };

/proc/sys/kernel/shmmax can be disabled by CONFIG_SYSVIPC_SYSCTL, although that would be rare. I think the save_restore flags should be TST_SR_TCONF_MISSING | TST_SR_TBROK_RO. This can be changed during merge.

Good point, patch was applied with that changes.

Signature · 5 lines
Regards,
Li Wang

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