Skip to content

Commit adc77b1

Browse files
dmantipovakpm00
authored andcommitted
ocfs2: fix uninitialized value in ocfs2_file_read_iter()
Syzbot has reported the following KMSAN splat: BUG: KMSAN: uninit-value in ocfs2_file_read_iter+0x9a4/0xf80 ocfs2_file_read_iter+0x9a4/0xf80 __io_read+0x8d4/0x20f0 io_read+0x3e/0xf0 io_issue_sqe+0x42b/0x22c0 io_wq_submit_work+0xaf9/0xdc0 io_worker_handle_work+0xd13/0x2110 io_wq_worker+0x447/0x1410 ret_from_fork+0x6f/0x90 ret_from_fork_asm+0x1a/0x30 Uninit was created at: __alloc_pages_noprof+0x9a7/0xe00 alloc_pages_mpol_noprof+0x299/0x990 alloc_pages_noprof+0x1bf/0x1e0 allocate_slab+0x33a/0x1250 ___slab_alloc+0x12ef/0x35e0 kmem_cache_alloc_bulk_noprof+0x486/0x1330 __io_alloc_req_refill+0x84/0x560 io_submit_sqes+0x172f/0x2f30 __se_sys_io_uring_enter+0x406/0x41c0 __x64_sys_io_uring_enter+0x11f/0x1a0 x64_sys_call+0x2b54/0x3ba0 do_syscall_64+0xcd/0x1e0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Since an instance of 'struct kiocb' may be passed from the block layer with 'private' field uninitialized, introduce 'ocfs2_iocb_init_rw_locked()' and use it from where 'ocfs2_dio_end_io()' might take care, i.e. in 'ocfs2_file_read_iter()' and 'ocfs2_file_write_iter()'. Link: https://lkml.kernel.org/r/20241029091736.1501946-1-dmantipov@yandex.ru Fixes: 7cdfc3a ("ocfs2: Remember rw lock level during direct io") Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Reported-by: syzbot+a73e253cca4f0230a5a5@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=a73e253cca4f0230a5a5 Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Joseph Qi <jiangqi903@gmail.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 62bf706 commit adc77b1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

fs/ocfs2/aops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ enum ocfs2_iocb_lock_bits {
7070
OCFS2_IOCB_NUM_LOCKS
7171
};
7272

73+
#define ocfs2_iocb_init_rw_locked(iocb) \
74+
(iocb->private = NULL)
7375
#define ocfs2_iocb_clear_rw_locked(iocb) \
7476
clear_bit(OCFS2_IOCB_RW_LOCK, (unsigned long *)&iocb->private)
7577
#define ocfs2_iocb_rw_locked_level(iocb) \

fs/ocfs2/file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,8 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
23982398
} else
23992399
inode_lock(inode);
24002400

2401+
ocfs2_iocb_init_rw_locked(iocb);
2402+
24012403
/*
24022404
* Concurrent O_DIRECT writes are allowed with
24032405
* mount_option "coherency=buffered".
@@ -2544,6 +2546,8 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
25442546
if (!direct_io && nowait)
25452547
return -EOPNOTSUPP;
25462548

2549+
ocfs2_iocb_init_rw_locked(iocb);
2550+
25472551
/*
25482552
* buffered reads protect themselves in ->read_folio(). O_DIRECT reads
25492553
* need locks to protect pending reads from racing with truncate.

0 commit comments

Comments
 (0)