aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaokun Li <libaokun1@huawei.com>2023-11-24 19:53:56 +0800
committerZorro Lang <zlang@kernel.org>2023-12-10 21:38:00 +0800
commitb05c808ce4a4686b40c4e0b5029cb889c39f3856 (patch)
tree05dc88745f4e295d1c92b8eec544523492cb027f
parentc71b4e6203752cb4c54b5ae63f5197076070726b (diff)
downloadxfstests-dev-b05c808ce4a4686b40c4e0b5029cb889c39f3856.tar.gz
generic: regression test of ext4_lblk_t overflow
Append writes to a file with logical block numbers close to 0xffffffff and observe if a kernel crash is caused by ext4_lblk_t overflow triggering BUG_ON at ext4_mb_new_inode_pa(). This is a regression test for commit bc056e7163ac ("ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow") Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Zorro Lang <zlang@redhat.com> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Zorro Lang <zlang@kernel.org>
-rwxr-xr-xtests/generic/73554
-rw-r--r--tests/generic/735.out2
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/generic/735 b/tests/generic/735
new file mode 100755
index 0000000000..44b454771d
--- /dev/null
+++ b/tests/generic/735
@@ -0,0 +1,54 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 HUAWEI. All Rights Reserved.
+#
+# FS QA Test No. 735
+#
+# Append writes to a file with logical block numbers close to 0xffffffff
+# and observe if a kernel crash is caused by ext4_lblk_t overflow triggering
+# BUG_ON at ext4_mb_new_inode_pa(). This is a regression test for commit
+# bc056e7163ac ("ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow")
+#
+. ./common/preamble
+. ./common/populate
+_begin_fstest auto quick insert prealloc
+
+# real QA test starts here
+[[ "$FSTYP" =~ ext[0-9]+ ]] && _fixed_by_kernel_commit bc056e7163ac \
+ "ext4: fix BUG in ext4_mb_new_inode_pa() due to overflow"
+
+_require_odirect
+_require_xfs_io_command "falloc"
+_require_xfs_io_command "finsert"
+
+dev_size=$((80 * 1024 * 1024))
+_scratch_mkfs_sized $dev_size >>$seqres.full 2>&1 || _fail "mkfs failed"
+
+_scratch_mount
+file_blksz="$(_get_file_block_size ${SCRATCH_MNT})"
+
+# Reserve 1M space
+$XFS_IO_PROG -f -c "falloc 0 1M" "${SCRATCH_MNT}/tmp" >> $seqres.full
+
+# Create a file with logical block numbers close to 0xffffffff
+$XFS_IO_PROG -f -c "falloc 0 10M" "${SCRATCH_MNT}/file" >> $seqres.full
+max_pos=$(( 0xffffffff * file_blksz ))
+finsert_len=$(( max_pos - ((10 + 2) << 20) ))
+$XFS_IO_PROG -f -c "finsert 1M ${finsert_len}" "${SCRATCH_MNT}/file" >> $seqres.full
+
+# Filling up the free space ensures that the pre-allocated space is the reserved space.
+nr_free=$(stat -f -c '%f' ${SCRATCH_MNT})
+_fill_fs $((nr_free * file_blksz)) ${SCRATCH_MNT}/fill $file_blksz 0 >> $seqres.full 2>&1
+sync
+
+# Remove reserved space to gain free space for allocation
+rm -f ${SCRATCH_MNT}/tmp
+
+# Trying to allocate two blocks triggers BUG_ON.
+$XFS_IO_PROG -c "open -ad ${SCRATCH_MNT}/file" -c "pwrite -S 0xff 0 $((2 * file_blksz))" >> $seqres.full
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/735.out b/tests/generic/735.out
new file mode 100644
index 0000000000..92df092c05
--- /dev/null
+++ b/tests/generic/735.out
@@ -0,0 +1,2 @@
+QA output created by 735
+Silence is golden