mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] init: do_mounts: free the ramfs info of the boot rootfs
@ 2026-10-16 14:27 Breno Leitao
  2026-10-27  9:48 ` Breno Leitao
  0 siblings, 1 reply; 3+ messages in thread
From: Breno Leitao @ 2026-10-16 14:27 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Shuah Khan
  Cc: linux-fsdevel, linux-kernel, catalin.marinas, linux-kselftest,
	kernel-team, Breno Leitao

Kmemleak is reporting the following leak in ramfs_init_fs_context:

  unreferenced object 0xffff000080302480 (size 8):
    comm "swapper/0", pid 0, jiffies 4294667306
    hex dump (first 8 bytes):
      ed 01 00 00 00 00 00 00                          ........
    backtrace (crc bea23b04):
      __kmalloc_cache_noprof+0x28c/0x5a0
      ramfs_init_fs_context+0x5c/0xf8
      rootfs_init_fs_context+0x30/0x40
      alloc_fs_context+0x4c0/0x6a8
      fs_context_for_mount+0x28/0x40
      vfs_kern_mount+0x40/0x220
      init_mount_tree+0x80/0x440
      mnt_init+0x138/0x170
      vfs_caches_init+0x2c/0x48
      start_kernel+0x350/0x3f8

When init pivot_root()s away from a ramfs-backed boot rootfs and
unmounts it, the rootfs superblock is killed with kill_anon_super() and
the struct ramfs_fs_info allocated by ramfs_init_fs_context() is never
freed.

Kill a ramfs-backed rootfs with ramfs_kill_sb(). A tmpfs-backed one keeps
kill_anon_super(), as shmem frees its info in ->put_super.

Fixes: 576ee5dfd459 ("fs: add immutable rootfs")
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 init/do_mounts.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 95e0b3a0f711bd..b088021b1546d8 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -503,10 +503,18 @@ static int rootfs_init_fs_context(struct fs_context *fc)
 	return ramfs_init_fs_context(fc);
 }
 
+static void rootfs_kill_sb(struct super_block *sb)
+{
+	if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
+		kill_anon_super(sb);
+	else
+		ramfs_kill_sb(sb);
+}
+
 struct file_system_type rootfs_fs_type = {
 	.name		= "rootfs",
 	.init_fs_context = rootfs_init_fs_context,
-	.kill_sb	= kill_anon_super,
+	.kill_sb	= rootfs_kill_sb,
 };
 
 void __init init_rootfs(void)

---
base-commit: d419d682257d813f6cb7a28e42b35d0edf4ad038
change-id: 20261016-rootfs-kill-sb-4f1b597dab24

Best regards,
--  
Breno Leitao <leitao@debian.org>


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

* Re: [PATCH] init: do_mounts: free the ramfs info of the boot rootfs
  2026-10-16 14:27 [PATCH] init: do_mounts: free the ramfs info of the boot rootfs Breno Leitao
@ 2026-10-27  9:48 ` Breno Leitao
  2026-10-29  9:28   ` Zenghui Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Breno Leitao @ 2026-10-27  9:48 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Shuah Khan
  Cc: linux-fsdevel, linux-kernel, catalin.marinas, linux-kselftest,
	kernel-team

On Fri, Oct 16, 2026 at 07:27:58AM -0700, Breno Leitao wrote:
> Kmemleak is reporting the following leak in ramfs_init_fs_context:
> 
>   unreferenced object 0xffff000080302480 (size 8):
>     comm "swapper/0", pid 0, jiffies 4294667306
>     hex dump (first 8 bytes):
>       ed 01 00 00 00 00 00 00                          ........
>     backtrace (crc bea23b04):
>       __kmalloc_cache_noprof+0x28c/0x5a0
>       ramfs_init_fs_context+0x5c/0xf8
>       rootfs_init_fs_context+0x30/0x40
>       alloc_fs_context+0x4c0/0x6a8
>       fs_context_for_mount+0x28/0x40
>       vfs_kern_mount+0x40/0x220
>       init_mount_tree+0x80/0x440
>       mnt_init+0x138/0x170
>       vfs_caches_init+0x2c/0x48
>       start_kernel+0x350/0x3f8
> 
> When init pivot_root()s away from a ramfs-backed boot rootfs and
> unmounts it, the rootfs superblock is killed with kill_anon_super() and
> the struct ramfs_fs_info allocated by ramfs_init_fs_context() is never
> freed.
> 
> Kill a ramfs-backed rootfs with ramfs_kill_sb(). A tmpfs-backed one keeps
> kill_anon_super(), as shmem frees its info in ->put_super.
> 
> Fixes: 576ee5dfd459 ("fs: add immutable rootfs")
> Signed-off-by: Breno Leitao <leitao@debian.org>

Ping?

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

* Re: [PATCH] init: do_mounts: free the ramfs info of the boot rootfs
  2026-10-27  9:48 ` Breno Leitao
@ 2026-10-29  9:28   ` Zenghui Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Zenghui Yu @ 2026-10-29  9:28 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Shuah Khan,
	linux-fsdevel, linux-kernel, catalin.marinas, linux-kselftest,
	kernel-team

On 10/27/26 5:48 PM, Breno Leitao wrote:
> On Fri, Oct 16, 2026 at 07:27:58AM -0700, Breno Leitao wrote:
> > Kmemleak is reporting the following leak in ramfs_init_fs_context:
> >
> >   unreferenced object 0xffff000080302480 (size 8):
> >     comm "swapper/0", pid 0, jiffies 4294667306
> >     hex dump (first 8 bytes):
> >       ed 01 00 00 00 00 00 00                          ........
> >     backtrace (crc bea23b04):
> >       __kmalloc_cache_noprof+0x28c/0x5a0
> >       ramfs_init_fs_context+0x5c/0xf8
> >       rootfs_init_fs_context+0x30/0x40
> >       alloc_fs_context+0x4c0/0x6a8
> >       fs_context_for_mount+0x28/0x40
> >       vfs_kern_mount+0x40/0x220
> >       init_mount_tree+0x80/0x440
> >       mnt_init+0x138/0x170
> >       vfs_caches_init+0x2c/0x48
> >       start_kernel+0x350/0x3f8
> >
> > When init pivot_root()s away from a ramfs-backed boot rootfs and
> > unmounts it, the rootfs superblock is killed with kill_anon_super() and
> > the struct ramfs_fs_info allocated by ramfs_init_fs_context() is never
> > freed.
> >
> > Kill a ramfs-backed rootfs with ramfs_kill_sb(). A tmpfs-backed one keeps
> > kill_anon_super(), as shmem frees its info in ->put_super.
> >
> > Fixes: 576ee5dfd459 ("fs: add immutable rootfs")
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> 
> Ping?

There is a similar fix for that.

https://lore.kernel.org/20261009055546.85279-1-kmehltretter@gmail.com

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

end of thread, other threads:[~2026-10-29  9:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-16 14:27 [PATCH] init: do_mounts: free the ramfs info of the boot rootfs Breno Leitao
2026-10-27  9:48 ` Breno Leitao
2026-10-29  9:28   ` Zenghui Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®