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

* Re: [LTP] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes
  2026-04-28 11:57 [LTP] [PATCH] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes Sayali Patil
@ 2026-04-28 14:39 ` linuxtestproject.agent
  2026-05-06 16:02 ` [LTP] [PATCH] " Andrea Cervesato via ltp
  2026-05-06 16:02 ` Andrea Cervesato via ltp
  2 siblings, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-04-28 14:39 UTC (permalink / raw)
  To: Sayali Patil; +Cc: ltp, LTP AI Reviewer

Hi Sayali,

On Tue, 28 Apr 2026 17:27:29 +0530, Sayali Patil wrote:
> hugetlb/hugeshmat05: use size_t for hugepage allocation sizes

Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com>

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- hugeshmat05.c:47 — shmget() should use SAFE_SHMGET()
- hugeshmat05.c:51 — shmat() should use SAFE_SHMAT()
- hugeshmat05.c:61 — shmdt() should use SAFE_SHMDT()
- hugeshmat05.c:62,66 — shmctl() should use SAFE_SHMCTL()

---
Note:

Our agent completed the review of the patch. 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

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

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

* Re: [LTP] [PATCH] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes
  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 ` Andrea Cervesato via ltp
  2026-05-06 16:02 ` Andrea Cervesato via ltp
  2 siblings, 0 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-06 16:02 UTC (permalink / raw)
  To: Sayali Patil; +Cc: Ritesh Harjani, Pavithra Prakash, ltp

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] [PATCH] hugetlb/hugeshmat05: use size_t for hugepage allocation sizes
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-06 16:02 UTC (permalink / raw)
  To: Sayali Patil; +Cc: Ritesh Harjani, Pavithra Prakash, ltp

Merged, Thanks!

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

^ permalink raw reply	[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