[LTP] [PATCH] mbind04: terminate child processes

Jan Stancek jstancek@redhat.com
Wed Nov 13 20:58:38 CET 2019


verify_policy() forks a child, which continues to run
pass end of function and into same loop in verify_mbind()
as parent, effectively creating fork bomb. With 2 nodes,
there's 45 forked children. With 4 nodes, 765 processes.

Terminate child process at the end of verify_policy();

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/mbind/mbind04.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/mbind/mbind04.c b/testcases/kernel/syscalls/mbind/mbind04.c
index 6a7a2a2321a8..aaad8a988bad 100644
--- a/testcases/kernel/syscalls/mbind/mbind04.c
+++ b/testcases/kernel/syscalls/mbind/mbind04.c
@@ -47,6 +47,7 @@ static void verify_policy(unsigned int node, int mode, unsigned flag)
 	struct bitmask *bm = numa_allocate_nodemask();
 	unsigned int i;
 	void *ptr;
+	pid_t child;
 	unsigned long size = PAGES_ALLOCATED * page_size;
 
 	numa_bitmask_setbit(bm, node);
@@ -69,7 +70,8 @@ static void verify_policy(unsigned int node, int mode, unsigned flag)
 
 	const char *prefix = "child: ";
 
-	if (SAFE_FORK()) {
+	child = SAFE_FORK();
+	if (child) {
 		prefix = "parent: ";
 		tst_reap_children();
 	}
@@ -104,6 +106,9 @@ static void verify_policy(unsigned int node, int mode, unsigned flag)
 
 	if (fail)
 		tst_nodemap_print_counters(nodes);
+
+	if (!child)
+		exit(0);
 }
 
 static const int modes[] = {
-- 
1.8.3.1



More information about the ltp mailing list