From: "Darrick J. Wong" <djwong@kernel.org>
To: Yousef Alhouseen <alhouseenyousef@gmail.com>
Cc: Carlos Maiolino <cem@kernel.org>,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
syzbot+97f2c05378c5d68dcb8c@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] xfs: zero newly allocated btree root space
Date: Tue, 30 Jun 2026 09:11:13 -0700 [thread overview]
Message-ID: <20260630161113.GB6526@frogsfrogsfrogs> (raw)
In-Reply-To: <20260630100621.7173-1-alhouseenyousef@gmail.com>
On Tue, Jun 30, 2026 at 12:06:21PM +0200, Yousef Alhouseen wrote:
> xfs_broot_realloc() preserves the existing in-inode btree root while
> growing its allocation, but leaves the added bytes uninitialized. The
> inode log formatter copies if_broot_bytes bytes into the journal, so those
> bytes reach the log record and its CRC calculation before every location
> has necessarily been overwritten by btree updates.
>
> Request __GFP_ZERO for the initial allocation and every subsequent
> allocation or reallocation, as required by krealloc() semantics. This
> keeps stale heap contents out of the filesystem log without a separate
> memset after each growth.
>
> Fixes: 6c1c55ac3c05 ("xfs: refactor the inode fork memory allocation functions")
> Suggested-by: Darrick J. Wong <djwong@kernel.org>
> Reported-by: syzbot+97f2c05378c5d68dcb8c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=97f2c05378c5d68dcb8c
I wonder, did you figure out exactly *which* code path was leaving
if_broot partially uninitialized? Somewhere out there, someone will get
cranky at the reduced performance that comes from zeroing (especially on
krealloc) when most of the codepaths will immediately zero/set the
buffer anyway.
> Cc: stable@vger.kernel.org
> Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
In the long run I'm willing to take a small performance hit of having
many layered protections as is reasonably performant to avoid spilling
kernel memory contents to disk, though, so
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
(others may disagree)
--D
> ---
> Changes in v2:
> - Use __GFP_ZERO instead of an explicit memset after krealloc().
> - Apply __GFP_ZERO consistently across the allocation lifetime.
>
> fs/xfs/libxfs/xfs_inode_fork.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
> index 606a36526ce2..dc05540fa85b 100644
> --- a/fs/xfs/libxfs/xfs_inode_fork.c
> +++ b/fs/xfs/libxfs/xfs_inode_fork.c
> @@ -384,7 +384,8 @@ xfs_broot_alloc(
> ASSERT(ifp->if_broot == NULL);
>
> ifp->if_broot = kmalloc(new_size,
> - GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
> + GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL |
> + __GFP_ZERO);
> ifp->if_broot_bytes = new_size;
> return ifp->if_broot;
> }
> @@ -417,7 +418,8 @@ xfs_broot_realloc(
> if (ifp->if_broot_bytes > 0 && ifp->if_broot_bytes > new_size) {
> struct xfs_btree_block *old_broot = ifp->if_broot;
>
> - ifp->if_broot = kmalloc(new_size, GFP_KERNEL | __GFP_NOFAIL);
> + ifp->if_broot = kmalloc(new_size,
> + GFP_KERNEL | __GFP_NOFAIL | __GFP_ZERO);
> ifp->if_broot_bytes = new_size;
> memcpy(ifp->if_broot, old_broot, new_size);
> kfree(old_broot);
> @@ -429,7 +431,7 @@ xfs_broot_realloc(
> * object.
> */
> ifp->if_broot = krealloc(ifp->if_broot, new_size,
> - GFP_KERNEL | __GFP_NOFAIL);
> + GFP_KERNEL | __GFP_NOFAIL | __GFP_ZERO);
> ifp->if_broot_bytes = new_size;
> return ifp->if_broot;
> }
> --
> 2.54.0
>
next prev parent reply other threads:[~2026-06-30 16:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 10:06 [PATCH v2] xfs: zero newly allocated btree root space Yousef Alhouseen
2026-06-30 16:11 ` Darrick J. Wong [this message]
2026-06-30 20:39 ` Yousef Alhouseen
2026-07-01 10:56 ` Christoph Hellwig
2026-07-01 15:52 ` Darrick J. Wong
2026-07-02 11:05 ` Christoph Hellwig
2026-07-02 15:31 ` Darrick J. Wong
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=20260630161113.GB6526@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=alhouseenyousef@gmail.com \
--cc=cem@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+97f2c05378c5d68dcb8c@syzkaller.appspotmail.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