From: Dave Chinner <david@fromorbit.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org, allison.henderson@oracle.com
Subject: Re: [PATCH 3/4] xfs: share xattr name and value buffers when logging xattr updates
Date: Mon, 23 May 2022 15:59:34 +1000 [thread overview]
Message-ID: <20220523055934.GS1098723@dread.disaster.area> (raw)
In-Reply-To: <165323328378.78754.13988952314410368815.stgit@magnolia>
On Sun, May 22, 2022 at 08:28:03AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> While running xfs/297 and generic/642, I noticed a crash in
> xfs_attri_item_relog when it tries to copy the attr name to the new
> xattri log item. I think what happened here was that we called
> ->iop_commit on the old attri item (which nulls out the pointers) as
> part of a log force at the same time that a chained attr operation was
> ongoing. The system was busy enough that at some later point, the defer
> ops operation decided it was necessary to relog the attri log item, but
> as we've detached the name buffer from the old attri log item, we can't
> copy it to the new one, and kaboom.
>
> I think there's a broader refcounting problem with LARP mode -- the
> setxattr code can return to userspace before the CIL actually formats
> and commits the log item, which results in a UAF bug. Therefore, the
> xattr log item needs to be able to retain a reference to the name and
> value buffers until the log items have completely cleared the log.
> Furthermore, each time we create an intent log item, we allocate new
> memory and (re)copy the contents; sharing here would be very useful.
>
> Solve the UAF and the unnecessary memory allocations by having the log
> code create a single refcounted buffer to contain the name and value
> contents. This buffer can be passed from old to new during a relog
> operation, and the logging code can (optionally) attach it to the
> xfs_attr_item for reuse when LARP mode is enabled.
>
> This also fixes a problem where the xfs_attri_log_item objects weren't
> being freed back to the same cache where they came from.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> fs/xfs/libxfs/xfs_attr.h | 8 +
> fs/xfs/xfs_attr_item.c | 271 ++++++++++++++++++++++++++--------------------
> fs/xfs/xfs_attr_item.h | 13 ++
> fs/xfs/xfs_log.h | 7 +
> 4 files changed, 178 insertions(+), 121 deletions(-)
Lots neater!
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Thanks!
-Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2022-05-23 5:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-22 15:27 [PATCHSET 0/4] xfs: last bit of LARP and other fixes for 5.19 Darrick J. Wong
2022-05-22 15:27 ` [PATCH 1/4] xfs: purge dquots after inode walk fails during quotacheck Darrick J. Wong
2022-05-22 15:27 ` [PATCH 2/4] xfs: do not use logged xattr updates on V4 filesystems Darrick J. Wong
2022-05-23 5:51 ` Dave Chinner
2022-05-22 15:28 ` [PATCH 3/4] xfs: share xattr name and value buffers when logging xattr updates Darrick J. Wong
2022-05-23 5:59 ` Dave Chinner [this message]
2022-05-22 15:28 ` [PATCH 4/4] xfs: allow ->create_intent to return negative errnos Darrick J. Wong
2022-05-22 22:59 ` [PATCHSET 0/4] xfs: last bit of LARP and other fixes for 5.19 Dave Chinner
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=20220523055934.GS1098723@dread.disaster.area \
--to=david@fromorbit.com \
--cc=allison.henderson@oracle.com \
--cc=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/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