In the Linux kernel, the following vulnerability has been resolved:
f2fs: fix to do sanity check on node blkaddr in truncate_node()
syzbot reports a f2fs bug as below:
------------[ cut here ]------------ kernel BUG at fs/f2fs/segment.c:2534! RIP: 0010:f2fsinvalidateblocks+0x35f/0x370 fs/f2fs/segment.c:2534 Call Trace: truncatenode+0x1ae/0x8c0 fs/f2fs/node.c:909 f2fsremoveinodepage+0x5c2/0x870 fs/f2fs/node.c:1288 f2fsevictinode+0x879/0x15c0 fs/f2fs/inode.c:856 evict+0x4e8/0x9b0 fs/inode.c:723 f2fshandlefailedinode+0x271/0x2e0 fs/f2fs/inode.c:986 f2fscreate+0x357/0x530 fs/f2fs/namei.c:394 lookupopen fs/namei.c:3595 [inline] openlastlookups fs/namei.c:3694 [inline] pathopenat+0x1c03/0x3590 fs/namei.c:3930 dofilpopen+0x235/0x490 fs/namei.c:3960 dosysopenat2+0x13e/0x1d0 fs/open.c:1415 dosysopen fs/open.c:1430 [inline] _dosysopenat fs/open.c:1446 [inline] _sesysopenat fs/open.c:1441 [inline] _x64sysopenat+0x247/0x2a0 fs/open.c:1441 dosyscallx64 arch/x86/entry/common.c:52 [inline] dosyscall64+0xf3/0x230 arch/x86/entry/common.c:83 entrySYSCALL64afterhwframe+0x77/0x7f RIP: 0010:f2fsinvalidate_blocks+0x35f/0x370 fs/f2fs/segment.c:2534
The root cause is: on a fuzzed image, blkaddr in nat entry may be corrupted, then it will cause system panic when using it in f2fsinvalidateblocks(), to avoid this, let's add sanity check on nat blkaddr in truncate_node().