From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Gao Xiang <hsiangkao@redhat.com>
Cc: linux-xfs@vger.kernel.org, Dennis Gilmore <dgilmore@redhat.com>,
Christoph Hellwig <hch@lst.de>, Eric Sandeen <sandeen@redhat.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v3] xfs: fix forkoff miscalculation related to XFS_LITINO(mp)
Date: Sat, 14 Nov 2020 11:06:42 -0800 [thread overview]
Message-ID: <20201114190642.GQ9695@magnolia> (raw)
In-Reply-To: <20201114140234.1154690-1-hsiangkao@redhat.com>
On Sat, Nov 14, 2020 at 10:02:34PM +0800, Gao Xiang wrote:
> Currently, commit e9e2eae89ddb dropped a (int) decoration from
> XFS_LITINO(mp), and since sizeof() expression is also involved,
> the result of XFS_LITINO(mp) is simply as the size_t type
> (commonly unsigned long).
>
> Considering the expression in xfs_attr_shortform_bytesfit():
> offset = (XFS_LITINO(mp) - bytes) >> 3;
> let "bytes" be (int)340, and
> "XFS_LITINO(mp)" be (unsigned long)336.
>
> on 64-bit platform, the expression is
> offset = ((unsigned long)336 - (int)340) >> 3 =
> (int)(0xfffffffffffffffcUL >> 3) = -1
>
> but on 32-bit platform, the expression is
> offset = ((unsigned long)336 - (int)340) >> 3 =
> (int)(0xfffffffcUL >> 3) = 0x1fffffff
> instead.
>
> so offset becomes a large positive number on 32-bit platform, and
> cause xfs_attr_shortform_bytesfit() returns maxforkoff rather than 0.
>
> Therefore, one result is
> "ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));"
>
> assertion failure in xfs_idata_realloc(), which was also the root
> cause of the original bugreport from Dennis, see:
> https://bugzilla.redhat.com/show_bug.cgi?id=1894177
>
> And it can also be manually triggered with the following commands:
> $ touch a;
> $ setfattr -n user.0 -v "`seq 0 80`" a;
> $ setfattr -n user.1 -v "`seq 0 80`" a
>
> on 32-bit platform.
>
> Fix the case in xfs_attr_shortform_bytesfit() by bailing out
> "XFS_LITINO(mp) < bytes" in advance suggested by Eric and a misleading
> comment together with this bugfix suggested by Darrick. It seems the
> other users of XFS_LITINO(mp) are not impacted.
>
> Fixes: e9e2eae89ddb ("xfs: only check the superblock version for dinode size calculation")
> Cc: <stable@vger.kernel.org> # 5.7+
> Reported-and-tested-by: Dennis Gilmore <dgilmore@redhat.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Looks good to me,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
> changes since v2:
> - collect more tags from the replies of v2;
> - refine a comment suggested by Christoph.
>
> fs/xfs/libxfs/xfs_attr_leaf.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index bb128db220ac..d6ef69ab1c67 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -515,7 +515,7 @@ xfs_attr_copy_value(
> *========================================================================*/
>
> /*
> - * Query whether the requested number of additional bytes of extended
> + * Query whether the total requested number of attr fork bytes of extended
> * attribute space will be able to fit inline.
> *
> * Returns zero if not, else the di_forkoff fork offset to be used in the
> @@ -535,6 +535,12 @@ xfs_attr_shortform_bytesfit(
> int maxforkoff;
> int offset;
>
> + /*
> + * Check if the new size could fit at all first:
> + */
> + if (bytes > XFS_LITINO(mp))
> + return 0;
> +
> /* rounded down */
> offset = (XFS_LITINO(mp) - bytes) >> 3;
>
> --
> 2.18.4
>
prev parent reply other threads:[~2020-11-14 19:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 6:30 [PATCH] xfs: fix signed calculation related to XFS_LITINO(mp) Gao Xiang
2020-11-12 15:53 ` Eric Sandeen
2020-11-12 18:30 ` Darrick J. Wong
2020-11-13 2:04 ` Gao Xiang
2020-11-13 2:12 ` Gao Xiang
2020-11-13 1:50 ` [PATCH v2] xfs: fix forkoff miscalculation " Gao Xiang
2020-11-13 15:31 ` Dennis Gilmore
2020-11-14 10:32 ` Christoph Hellwig
2020-11-14 13:49 ` Gao Xiang
2020-11-14 14:02 ` [PATCH v3] " Gao Xiang
2020-11-14 19:06 ` Darrick J. Wong [this message]
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=20201114190642.GQ9695@magnolia \
--to=darrick.wong@oracle.com \
--cc=dgilmore@redhat.com \
--cc=hch@lst.de \
--cc=hsiangkao@redhat.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=stable@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