On Fri, Dec 15, 2023 at 09:20:22PM -0800, syzbot wrote: > Hello, > > syzbot found the following issue on: Good bot. > commit 1b151e2435fc3a9b10c8946c6aebe9f3e1938c55 > Author: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> > Date: Mon Aug 14 14:41:00 2023 +0000 > > block: Remove special-casing of compound pages > > bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=152f8a8ee80000 > final oops: https://syzkaller.appspot.com/x/report.txt?x=172f8a8ee80000 > console output: https://syzkaller.appspot.com/x/log.txt?x=132f8a8ee80000 > > general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN > KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] I _think_ what's happened here is that __bio_release_pages() was called with a zero-length bio. > CPU: 0 PID: 5059 Comm: syz-executor696 Not tainted 6.7.0-rc5-next-20231212-syzkaller #0 > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/10/2023 > RIP: 0010:_compound_head include/linux/page-flags.h:247 [inline] > RIP: 0010:bio_first_folio+0xcb/0x5c0 include/linux/bio.h:289 ... bio_first_folio() doesn't handle it well, whereas bio_for_each_segment_all() did. > If you want syzbot to run the reproducer, reply with: > #syz test: git://repo/address.git branch-or-commit-hash > If you attach or paste a git patch, syzbot will apply it before testing. #syz test git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next abb240f7a2bd diff --git a/include/linux/bio.h b/include/linux/bio.h index ec4db73e5f4e..1518f1201ddd 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -286,6 +286,11 @@ static inline void bio_first_folio(struct folio_iter *fi, struct bio *bio, { struct bio_vec *bvec = bio_first_bvec_all(bio) + i; + if (i >= bio->bi_vcnt) { + fi->folio = NULL; + return; + } + fi->folio = page_folio(bvec->bv_page); fi->offset = bvec->bv_offset + PAGE_SIZE * (bvec->bv_page - &fi->folio->page); @@ -303,10 +308,8 @@ static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio) fi->offset = 0; fi->length = min(folio_size(fi->folio), fi->_seg_count); fi->_next = folio_next(fi->folio); - } else if (fi->_i + 1 < bio->bi_vcnt) { - bio_first_folio(fi, bio, fi->_i + 1); } else { - fi->folio = NULL; + bio_first_folio(fi, bio, fi->_i + 1); } }