* [PATCH] selftests/statmount: Fix file descriptor leak in setup_namespace
@ 2026-07-04 12:04 Malaya Kumar Rout
2026-07-06 13:08 ` Christian Brauner
2026-09-03 1:15 ` Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Malaya Kumar Rout @ 2026-07-04 12:04 UTC (permalink / raw)
To: linux-kselftest
Cc: mrout, skhan, me, Malaya Kumar Rout, Shuah Khan,
Christian Brauner, Andrei Vagin, Andrew Morton,
Bala-Vignesh-Reddy, Bhavik Sachdev, linux-kernel
In setup_namespace(), f_mountinfo is opened with fopen() at line 115
but is never closed. Multiple ksft_exit_fail_msg() calls exit the
program without closing this file descriptor, and the cleanup_namespace()
function registered with atexit() also doesn't close it.
Add fclose(f_mountinfo) in cleanup_namespace() to ensure the file
descriptor is properly closed on both normal and error exit paths,
since cleanup_namespace() is already registered as an atexit handler.
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
---
tools/testing/selftests/filesystems/statmount/statmount_test.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c
index 8dc018d47a93..7d9035c1815f 100644
--- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
+++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
@@ -82,6 +82,9 @@ static void cleanup_namespace(void)
{
int ret;
+ if (f_mountinfo)
+ fclose(f_mountinfo);
+
ret = fchdir(orig_root);
if (ret == -1)
ksft_perror("fchdir to original root");
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/statmount: Fix file descriptor leak in setup_namespace
2026-07-04 12:04 [PATCH] selftests/statmount: Fix file descriptor leak in setup_namespace Malaya Kumar Rout
@ 2026-07-06 13:08 ` Christian Brauner
2026-09-03 1:15 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2026-07-06 13:08 UTC (permalink / raw)
To: linux-kselftest, Malaya Kumar Rout
Cc: mrout, skhan, me, Shuah Khan, Andrei Vagin, Andrew Morton,
Bala-Vignesh-Reddy, Bhavik Sachdev, linux-kernel
On Sat, 04 Jul 2026 17:34:36 +0530, Malaya Kumar Rout wrote:
> selftests/statmount: Fix file descriptor leak in setup_namespace
Applied to the vfs-7.3.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.3.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.3.misc
[1/1] selftests/statmount: Fix file descriptor leak in setup_namespace
https://git.kernel.org/vfs/vfs/c/38e48ee20792
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/statmount: Fix file descriptor leak in setup_namespace
2026-07-04 12:04 [PATCH] selftests/statmount: Fix file descriptor leak in setup_namespace Malaya Kumar Rout
2026-07-06 13:08 ` Christian Brauner
@ 2026-09-03 1:15 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-09-03 1:15 UTC (permalink / raw)
To: Malaya Kumar Rout
Cc: linux-kselftest, mrout, skhan, me, Shuah Khan, Christian Brauner,
Andrei Vagin, Bala-Vignesh-Reddy, Bhavik Sachdev, linux-kernel,
Miklos Szeredi
On Sat, 4 Jul 2026 17:34:36 +0530 Malaya Kumar Rout <malayarout91@gmail.com> wrote:
> In setup_namespace(), f_mountinfo is opened with fopen() at line 115
> but is never closed. Multiple ksft_exit_fail_msg() calls exit the
> program without closing this file descriptor, and the cleanup_namespace()
> function registered with atexit() also doesn't close it.
>
> Add fclose(f_mountinfo) in cleanup_namespace() to ensure the file
> descriptor is properly closed on both normal and error exit paths,
> since cleanup_namespace() is already registered as an atexit handler.
>
Thanks.
get_maintainer totally sucks with selftests/, alas. When determining
who should be cc'ed it's best to poke around in git-blame.
I did that. Hi, Miklos!
> --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c
> +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c
> @@ -82,6 +82,9 @@ static void cleanup_namespace(void)
> {
> int ret;
>
> + if (f_mountinfo)
> + fclose(f_mountinfo);
> +
> ret = fchdir(orig_root);
> if (ret == -1)
> ksft_perror("fchdir to original root");
AI review suggests that the patch is good, but the leak is not fully
resolved:
https://sashiko.dev/#/patchset/20260704120437.99851-1-malayarout91@gmail.com
All that being said, we don't care much about leaks in selftests/.
Because exit() handles them pretty darn well. So fixing this is mainly
a matter of pride and of setting a good example.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-03 1:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 12:04 [PATCH] selftests/statmount: Fix file descriptor leak in setup_namespace Malaya Kumar Rout
2026-07-06 13:08 ` Christian Brauner
2026-09-03 1:15 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox