* [PATCH] selftests/memfd: close fd in sysctl helpers
@ 2026-11-13 7:13 zhangchujun
2026-11-14 7:13 ` sashiko-bot
0 siblings, 1 reply; 2+ 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] 2+ messages in thread
* Re: [PATCH] selftests/memfd: close fd in sysctl helpers
2026-11-13 7:13 [PATCH] selftests/memfd: close fd in sysctl helpers zhangchujun
@ 2026-11-14 7:13 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-14 7:13 UTC (permalink / raw)
To: zhangchujun, hughd, david; +Cc: akpm, baolin.wang, shuah, linux-mm
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] selftests/memfd: Signed-off-by trailer uses handle instead of
real name
- [Low] selftests/memfd: missing Fixes trailers for sysctl helper fd
leaks
--
commit f7c1cc7489dcee54b6a1302dc52c7e84f82859e6
Author: zhangchujun <zhangchujun@cmss.chinamobile.com>
> selftests/memfd: close fd in sysctl helpers
>
> 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>
[Severity: High]
Per Documentation/process/submitting-patches.rst, the Signed-off-by trailer
and commit Author field must use a real human name rather than a single-word
account handle or username ("zhangchujun").
[Severity: Low]
Since this fixes file descriptor leaks introduced in sysctl_assert_write(),
sysctl_fail_write(), and sysctl_assert_equal(), should the commit message
include Fixes tags for the commits that added those helpers?
Fixes: 11f75a01448f ("selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC")
Fixes: 6469b66e3f5a ("selftests: improve vm.memfd_noexec sysctl tests")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261113071306.1673-1-zhangchujun@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-14 7:13 UTC | newest]
Thread overview: 2+ 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
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.