Re: [PATCH fstests] xfs/554: xfs add illegal bestfree array size inject for leaf dir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 02, 2022 at 05:40:46PM +0800, Guo Xuenan wrote:
> Test leaf dir allocting new block when bestfree array size
> less than data blocks count, which may lead to UAF.
> 
> Signed-off-by: Guo Xuenan <guoxuenan@xxxxxxxxxx>
> ---
>  tests/xfs/554     | 48 +++++++++++++++++++++++++++++++++++++++++++++++
>  tests/xfs/554.out |  6 ++++++
>  2 files changed, 54 insertions(+)
>  create mode 100755 tests/xfs/554
>  create mode 100644 tests/xfs/554.out
> 
> diff --git a/tests/xfs/554 b/tests/xfs/554
> new file mode 100755
> index 00000000..fcf45731
> --- /dev/null
> +++ b/tests/xfs/554
> @@ -0,0 +1,48 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2022 Huawei Limited.  All Rights Reserved.
> +#
> +# FS QA Test No. 554
> +#
> +# Test leaf dir bestfree array size match with dir disk size

Is it for a known bug? known commit id?

> +#
> +. ./common/preamble
> +_begin_fstest auto quick
> +
> +# Import common functions.
> +. ./common/populate
> +
> +# real QA test starts here
> +_supported_fs xfs
> +_require_scratch

Do you need V5 xfs? Or v4 is fine?
_require_scratch_xfs_crc ??

> +_require_check_dmesg
> +
> +echo "Format and mount"
> +_scratch_mkfs > $seqres.full 2>&1
> +_scratch_mount  >> $seqres.full 2>&1
> +
> +echo "Create and check leaf dir"
> +blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
> +dblksz="$($XFS_INFO_PROG "${SCRATCH_DEV}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"

Why do you need these two kinds of block size for xfs? And you sometimes
use the former, sometimes use the later? If you'd like to get the xfs data
block size, you can:

  _scratch_mkfs | _filter_mkfs >>$seqres.full 2>$tmp.mkfs
  . $tmp.mkfs

Then "dbsize" is what you want.

> +leaf_lblk="$((32 * 1073741824 / blksz))"
> +node_lblk="$((64 * 1073741824 / blksz))"

I didn't see the "node_lblk" is used in this case, looks like you don't want to
get directory node blocks in this case.

> +__populate_create_dir "${SCRATCH_MNT}/S_IFDIR.FMT_LEAF" "$((dblksz / 12))"
> +leaf_dir="$(__populate_find_inode "${SCRATCH_MNT}/S_IFDIR.FMT_LEAF")"
> +_scratch_unmount
> +__populate_check_xfs_dir "${leaf_dir}" "leaf"
> +
> +echo "Inject bad bestfress array size"
> +_scratch_xfs_db -x -c "inode ${leaf_dir}" -c "dblock 8388608" -c "write ltail.bestcount 0"

As you tried to detect xfs block size above, so it might not 4k block size, so
8388608 is not fixed.

According to the kernel definition:
  #define XFS_DIR2_DATA_ALIGN_LOG 3
  #define XFS_DIR2_SPACE_SIZE     (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
  #define XFS_DIR2_LEAF_SPACE     1
  #define XFS_DIR2_LEAF_OFFSET    (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)

The XFS_DIR2_LEAF_OFFSET = 1 * (1 << (32 + 3)) = 1<<35 = 34359738368 = 32GB, so
the fixed logical offset of leaf extent is 34359738368 bytes, then the offset
block number should be "34359738368 / dbsize". 8388608 is only for 4k block
size.

> +
> +echo "Test add entry to dir"
> +_scratch_mount
> +touch ${SCRATCH_MNT}/S_IFDIR.FMT_LEAF/{1..100}.txt > /dev/null 2>&1
> +_scratch_unmount 2>&1
> +_repair_scratch_fs >> $seqres.full 2>&1

Can you explain more about this testing steps? The xfs has been corrupted, then
we expect is can be mounted. And create 100 new files on that corrupted dir,
do you expect the 100 files can be created successfully? Or what ever, even
nothing be created?

What's the xfs_repair expect? Fix all curruption and left a clean xfs?

> +
> +# check demsg error
> +_check_dmesg

Which above step will trigger a dmesg you want to check? What kind of dmesg do
you want to check? I think xfstests checks dmesg at the end of each test case,
except you need to check some special one, or need a special filter?

Thanks,
Zorro

> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/xfs/554.out b/tests/xfs/554.out
> new file mode 100644
> index 00000000..ea1f30cc
> --- /dev/null
> +++ b/tests/xfs/554.out
> @@ -0,0 +1,6 @@
> +QA output created by 554
> +Format and mount
> +Create and check leaf dir
> +Inject bad bestfress array size
> +ltail.bestcount = 0
> +Test add entry to dir
> -- 
> 2.25.1
> 




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux