Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes
@ 2026-04-28 11:57 Sayali Patil
  2026-04-28 14:39 ` [LTP] " linuxtestproject.agent
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sayali Patil @ 2026-04-28 11:57 UTC (permalink / raw)
  To: ltp; +Cc: Ritesh Harjani, Pavithra Prakash, sayalip

hugeshmat05 stores hugepage allocation sizes in int variables and
passes them through shm_test(). This can overflow on systems with
1GB hugepages, where computed test sizes may exceed INT_MAX.

For example, with 1GB hugepages and N=4, the test generates a 4GB
allocation size. Storing this in int truncates the value, resulting
in invalid sizes being passed to shmget() and subsequent failures
such as EINVAL during shared memory attachment.

Use size_t for size-related variables and update the corresponding
printf format specifier to correctly represent allocation sizes.

Fixes: 46640e176d ("hugetlb: add new testcase hugeshmat05.c")
Reported-by: Pavithra Prakash <pavrampu@linux.ibm.com>
Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
---
 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
index 3b2ae351c..eb8663f2c 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
@@ -39,7 +39,7 @@ void setup(void)
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 }
 
-void shm_test(int size)
+void shm_test(size_t size)
 {
 	int shmid;
 	char *shmaddr;
@@ -56,7 +56,7 @@ void shm_test(int size)
 	}
 
 	shmaddr[0] = 1;
-	tst_res(TINFO, "allocated %d huge bytes", size);
+	tst_res(TINFO, "allocated %zu huge bytes", size);
 
 	if (shmdt((const void *)shmaddr) != 0) {
 		shmctl(shmid, IPC_RMID, NULL);
@@ -70,7 +70,7 @@ static void test_hugeshmat(void)
 {
 	unsigned int i;
 
-	const int tst_sizes[] = {
+	const size_t tst_sizes[] = {
 		N * hpage_size - page_size,
 		N * hpage_size - page_size - 1,
 		hpage_size,
-- 
2.52.0


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

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

end of thread, other threads:[~2026-05-06 16:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 11:57 [LTP] [PATCH] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes Sayali Patil
2026-04-28 14:39 ` [LTP] " linuxtestproject.agent
2026-05-06 16:02 ` [LTP] [PATCH] " Andrea Cervesato via ltp
2026-05-06 16:02 ` Andrea Cervesato via ltp

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