All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/memfd: close fd in sysctl helpers
@ 2026-11-13  7:13 zhangchujun
  2026-11-14  7:13 ` sashiko-bot
  2026-11-22  6:42 ` + selftests-memfd-close-fd-in-sysctl-helpers.patch added to mm-unstable branch Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: zhangchujun @ 2026-11-13  7:13 UTC (permalink / raw)
  To: hughd, david
  Cc: akpm, baolin.wang, shuah, linux-mm, linux-kselftest, linux-kernel,
	zhangchujun

The three sysctl helpers sysctl_assert_write(), sysctl_fail_write()
and sysctl_assert_equal() open /proc/sys/vm/memfd_noexec but never
close the descriptor, leaking one fd on every call.  The noexec tests
call these helpers in a loop, so the test can run out of file
descriptors on a system with a low limit.

Close the fd before returning from each helper.

Signed-off-by: zhangchujun <zhangchujun@cmss.chinamobile.com>

diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index cdab3a837624..8bdfa91d3b76 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -120,6 +120,8 @@ static void sysctl_assert_write(const char *val)
 		printf("write sysctl %s failed: %m\n", val);
 		abort();
 	}
+
+	close(fd);
 }
 
 static void sysctl_fail_write(const char *val)
@@ -136,6 +138,8 @@ static void sysctl_fail_write(const char *val)
 				val);
 		abort();
 	}
+
+	close(fd);
 }
 
 static void sysctl_assert_equal(const char *val)
@@ -153,6 +157,8 @@ static void sysctl_assert_equal(const char *val)
 		abort();
 	}
 
+	close(fd);
+
 	/* Strip trailing whitespace. */
 	p = buf;
 	while (!isspace(*p))
-- 
2.50.1.windows.1




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

end of thread, other threads:[~2026-11-22  6:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  7:13 [PATCH] selftests/memfd: close fd in sysctl helpers zhangchujun
2026-11-14  7:13 ` sashiko-bot
2026-11-22  6:42 ` + selftests-memfd-close-fd-in-sysctl-helpers.patch added to mm-unstable branch Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.