Skip to contentSkip to conversation

process_vm_writev02: Fix stack overflow with large buffer size

PATCH Applied Darren Chang via ltp 2 participants 4 messages Oct 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 process_vm_writev02: Fix stack overflow with large buffer size

Both child processes allocate their buffers on the stack. The buffer size can be set with the -s option. If the size is larger than the stack limit (8 MB by default), the test crashes.

Allocate the buffers on the heap with SAFE_MALLOC() instead, and free them after use.

---
 testcases/kernel/syscalls/cma/process_vm_writev02.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/cma/process_vm_writev02.c +8 -2
index aaf4c0b18..15bd66a44 100644
@@ -23,10 +23,11 @@ static int bufsize = 100000;
 
 static void child_alloc_and_verify(int buffsize)
 {
-	char foo[buffsize];
+	char *foo;
 	int i;
 	int err;
 
+	foo = SAFE_MALLOC(buffsize);
 	tst_res(TINFO, "child 0: allocate memory");
 
 	memset(foo, 'a', buffsize);
@@ -43,13 +44,16 @@ static void child_alloc_and_verify(int buffsize)
 		tst_res(TFAIL, "child 0: found %d differences from expected data", err);
 	else
 		tst_res(TPASS, "child 0: read back expected data");
+
+	free(foo);
 }
 
 static void child_write(int buffsize, pid_t pid_alloc)
 {
-	char lp[buffsize];
+	char *lp;
 	struct iovec local, remote;
 
+	lp = SAFE_MALLOC(buffsize);
 	tst_res(TINFO, "child 1: write to the same memory location");
 
 	memset(lp, 'w', buffsize);
@@ -66,6 +70,8 @@ static void child_write(int buffsize, pid_t pid_alloc)
 		tst_brk(TBROK, "process_vm_writev: expected %d bytes but got %ld",
 			buffsize, TST_RET);
 	}
+
+	free(lp);
 }
 
 static void setup(void)
Signature · 5 lines
2.56.0.385.gd3acb90ef8-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Darren Chang via ltp

Hi Darren,

Quoted 1 line · Darren Chang

process_vm_writev02: Fix stack overflow with large buffer size

Verdict - Reviewed

---
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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp