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

* 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
  2026-11-22  6:42 ` + selftests-memfd-close-fd-in-sysctl-helpers.patch added to mm-unstable branch Andrew Morton
  1 sibling, 0 replies; 3+ 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] 3+ messages in thread

* + selftests-memfd-close-fd-in-sysctl-helpers.patch added to mm-unstable branch
  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 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-22  6:42 UTC (permalink / raw)
  To: mm-commits, shuah, hughd, david, baolin.wang, zhangchujun, akpm


The patch titled
     Subject: selftests/memfd: close fd in sysctl helpers
has been added to the -mm mm-unstable branch.  Its filename is
     selftests-memfd-close-fd-in-sysctl-helpers.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-memfd-close-fd-in-sysctl-helpers.patch

This patch will later appear in the mm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Zhang Chujun <zhangchujun@cmss.chinamobile.com>
Subject: selftests/memfd: close fd in sysctl helpers
Date: Fri, 13 Nov 2026 15:13:06 +0800

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.

Link: https://patch.msgid.link/20261113071306.1673-1-zhangchujun@cmss.chinamobile.com
Fixes: 6469b66e3f5a ("selftests: improve vm.memfd_noexec sysctl tests")
Signed-off-by: Zhang Chujun <zhangchujun@cmss.chinamobile.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Shuah Khan <shuah@kernel.org>

 tools/testing/selftests/memfd/memfd_test.c |    6 ++++++
 1 file changed, 6 insertions(+)

--- a/tools/testing/selftests/memfd/memfd_test.c~selftests-memfd-close-fd-in-sysctl-helpers
+++ a/tools/testing/selftests/memfd/memfd_test.c
@@ -126,6 +126,8 @@ static void sysctl_assert_write(const ch
 		printf("write sysctl %s failed: %m\n", val);
 		abort();
 	}
+
+	close(fd);
 }
 
 static void sysctl_fail_write(const char *val)
@@ -142,6 +144,8 @@ static void sysctl_fail_write(const char
 				val);
 		abort();
 	}
+
+	close(fd);
 }
 
 static void sysctl_assert_equal(const char *val)
@@ -159,6 +163,8 @@ static void sysctl_assert_equal(const ch
 		abort();
 	}
 
+	close(fd);
+
 	/* Strip trailing whitespace. */
 	p = buf;
 	while (!isspace(*p))
_

Patches currently in -mm which might be from zhangchujun@cmss.chinamobile.com are

mm-page_owner-use-%u-to-print-the-stack-depot-handle.patch
selftests-cgroup-test_zswap-check-malloc-return-value.patch
selftests-memfd-close-fd-in-sysctl-helpers.patch


^ permalink raw reply	[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.