linux/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 nilfs2: fix missing initial short descriptions of kernel-doc comments 2024-09-01 20:43:37 -07:00
bmap.h nilfs2: use the BITS_PER_LONG macro 2024-09-01 20:43:42 -07:00
btnode.c nilfs2: fix null-ptr-deref in block_dirty_buffer tracepoint 2024-11-11 17:20:23 -08:00
btnode.h fs/nilfs2: Use the enum req_op and blk_opf_t types 2022-07-14 12:14:33 -06:00
btree.c nilfs2: fix potential oob read in nilfs_btree_check_delete() 2024-09-09 16:47:42 -07:00
btree.h nilfs2: add missing description of nilfs_btree_path structure 2024-09-01 20:43:36 -07:00
cpfile.c nilfs2: convert checkpoint file to be folio-based 2024-11-05 17:12:39 -08:00
cpfile.h nilfs2: remove nilfs_cpfile_{get,put}_checkpoint() 2024-02-22 15:38:53 -08:00
dat.c nilfs2: convert DAT file to be folio-based 2024-11-05 17:12:38 -08:00
dat.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
dir.c nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry() 2024-12-05 19:54:43 -08:00
direct.c nilfs2: fix failure to detect DAT corruption in btree and direct mappings 2024-03-14 09:17:29 -07:00
direct.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
export.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() 2024-02-07 21:20:36 -08:00
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 nilfs2: add missing argument descriptions for ioctl-related helpers 2024-09-01 20:43:35 -07:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdt.c - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
mdt.h nilfs2: fix lockdep warnings during disk space reclamation 2022-04-01 11:46:09 -07:00
namei.c nilfs2: fix potential deadlock with newly created symlinks 2024-10-30 20:14:12 -07:00
nilfs.h nilfs2: propagate directory read errors from nilfs_find_entry() 2024-10-17 00:28:06 -07:00
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 nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
segment.c Many singleton patches - please see the various changelogs for details. 2024-09-21 08:20:50 -07:00
segment.h nilfs2: use kthread_create and kthread_stop for the log writer thread 2024-09-01 20:43:44 -07:00
sufile.c nilfs2: convert segment usage file to be folio-based 2024-11-05 17:12:38 -08:00
sufile.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
super.c nilfs2: separate inode type information from i_state field 2024-09-01 20:43:43 -07:00
sysfs.c nilfs2: protect references to superblock parameters exposed in sysfs 2024-09-01 17:59:00 -07:00
sysfs.h nilfs2: remove filenames from file comments 2021-11-09 10:02:52 -08:00
the_nilfs.c nilfs2: eliminate the shared counter and spinlock for i_generation 2024-09-01 20:43:43 -07:00
the_nilfs.h nilfs2: eliminate the shared counter and spinlock for i_generation 2024-09-01 20:43:43 -07:00