[LTP] [PATCH] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes
Sayali Patil
sayalip@linux.ibm.com
Tue Apr 28 13:57:29 CEST 2026
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
More information about the ltp
mailing list