]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
block: Fix iterating over an empty bio with bio_for_each_folio_all
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 16 Jan 2024 21:29:59 +0000 (21:29 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 23:27:42 +0000 (15:27 -0800)
commitc6350b5cb78e9024c49eaee6fdb914ad2903a5fe
tree5dc953d14a6df693b273621c0c523c174770883c
parentef31cc87794731ffcb578a195a2c47d744e25fb8
block: Fix iterating over an empty bio with bio_for_each_folio_all

commit 7bed6f3d08b7af27b7015da8dc3acf2b9c1f21d7 upstream.

If the bio contains no data, bio_first_folio() calls page_folio() on a
NULL pointer and oopses.  Move the test that we've reached the end of
the bio from bio_next_folio() to bio_first_folio().

Reported-by: syzbot+8b23309d5788a79d3eea@syzkaller.appspotmail.com
Reported-by: syzbot+004c1e0fced2b4bc3dcc@syzkaller.appspotmail.com
Fixes: 640d1930bef4 ("block: Add bio_for_each_folio_all()")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/r/20240116212959.3413014-1-willy@infradead.org
[axboe: add unlikely() to error case]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/bio.h