* [PATCH] befs: fix indirect index in double-indirect mapper
@ 2026-11-28 11:15 shaos
0 siblings, 0 replies; only message in thread
From: shaos @ 2026-11-28 11:15 UTC (permalink / raw)
To: luisbg, salah.triki; +Cc: linux-kernel, stable
Hello,
befs_find_brun_dblindirect() computes the index within the indirect
block as dblindir_leftover / diblklen. Since dblindir_leftover is the
remainder modulo diblklen, that quotient is always zero. The divisor
must be iblklen, the number of file blocks described by one indirect
entry.
With a valid-layout image whose direct and indirect ranges are both
non-empty, reads from the second data run in the double-indirect range
return data from the first run plus the logical offset. The PoC reads
file blocks 6 and 7 as WRONG_BLOCK_024 and WRONG_BLOCK_025; the correct
blocks contain RUN1_BLOCK_200 and RUN1_BLOCK_201.
The trigger requires a crafted BeFS image to be mounted from a block
device, which requires mount privilege. The reproducer mounts the
image read-only and reads a regular file. It demonstrates incorrect
file contents; it does not demonstrate a panic, memory disclosure, or
privilege escalation.
HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: v7.3-23088-g8d7fe9885c62f (Linux 7.4.0-rc4)
compiler: gcc 11.4.0, GNU ld 2.38
Console output:
https://gist.githubusercontent.com/shaos26/6be5e0efeaa44a6715bdba598ca6c2f6/raw/c1fcaab9327372c7021788ebfcdddac66810cb26/console-output.txt
Kernel config:
https://gist.githubusercontent.com/shaos26/6be5e0efeaa44a6715bdba598ca6c2f6/raw/c1fcaab9327372c7021788ebfcdddac66810cb26/kernel-config.txt
PoC:
https://gist.githubusercontent.com/shaos26/6be5e0efeaa44a6715bdba598ca6c2f6/raw/c1fcaab9327372c7021788ebfcdddac66810cb26/poc.c
Image builder:
https://gist.githubusercontent.com/shaos26/6be5e0efeaa44a6715bdba598ca6c2f6/raw/c1fcaab9327372c7021788ebfcdddac66810cb26/make_befs_image.py
Build the kernel from the revision above using kernel-config.txt:
work=$(mktemp -d /tmp/befs-dblindir.XXXXXX)
cd "$work"
gist_id=6be5e0efeaa44a6715bdba598ca6c2f6
gist_revision=c1fcaab9327372c7021788ebfcdddac66810cb26
gist_base=https://gist.githubusercontent.com/shaos26
gist=$gist_base/$gist_id/raw/$gist_revision
for file in console-output.txt kernel-config.txt poc.c \
make_befs_image.py; do
curl -fL "$gist/$file" -o "$file"
done
git clone \
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
git checkout 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
mkdir build
cp ../kernel-config.txt build/.config
make O=build olddefconfig
make O=build -j"$(nproc)" bzImage
cd ..
Build the image and initramfs:
gcc -O2 -static -Wall -Wextra -o poc poc.c
python3 make_befs_image.py befs.img
mkdir -p root/dev root/mnt
cp poc root/init
(cd root && find . -print0 | cpio --null -o -H newc) | \
gzip -9 > initramfs.cpio.gz
Run the positive case with the image attached read-only:
timeout 30 qemu-system-x86_64 -machine pc,accel=tcg -cpu max \
-m 1024M -smp 2 -display none -monitor none -serial stdio \
-no-reboot -kernel linux/build/arch/x86/boot/bzImage \
-initrd initramfs.cpio.gz \
-append 'console=ttyS0 rdinit=/init panic=-1 loglevel=7' \
-drive file=befs.img,if=virtio,format=raw,readonly=on
The unfixed kernel reads WRONG_BLOCK_024 and WRONG_BLOCK_025 for file
blocks 6 and 7. The same image and initramfs on the fixed kernel read
RUN1_BLOCK_200 and RUN1_BLOCK_201. Blocks in the direct range, the
first indirect range, and the first double-indirect run match on both
kernels.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: shaos <shawnq1@163.com>
Thanks,
shaos
---
fs/befs/datastream.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/befs/datastream.c b/fs/befs/datastream.c
index 4f5825a336f1c..9f610e775321a 100644
--- a/fs/befs/datastream.c
+++ b/fs/befs/datastream.c
@@ -456,7 +456,7 @@ befs_find_brun_dblindirect(struct super_block *sb,
dblindir_indx = dbl_indir_off / diblklen;
dblindir_leftover = dbl_indir_off % diblklen;
- indir_indx = dblindir_leftover / diblklen;
+ indir_indx = dblindir_leftover / iblklen;
/* Read double indirect block */
dbl_which_block = dblindir_indx / befs_iaddrs_per_block(sb);
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-28 11:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 11:15 [PATCH] befs: fix indirect index in double-indirect mapper shaos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®