xfs: fix wrong compat fields in xfs_ioctl32_bstat_copyin()
Subsystems (2)
PATCH v2 1/1 xfs: fix wrong compat fields in xfs_ioctl32_bstat_copyin()
bs_blocks and bs_xflags were both read from bstat32->bs_size. Read each one from its own field instead.
---
v2:
- Also fix bs_blocks (spotted by Eric Sandeen)
fs/xfs/xfs_ioctl32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_ioctl32.c +2 -2
@@ -143,8 +143,8 @@ xfs_ioctl32_bstat_copyin(xfs_ioctl32_bstime_copyin (&bstat->bs_atime, &bstat32->bs_atime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_mtime, &bstat32->bs_mtime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_ctime, &bstat32->bs_ctime) || -get_user (bstat->bs_blocks, &bstat32->bs_size) || -get_user (bstat->bs_xflags, &bstat32->bs_size) || +get_user (bstat->bs_blocks, &bstat32->bs_blocks) || +get_user (bstat->bs_xflags, &bstat32->bs_xflags) ||get_user (bstat->bs_extsize, &bstat32->bs_extsize) ||get_user (bstat->bs_extents, &bstat32->bs_extents) || get_user(bstat->bs_gen, &bstat32->bs_gen) ||
Signature · 1 line
2.53.0
Quoted 2 lines · On Tue, 27 Oct 2026 12:17:48 -0400 Reid Downing <[email protected]> wrote:
bs_blocksandbs_xflagswere both read frombstat32->bs_size. Read each one from its own field instead.
It would be much better to do a single copy_from_user() of the entire compat structure and copy the fields to the standard one.
The function would need to be 'noinline_for_stack'.
David
Quoted 26 lines
Fixes e94fc4a43e5c39 ("[XFS] Add compat handlers for swapext ioctl")Cc <[email protected]> # v2.6.29Signed-off-by Reid Downing <[email protected]>---
v2:
- Also fixbs_blocks(spotted by Eric Sandeen)fs/xfs/xfs_ioctl32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/xfs/xfs_ioctl32.c +2
-2@@ -143,8 +143,8 @@ xfs_ioctl32_bstat_copyin(xfs_ioctl32_bstime_copyin (&bstat->bs_atime, &bstat32->bs_atime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_mtime, &bstat32->bs_mtime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_ctime, &bstat32->bs_ctime) || -get_user (bstat->bs_blocks, &bstat32->bs_size) || -get_user (bstat->bs_xflags, &bstat32->bs_size) || +get_user (bstat->bs_blocks, &bstat32->bs_blocks) || +get_user (bstat->bs_xflags, &bstat32->bs_xflags) ||get_user (bstat->bs_extsize, &bstat32->bs_extsize) ||get_user (bstat->bs_extents, &bstat32->bs_extents) || get_user(bstat->bs_gen, &bstat32->bs_gen) ||
Quoted 10 lines · David Laight
Quoted 2 lines · On Tue, 27 Oct 2026 12:17:48 -0400 Reid Downing <[email protected]> wrote:
bs_blocksandbs_xflagswere both read frombstat32->bs_size. Read each one from its own field instead.It would be much better to do a single
copy_from_user()of the entire compat structure and copy the fields to the standard one.The function would need to be '
noinline_for_stack'.
I'm leaning that way too, but I think the simple, direct fix for the current code makes sense to merge first, then evaluate better options for all this.
Thanks,
-Eric
Quoted 30 lines
David
Quoted 26 lines
Fixes e94fc4a43e5c39 ("[XFS] Add compat handlers for swapext ioctl")Cc <[email protected]> # v2.6.29Signed-off-by Reid Downing <[email protected]>---
v2:
- Also fixbs_blocks(spotted by Eric Sandeen)fs/xfs/xfs_ioctl32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/xfs/xfs_ioctl32.c +2
-2@@ -143,8 +143,8 @@ xfs_ioctl32_bstat_copyin(xfs_ioctl32_bstime_copyin (&bstat->bs_atime, &bstat32->bs_atime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_mtime, &bstat32->bs_mtime) ||xfs_ioctl32_bstime_copyin (&bstat->bs_ctime, &bstat32->bs_ctime) || -get_user (bstat->bs_blocks, &bstat32->bs_size) || -get_user (bstat->bs_xflags, &bstat32->bs_size) || +get_user (bstat->bs_blocks, &bstat32->bs_blocks) || +get_user (bstat->bs_xflags, &bstat32->bs_xflags) ||get_user (bstat->bs_extsize, &bstat32->bs_extsize) ||get_user (bstat->bs_extents, &bstat32->bs_extents) || get_user(bstat->bs_gen, &bstat32->bs_gen) ||
Quoted 8 lines · David Laight
Quoted 2 lines · On Tue, 27 Oct 2026 12:17:48 -0400 Reid Downing <[email protected]> wrote:
bs_blocksandbs_xflagswere both read frombstat32->bs_size. Read each one from its own field instead.It would be much better to do a single
copy_from_user()of the entire compat structure and copy the fields to the standard one.
Care to explain why it would be "much better" to do two copies instead of one? The only benefits from copy_from/to_user over the current get_put/user is avoidind the conctant user access disabling/enabling, but the scoped uaccess thing would do the same.
Quoted 7 lines · On Wed, 28 Oct 2026 08:18:40 -0700 Christoph Hellwig <[email protected]> wrote:
Quoted 6 lines · David Laight
Quoted 2 lines · On Tue, 27 Oct 2026 12:17:48 -0400 Reid Downing <[email protected]> wrote:
bs_blocksandbs_xflagswere both read frombstat32->bs_size. Read each one from its own field instead.
Quoted 6 lines
Quoted 2 lines
It would be much better to do a single
copy_from_user()of the entire compat structure and copy the fields to the standard one.Care to explain why it would be "much better" to do two copies instead of one? The only benefits from copy_from/to_user over the current get_put/user is avoidind the conctant user access disabling/enabling,
That is a massive hit.
The current code also has all the conditionals from access_ok().
Quoted 1 line
but the scoped uaccess thing would do the same.
True, but unnecessarily 'technical' for this bit of code. You also save all the exception table entries - so the code size would be rather smaller.
David
Hi David, Eric, Carlos,
Thank you all for the careful review, and Eric, thanks for catching the second line.
I looked at the refactor David suggested and Eric sketched, and I agree it is the better way to write this function. I'm not confident enough in the 32-bit compat code to send it myself, and I only want to send changes I can fully vouch for. If the refactor should go in, I'd be glad to see it done.
Reid
Quoted 10 lines · Reid Downing
Hi David, Eric, Carlos,
Thank you all for the careful review, and Eric, thanks for catching the second line.
I looked at the refactor David suggested and Eric sketched, and I agree it is the better way to write this function. I'm not confident enough in the 32-bit compat code to send it myself, and I only want to send changes I can fully vouch for. If the refactor should go in, I'd be glad to see it done.
Might be, but that's a subject for another patch, not this one.
For this one:
Quoted 2 lines
Reid
Quoted 4 lines · Reid Downing
bs_blocksandbs_xflagswere both read frombstat32->bs_size. Read each one from its own field instead.
Applied to for-next, thanks!
[1/1] xfs: fix wrong compat fields in xfs_ioctl32_bstat_copyin()
commit: b7eb276a39b14e685c2fe578f8ac22fc48ff9e6c
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>