linux-mainline/fs/nilfs2
Ryusuke Konishi 985ebec4ab nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry()
Syzbot reported that when searching for records in a directory where the
inode's i_size is corrupted and has a large value, memory access outside
the folio/page range may occur, or a use-after-free bug may be detected if
KASAN is enabled.

This is because nilfs_last_byte(), which is called by nilfs_find_entry()
and others to calculate the number of valid bytes of directory data in a
page from i_size and the page index, loses the upper 32 bits of the 64-bit
size information due to an inappropriate type of local variable to which
the i_size value is assigned.

This caused a large byte offset value due to underflow in the end address
calculation in the calling nilfs_find_entry(), resulting in memory access
that exceeds the folio/page size.

Fix this issue by changing the type of the local variable causing the bit
loss from "unsigned int" to "u64".  The return value of nilfs_last_byte()
is also of type "unsigned int", but it is truncated so as not to exceed
PAGE_SIZE and no bit loss occurs, so no change is required.

Link: https://lkml.kernel.org/r/20241119172403.9292-1-konishi.ryusuke@gmail.com
Fixes: 2ba466d74e ("nilfs2: directory entry operations")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+96d5d14c47d97015c624@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=96d5d14c47d97015c624
Tested-by: syzbot+96d5d14c47d97015c624@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-12-05 19:54:43 -08:00
..
alloc.c nilfs2: remove nilfs_palloc_block_get_entry() 2024-11-05 17:12:39 -08:00
alloc.h nilfs2: remove nilfs_palloc_block_get_entry() 2024-11-05 17:12:39 -08:00
bmap.c
bmap.h
btnode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-11-11 17:20:23 -08:00
btnode.h
btree.c
btree.h
cpfile.c nilfs2: convert checkpoint file to be folio-based 2024-11-05 17:12:39 -08:00
cpfile.h
dat.c nilfs2: convert DAT file to be folio-based 2024-11-05 17:12:38 -08:00
dat.h
dir.c nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry() 2024-12-05 19:54:43 -08:00
direct.c
direct.h
export.h
file.c
gcinode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-11-11 17:20:23 -08:00
ifile.c nilfs2: convert inode file to be folio-based 2024-11-05 17:12:38 -08:00
ifile.h nilfs2: convert inode file to be folio-based 2024-11-05 17:12:38 -08:00
inode.c nilfs2: convert nilfs_page_count_clean_buffers() to take a folio 2024-11-05 17:12:39 -08:00
ioctl.c
Kconfig
Makefile
mdt.c - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
mdt.h
namei.c nilfs2: fix potential deadlock with newly created symlinks 2024-10-30 20:14:12 -07:00
nilfs.h
page.c - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
page.h nilfs2: convert nilfs_page_count_clean_buffers() to take a folio 2024-11-05 17:12:39 -08:00
recovery.c nilfs2: convert nilfs_recovery_copy_block() to take a folio 2024-11-05 17:12:40 -08:00
segbuf.c nilfs2: convert segment buffer to be folio-based 2024-11-05 17:12:37 -08:00
segbuf.h
segment.c
segment.h
sufile.c nilfs2: convert segment usage file to be folio-based 2024-11-05 17:12:38 -08:00
sufile.h
super.c
sysfs.c
sysfs.h
the_nilfs.c
the_nilfs.h