[LTP] tst_assert: Use 'long long' to fix 32bit compat mode truncation
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Thu Sep 24 15:24:08 CEST 2026
Hi Andrea,
On Thu, 24 Sep 2026 13:25:12 +0200, Andrea Cervesato wrote:
> [PATCH 1/3] tst_assert: Use 'long long' to fix 32bit compat mode truncation
--- [PATCH 1/3] ---
> @@ -25,16 +25,17 @@ void tst_assert_int(const char *file, const int lineno, const char *path, int va
>
> void tst_assert_ulong(const char *file, const int lineno, const char *path, unsigned long val)
> {
> - unsigned long sys_val;
> + unsigned long long sys_val;
>
> - safe_file_scanf(file, lineno, NULL, path, "%lu", &sys_val);
> + safe_file_scanf(file, lineno, NULL, path, "%llu", &sys_val);
>
> - if (val == sys_val) {
> + if (val == (unsigned long)sys_val) {
> tst_res_(file, lineno, TPASS, "%s = %lu", path, val);
> return;
> }
>
> - tst_res_(file, lineno, TFAIL, "%s != %lu got %lu", path, val, sys_val);
> + tst_res_(file, lineno, TFAIL, "%s != %lu got %lu",
> + path, val, (unsigned long)sys_val);
> }
Casting sys_val to (unsigned long) truncates values exceeding ULONG_MAX on
32-bit systems, causing false passes when (sys_val & 0xFFFFFFFF) == val and
printing a truncated value on failure. Compare values without truncation
using (unsigned long long)val == sys_val, and print sys_val with %llu on
mismatch. Handling of 32-bit compat truncation for /proc/sys/kernel/shmall
should be done in shmctl03.c instead of altering generic library assertions.
--- [PATCH 2/3] ---
> @@ -30,7 +30,14 @@ static void verify_ipcinfo(void)
> else
> tst_res(TPASS, "shmmin = 1");
>
> - TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax);
> + if (tst_is_compat_mode() && info.shmmax == INT_MAX) {
> + unsigned long long shmmax;
> + SAFE_FILE_SCANF(PATH_KERN_SHMMAX, "%llu", &shmmax);
> + TST_EXP_LE_LU(INT_MAX, shmmax);
> + } else {
> + TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax);
> + }
> +
Branching on info.shmmax == INT_MAX conditions on the result of the syscall
under test, and TST_EXP_LE_LU(INT_MAX, shmmax) only asserts that the sysctl
file is >= INT_MAX rather than verifying that info.shmmax was clamped.
Read PATH_KERN_SHMMAX into shmmax first, and if in compat mode with
shmmax >= INT_MAX, assert TST_EXP_EQ_LU(info.shmmax, (unsigned long)INT_MAX);
otherwise assert info.shmmax == shmmax.
--- [PATCH 3/3] ---
> + safe_shmctl(__FILE__, __LINE__, 0, IPC_INFO, ((struct shmid_ds *)&info));
Because shmctl() is the syscall under test, replacing TEST(shmctl(...)) with
safe_shmctl() turns a syscall failure into TBROK instead of TFAIL. In
addition, tests must not call safe_*() functions directly. Keep
TEST(shmctl(...)) or use TST_EXP_PASS(shmctl(0, IPC_INFO, ...)).
> + TST_EXP_LE_LU(info.shmmin, 1);
TST_EXP_LE_LU() checks info.shmmin <= 1, which incorrectly allows 0 to pass.
The kernel SHMMIN constant is 1 and requires equality. Use
TST_EXP_EQ_LU(info.shmmin, 1).
Verdict - Needs revision
---
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
More information about the ltp
mailing list