public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] overcommit_memory: Fix integer overflow and 32-bit limits
@ 2025-10-16 12:40 Ben Copeland
  2025-10-17  9:58 ` Li Wang via ltp
  2025-10-17 16:22 ` Petr Vorel
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Copeland @ 2025-10-16 12:40 UTC (permalink / raw)
  To: ltp; +Cc: arnd, lkft-triage, dan.carpenter

The overcommit test uses sum_total, the sum (memory and swap) to test
the overcommit settings.

This fixes two problems on 32-bit systems. The first is seen with a
integer overflow can occur when calculating sum_total * 2, if the
sum_total is larger than 2GB. The second is limited virtual address
space (2-3GB) means the test can fail from address space exhaustion
before overcommit has been tested.

Now the test runs correctly on low-memory 32-bit systems while avoiding
both the overflow bug and virtual address space issues.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Ben Copeland <ben.copeland@linaro.org>
---
 .../kernel/mem/tunable/overcommit_memory.c    | 31 ++++++++++++++-----
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c b/testcases/kernel/mem/tunable/overcommit_memory.c
index 9b2cb479d..d4faaeee0 100644
--- a/testcases/kernel/mem/tunable/overcommit_memory.c
+++ b/testcases/kernel/mem/tunable/overcommit_memory.c
@@ -131,24 +131,41 @@ static void overcommit_memory_test(void)
 	TST_SYS_CONF_LONG_SET(OVERCOMMIT_MEMORY, 2, 1);
 
 	update_mem_commit();
-	alloc_and_check(commit_left * 2, EXPECT_FAIL);
-	alloc_and_check(commit_limit + total_batch_size, EXPECT_FAIL);
-	update_mem_commit();
-	alloc_and_check(commit_left / 2, EXPECT_PASS);
+	/* Skip tests that would overflow or exceed 32-bit address space */
+	if (tst_kernel_bits() == 64 || (unsigned long)commit_left <= TST_GB / TST_KB) {
+		alloc_and_check(commit_left * 2, EXPECT_FAIL);
+		alloc_and_check(commit_limit + total_batch_size, EXPECT_FAIL);
+		update_mem_commit();
+		alloc_and_check(commit_left / 2, EXPECT_PASS);
+	} else {
+		tst_res(TCONF, "Skipping large allocation tests due to address space limits");
+	}
 
 	/* start to test overcommit_memory=0 */
 	TST_SYS_CONF_LONG_SET(OVERCOMMIT_MEMORY, 0, 1);
 
 	update_mem();
 	alloc_and_check(free_total / 2, EXPECT_PASS);
-	alloc_and_check(sum_total * 2, EXPECT_FAIL);
+	/* Skip if sum_total * 2 would exceed address space.
+	 * On 32-bit, skip when sum_total > ULONG_MAX/4 (~1GB).
+	 * Most 32-bit systems with <=1GB RAM can map 2x that in 3GB vaddr space.
+	 * Systems with 2GB+ RAM likely cannot fit allocations in vaddr space. */
+	if (tst_kernel_bits() == 64 || (unsigned long)sum_total <= TST_GB / TST_KB) {
+		alloc_and_check(sum_total * 2, EXPECT_FAIL);
+	} else {
+		tst_res(TCONF, "Skipping large allocation test due to address space limits");
+	}
 
 	/* start to test overcommit_memory=1 */
 	TST_SYS_CONF_LONG_SET(OVERCOMMIT_MEMORY, 1, 1);
 
 	alloc_and_check(sum_total / 2, EXPECT_PASS);
-	alloc_and_check(sum_total, EXPECT_PASS);
-	alloc_and_check(sum_total * 2, EXPECT_PASS);
+	if (tst_kernel_bits() == 64 || (unsigned long)sum_total <= TST_GB / TST_KB) {
+		alloc_and_check(sum_total, EXPECT_PASS);
+		alloc_and_check(sum_total * 2, EXPECT_PASS);
+	} else {
+		tst_res(TCONF, "Skipping large allocation tests due to address space limits");
+	}
 
 }
 
-- 
2.51.0


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v3] overcommit_memory: Fix integer overflow and 32-bit limits
  2025-10-16 12:40 [LTP] [PATCH v3] overcommit_memory: Fix integer overflow and 32-bit limits Ben Copeland
@ 2025-10-17  9:58 ` Li Wang via ltp
  2025-10-17 16:22 ` Petr Vorel
  1 sibling, 0 replies; 3+ messages in thread
From: Li Wang via ltp @ 2025-10-17  9:58 UTC (permalink / raw)
  To: Ben Copeland; +Cc: dan.carpenter, lkft-triage, arnd, ltp

On Thu, Oct 16, 2025 at 8:41 PM Ben Copeland <ben.copeland@linaro.org>
wrote:

> The overcommit test uses sum_total, the sum (memory and swap) to test
> the overcommit settings.
>
> This fixes two problems on 32-bit systems. The first is seen with a
> integer overflow can occur when calculating sum_total * 2, if the
> sum_total is larger than 2GB. The second is limited virtual address
> space (2-3GB) means the test can fail from address space exhaustion
> before overcommit has been tested.
>
> Now the test runs correctly on low-memory 32-bit systems while avoiding
> both the overflow bug and virtual address space issues.
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Ben Copeland <ben.copeland@linaro.org>
>

Reviewed-by: Li Wang <liwang@redhat.com>


---
>  .../kernel/mem/tunable/overcommit_memory.c    | 31 ++++++++++++++-----
>  1 file changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c
> b/testcases/kernel/mem/tunable/overcommit_memory.c
> index 9b2cb479d..d4faaeee0 100644
> --- a/testcases/kernel/mem/tunable/overcommit_memory.c
> +++ b/testcases/kernel/mem/tunable/overcommit_memory.c
> @@ -131,24 +131,41 @@ static void overcommit_memory_test(void)
>         TST_SYS_CONF_LONG_SET(OVERCOMMIT_MEMORY, 2, 1);
>
>         update_mem_commit();
> -       alloc_and_check(commit_left * 2, EXPECT_FAIL);
> -       alloc_and_check(commit_limit + total_batch_size, EXPECT_FAIL);
> -       update_mem_commit();
> -       alloc_and_check(commit_left / 2, EXPECT_PASS);
> +       /* Skip tests that would overflow or exceed 32-bit address space */
> +       if (tst_kernel_bits() == 64 || (unsigned long)commit_left <=
> TST_GB / TST_KB) {
> +               alloc_and_check(commit_left * 2, EXPECT_FAIL);
> +               alloc_and_check(commit_limit + total_batch_size,
> EXPECT_FAIL);
> +               update_mem_commit();
> +               alloc_and_check(commit_left / 2, EXPECT_PASS);
> +       } else {
> +               tst_res(TCONF, "Skipping large allocation tests due to
> address space limits");
> +       }
>
>         /* start to test overcommit_memory=0 */
>         TST_SYS_CONF_LONG_SET(OVERCOMMIT_MEMORY, 0, 1);
>
>         update_mem();
>         alloc_and_check(free_total / 2, EXPECT_PASS);
> -       alloc_and_check(sum_total * 2, EXPECT_FAIL);
> +       /* Skip if sum_total * 2 would exceed address space.
> +        * On 32-bit, skip when sum_total > ULONG_MAX/4 (~1GB).
> +        * Most 32-bit systems with <=1GB RAM can map 2x that in 3GB vaddr
> space.
> +        * Systems with 2GB+ RAM likely cannot fit allocations in vaddr
> space. */
> +       if (tst_kernel_bits() == 64 || (unsigned long)sum_total <= TST_GB
> / TST_KB) {
> +               alloc_and_check(sum_total * 2, EXPECT_FAIL);
> +       } else {
> +               tst_res(TCONF, "Skipping large allocation test due to
> address space limits");
> +       }
>
>         /* start to test overcommit_memory=1 */
>         TST_SYS_CONF_LONG_SET(OVERCOMMIT_MEMORY, 1, 1);
>
>         alloc_and_check(sum_total / 2, EXPECT_PASS);
> -       alloc_and_check(sum_total, EXPECT_PASS);
> -       alloc_and_check(sum_total * 2, EXPECT_PASS);
> +       if (tst_kernel_bits() == 64 || (unsigned long)sum_total <= TST_GB
> / TST_KB) {
> +               alloc_and_check(sum_total, EXPECT_PASS);
> +               alloc_and_check(sum_total * 2, EXPECT_PASS);
> +       } else {
> +               tst_res(TCONF, "Skipping large allocation tests due to
> address space limits");
> +       }
>
>  }
>
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v3] overcommit_memory: Fix integer overflow and 32-bit limits
  2025-10-16 12:40 [LTP] [PATCH v3] overcommit_memory: Fix integer overflow and 32-bit limits Ben Copeland
  2025-10-17  9:58 ` Li Wang via ltp
@ 2025-10-17 16:22 ` Petr Vorel
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2025-10-17 16:22 UTC (permalink / raw)
  To: Ben Copeland; +Cc: arnd, lkft-triage, ltp, dan.carpenter

Hi all,

> The overcommit test uses sum_total, the sum (memory and swap) to test
> the overcommit settings.

> This fixes two problems on 32-bit systems. The first is seen with a
> integer overflow can occur when calculating sum_total * 2, if the
> sum_total is larger than 2GB. The second is limited virtual address
> space (2-3GB) means the test can fail from address space exhaustion
> before overcommit has been tested.

> Now the test runs correctly on low-memory 32-bit systems while avoiding
> both the overflow bug and virtual address space issues.

Thanks, also this patch merged!

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-17 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-16 12:40 [LTP] [PATCH v3] overcommit_memory: Fix integer overflow and 32-bit limits Ben Copeland
2025-10-17  9:58 ` Li Wang via ltp
2025-10-17 16:22 ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox