Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Cen Zhang <zzzccc427@gmail.com>, Carlos Maiolino <cem@kernel.org>,
	Hans Holmberg <hans.holmberg@wdc.com>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com
Subject: Re: [PATCH v2] xfs: tear down zoned sysfs before freeing zone info
Date: Sun, 5 Jul 2026 12:22:23 +0900	[thread overview]
Message-ID: <51965467-4fd7-4d85-8382-9f8928ec718b@kernel.org> (raw)
In-Reply-To: <20260705024100.3398090-1-zzzccc427@gmail.com>

On 7/5/26 11:41, Cen Zhang wrote:
> The zoned sysfs directory is currently registered as part of the generic
> per-mount sysfs setup, but the data it exposes has a narrower lifetime.
> mp->m_zone_info is allocated later by xfs_mount_zones() and freed by
> xfs_unmount_zones(), while the zoned sysfs kobject remains registered
> until xfs_mount_sysfs_del() runs near the end of xfs_unmountfs().
> 
> A read of nr_open_zones can therefore enter through the still-live sysfs
> kobject after xfs_unmount_zones() has freed mp->m_zone_info, leading to a
> use-after-free in nr_open_zones_show().
> 
> Make the zoned sysfs lifetime match the zone allocator lifetime.  Create
> the zoned sysfs directory only after xfs_mount_zones() succeeds, and
> remove it before xfs_unmount_zones() frees m_zone_info during unmount and
> mount failure cleanup.

[...]

> Tear down the zoned sysfs directory before freeing m_zone_info instead of
> serializing nr_open_zones_show() with s_umount.

Hmmm... What if the user already has entered the show function but gets
preempted before referencing the zone info and umount proceeds ? That problem
remains, no ?

> 
>  fs/xfs/xfs_mount.c | 10 +++++++++-
>  fs/xfs/xfs_sysfs.c | 28 +++++++++++++++++-----------
>  fs/xfs/xfs_sysfs.h |  2 ++
>  3 files changed, 28 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
> index be90c7b03994..2dcb10bc6187 100644
> --- a/fs/xfs/xfs_mount.c
> +++ b/fs/xfs/xfs_mount.c
> @@ -1178,6 +1178,9 @@ xfs_mountfs(
>  		error = xfs_mount_zones(mp);
>  		if (error)
>  			goto out_rtunmount;
> +		error = xfs_zoned_sysfs_init(mp);
> +		if (error)
> +			goto out_unmount_zones;

Why not call this in xfs_mount_zones() ?

>  	}
>  
>  	/*
> @@ -1233,6 +1236,9 @@ xfs_mountfs(
>   out_agresv:
>  	xfs_fs_unreserve_ag_blocks(mp);
>  	xfs_qm_unmount_quotas(mp);
> +	if (xfs_has_zoned(mp))
> +		xfs_zoned_sysfs_del(mp);

And this as the first thing in xfs_unmount_zones() ?

Another simpler approach could be to simply call xfs_mount_sysfs_del() earlier
in xfs_unmountfs(). Though that may have other implications and I have not
checked details.

-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-07-05  3:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-05  2:41 [PATCH v2] xfs: tear down zoned sysfs before freeing zone info Cen Zhang
2026-07-05  3:22 ` Damien Le Moal [this message]
2026-07-05  3:44   ` Cen Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51965467-4fd7-4d85-8382-9f8928ec718b@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=baijiaju1990@gmail.com \
    --cc=cem@kernel.org \
    --cc=hans.holmberg@wdc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=zzzccc427@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox