* [PATCH 5.4 CANDIDATE] xfs: fix forkoff miscalculation related to XFS_LITINO(mp)
@ 2023-04-21 3:06 Chandan Babu R
2023-04-21 15:35 ` Darrick J. Wong
0 siblings, 1 reply; 2+ messages in thread
From: Chandan Babu R @ 2023-04-21 3:06 UTC (permalink / raw)
To: djwong; +Cc: chandan.babu, linux-xfs, amir73il, leah.rumancik
From: Gao Xiang <hsiangkao@redhat.com>
commit ada49d64fb3538144192181db05de17e2ffc3551 upstream.
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>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
---
Hi Darrick,
I had missed this commit when backporting fixes from 5.11 and 5.12. I
have executed 10 iterations of fstests via kdevops and did not notice
any new regressions.
Please ack this patch.
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 f5b16120c64d..2b74b6e9a354 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -435,7 +435,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
@@ -455,6 +455,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.39.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 5.4 CANDIDATE] xfs: fix forkoff miscalculation related to XFS_LITINO(mp)
2023-04-21 3:06 [PATCH 5.4 CANDIDATE] xfs: fix forkoff miscalculation related to XFS_LITINO(mp) Chandan Babu R
@ 2023-04-21 15:35 ` Darrick J. Wong
0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2023-04-21 15:35 UTC (permalink / raw)
To: Chandan Babu R; +Cc: linux-xfs, amir73il, leah.rumancik
On Fri, Apr 21, 2023 at 08:36:19AM +0530, Chandan Babu R wrote:
> From: Gao Xiang <hsiangkao@redhat.com>
>
> commit ada49d64fb3538144192181db05de17e2ffc3551 upstream.
>
> 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>
> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Looks good to me,
Acked-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
>
> Hi Darrick,
>
> I had missed this commit when backporting fixes from 5.11 and 5.12. I
> have executed 10 iterations of fstests via kdevops and did not notice
> any new regressions.
>
> Please ack this patch.
>
> 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 f5b16120c64d..2b74b6e9a354 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -435,7 +435,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
> @@ -455,6 +455,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.39.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-21 15:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-21 3:06 [PATCH 5.4 CANDIDATE] xfs: fix forkoff miscalculation related to XFS_LITINO(mp) Chandan Babu R
2023-04-21 15:35 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox