[LTP] [PATCH 1/1] shmctl03: Fix shmall clamped to UINT32_MAX in 32bit compat mode
Petr Vorel
pvorel@suse.cz
Mon Oct 26 16:16:38 CET 2026
Unlike shmmax, the kernel's compat shmctl(IPC_INFO) path does not clamp
shmall but truncates the 64-bit value into the 32-bit compat shminfo
(see copy_compat_shminfo_to_user() in ipc/shm.c, originally changed by
af7c693f14606 ("Cap shmmax at INT_MAX in compat shminfo") in kernel
v2.6.22.
Parsing /proc/sys/kernel/shmall's full decimal value with "%lu" into a
32-bit unsigned long saturates to ULONG_MAX instead of truncating,
causing a mismatch. Read it into an unsigned long long and compare
against the low 32 bits in compat mode.
Because this is a test specific error, fix it in the test itself instead
adding support to the LTP library.
This fixes error:
shmctl03.c:35: TFAIL: /proc/sys/kernel/shmall != 4294967040 got 4294967295
Reported-by: Wei Gao <wegao@suse.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi,
yet another attempt to fix struct shminfo shmall.
I believe in the end this is better than a general approach I posted
previously based on Andrea's suggestion [1] or older Wei's approach [2][3]
based on Cyril's suggestion.
Kind regards,
Petr
[1] https://patchwork.kernel.org/project/ltp/patch/20260924112514.2375626-2-pvorel@suse.cz/
[2] https://patchwork.kernel.org/project/ltp/patch/20260903095255.4925-3-wegao@suse.com/
[3] https://patchwork.kernel.org/project/ltp/patch/20260903095255.4925-2-wegao@suse.com/
testcases/kernel/syscalls/shmctl/shmctl03.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/shmctl/shmctl03.c b/testcases/kernel/syscalls/shmctl/shmctl03.c
index bccab5ba37..e5937fd023 100644
--- a/testcases/kernel/syscalls/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/shmctl/shmctl03.c
@@ -18,6 +18,7 @@ static void verify_ipcinfo(void)
{
struct shminfo info;
unsigned long shmmax;
+ unsigned long long shmall;
TST_EXP_POSITIVE(shmctl(0, IPC_INFO, (struct shmid_ds *)&info));
if (!TST_PASS)
@@ -32,7 +33,18 @@ static void verify_ipcinfo(void)
TST_EXP_EQ_LU(info.shmmax, shmmax);
TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni);
- TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall);
+
+ /*
+ * On 32-bit compat, the kernel truncates the (64-bit) shmall to the
+ * 32-bit compat shminfo, instead of clamping it like shmmax. The
+ * /proc file still holds the untruncated value, so compare against
+ * its low 32 bits.
+ */
+ SAFE_FILE_SCANF(PATH_KERN_SHMALL, "%llu", &shmall);
+ if (tst_is_compat_mode())
+ TST_EXP_EQ_LU(info.shmall, (uint32_t)shmall);
+ else
+ TST_EXP_EQ_LU(info.shmall, shmall);
}
static struct tst_test test = {
--
2.56.0
More information about the ltp
mailing list