[LTP] [PATCH] process_vm_writev02: Fix stack overflow with large buffer size

Darren Chang chihsheng@google.com
Wed Oct 14 08:02:12 CEST 2026


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.

Signed-off-by: Darren Chang <chihsheng@google.com>
---
 testcases/kernel/syscalls/cma/process_vm_writev02.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/cma/process_vm_writev02.c b/testcases/kernel/syscalls/cma/process_vm_writev02.c
index aaf4c0b18..15bd66a44 100644
--- a/testcases/kernel/syscalls/cma/process_vm_writev02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_writev02.c
@@ -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)
-- 
2.56.0.385.gd3acb90ef8-goog



More information about the ltp mailing list