[LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits

Wei Gao via ltp
2026-01-28T07:11:16Z

On 64-bit kernels, the default shmmax and shmall values often exceed
the range of a 32-bit unsigned long or are clipped differently by the
kernel's compat syscall layer than they appear in /proc.

Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/ipc/shmctl/shmctl03.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index a3291c37f..335a60980 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -13,6 +13,13 @@
#include "tst_safe_sysv_ipc.h"
#include "libnewipc.h"

+/* Force 32-bit limits to avoid overflow/mismatch on 64-bit kernels */
+#if __WORDSIZE == 32
+# define SET_SHM_LIMIT "2147483647"
+#else
+# define SET_SHM_LIMIT NULL
+#endif
+
static void verify_ipcinfo(void)
{
struct shminfo info;
@@ -37,4 +44,9 @@ static void verify_ipcinfo(void)

static struct tst_test test = {
.test_all = verify_ipcinfo,
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/kernel/shmmax", SET_SHM_LIMIT, TST_SR_TCONF_MISSING},
+ {"/proc/sys/kernel/shmall", SET_SHM_LIMIT, TST_SR_TCONF_MISSING},
+ {}
+ },
};
--
2.52.0