From: Mikulas Patocka <mpatocka@redhat.com>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcachefs@vger.kernel.org, dm-devel@redhat.com,
linux-fsdevel@vger.kernel.org
Subject: fuzzing bcachefs with dm-flakey
Date: Mon, 29 May 2023 16:59:40 -0400 (EDT) [thread overview]
Message-ID: <alpine.LRH.2.21.2305260915400.12513@file01.intranet.prod.int.rdu2.redhat.com> (raw)
Hi
I improved the dm-flakey device mapper target, so that it can do random
corruption of read and write bios - I uploaded it here:
https://people.redhat.com/~mpatocka/testcases/bcachefs/dm-flakey.c
I set up dm-flakey, so that it corrupts 10% of read bios and 10% of write
bios with this command:
dmsetup create flakey --table "0 `blockdev --getsize /dev/ram0` flakey /dev/ram0 0 0 1 4 random_write_corrupt 100000000 random_read_corrupt 100000000"
I created a bcachefs volume on a single disk (metadata and data checksums
were turned off) and mounted it on dm-flakey. I got:
crash: https://people.redhat.com/~mpatocka/testcases/bcachefs/crash1.txt
deadlock: https://people.redhat.com/~mpatocka/testcases/bcachefs/crash2.txt
infinite loop: https://people.redhat.com/~mpatocka/testcases/bcachefs/crash3.txt
Here I uploaded an image that causes infnite loop when we run bcachefs
fsck on it or when we attempt mount it:
https://people.redhat.com/~mpatocka/testcases/bcachefs/inf-loop.gz
I tried to run bcachefs on two block devices and fuzzing just one of them
(checksums and replication were turned on - so bcachefs shold correct the
corrupted data) - in this scenario, bcachefs doesn't return invalid data,
but it sometimes returns errors and sometimes crashes.
This script will trigger an oops on unmount:
https://people.redhat.com/~mpatocka/testcases/bcachefs/crash4.txt
or nonsensical errors returned to userspace:
rm: cannot remove '/mnt/test/test/cmd_migrate.c': Unknown error 2206
or I/O errors returned to userspace:
diff: /mnt/test/test/rust-src/target/release/.fingerprint/bch_bindgen-f0bad16858ff0019/lib-bch_bindgen.json: Input/output error
#!/bin/sh -ex
umount /mnt/test || true
dmsetup remove_all || true
rmmod brd || true
SRC=/usr/src/git/bcachefs-tools
while true; do
modprobe brd rd_size=1048576
bcachefs format --replicas=2 /dev/ram0 /dev/ram1
dmsetup create flakey --table "0 `blockdev --getsize /dev/ram0` linear /dev/ram0 0"
mount -t bcachefs /dev/mapper/flakey:/dev/ram1 /mnt/test
dmsetup load flakey --table "0 `blockdev --getsize /dev/ram0` flakey /dev/ram0 0 0 1 4 random_write_corrupt 100000000 random_read_corrupt 100000000"
dmsetup suspend flakey
dmsetup resume flakey
cp -a "$SRC" /mnt/test/test
diff -r "$SRC" /mnt/test/test
echo 3 >/proc/sys/vm/drop_caches
diff -r "$SRC" /mnt/test/test
echo 3 >/proc/sys/vm/drop_caches
diff -r "$SRC" /mnt/test/test
echo 3 >/proc/sys/vm/drop_caches
rm -rf /mnt/test/test
echo 3 >/proc/sys/vm/drop_caches
cp -a "$SRC" /mnt/test/test
echo 3 >/proc/sys/vm/drop_caches
diff -r "$SRC" /mnt/test/test
umount /mnt/test
dmsetup remove flakey
rmmod brd
done
The oops happens in set_btree_iter_dontneed and it is caused by the fact
that iter->path is NULL. The code in try_alloc_bucket is buggy because it
sets "struct btree_iter iter = { NULL };" and then jumps to the "err"
label that tries to dereference values in "iter".
Bcachefs gives not much usefull error messages, like "Fatal error: Unknown
error 2184" or "Error in recovery: cannot allocate memory" or "mount(2)
system call failed: Unknown error 2186." or "rm: cannot remove
'/mnt/test/xfstests-dev/tools/fs-walk': Unknown error 2206".
Mikulas
next reply other threads:[~2023-05-29 21:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-29 20:59 Mikulas Patocka [this message]
2023-05-29 21:14 ` fuzzing bcachefs with dm-flakey Matthew Wilcox
2023-05-29 23:12 ` Dave Chinner
2023-05-29 23:51 ` Kent Overstreet
2023-05-30 12:23 ` Mikulas Patocka
2023-05-29 21:43 ` Kent Overstreet
2023-05-30 21:00 ` Mikulas Patocka
2023-05-30 23:29 ` Kent Overstreet
2023-06-09 20:57 ` Mikulas Patocka
2023-06-09 22:17 ` Kent Overstreet
2023-06-02 1:13 ` Darrick J. Wong
2023-06-09 18:56 ` Mikulas Patocka
2023-06-09 19:38 ` Darrick J. Wong
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=alpine.LRH.2.21.2305260915400.12513@file01.intranet.prod.int.rdu2.redhat.com \
--to=mpatocka@redhat.com \
--cc=dm-devel@redhat.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).