[bug report] block/bio: add pcpu caching for non-polling bio_put

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Pavel Begunkov,

The patch 13a184e26965: "block/bio: add pcpu caching for non-polling
bio_put" from Oct 21, 2022, leads to the following Smatch static
checker warning:

	block/bio.c:450 bio_alloc_percpu_cache()
	error: we previously assumed 'bio' could be null (see line 449)

block/bio.c
    433 static struct bio *bio_alloc_percpu_cache(struct block_device *bdev,
    434                 unsigned short nr_vecs, blk_opf_t opf, gfp_t gfp,
    435                 struct bio_set *bs)
    436 {
    437         struct bio_alloc_cache *cache;
    438         struct bio *bio;
    439 
    440         cache = per_cpu_ptr(bs->cache, get_cpu());
    441         if (!cache->free_list &&
    442             READ_ONCE(cache->nr_irq) >= ALLOC_CACHE_THRESHOLD) {

Imagine "cache->free_list" is NULL but cache->nr_irq is less than the
threshold.

    443                 bio_alloc_irq_cache_splice(cache);
    444                 if (!cache->free_list) {
    445                         put_cpu();
    446                         return NULL;
    447                 }
    448         }
    449         bio = cache->free_list;
--> 450         cache->free_list = bio->bi_next;
                                   ^^^^^^^^^^^^
It would lead to a NULL dereference here.

    451         cache->nr--;
    452         put_cpu();
    453 
    454         bio_init(bio, bdev, nr_vecs ? bio->bi_inline_vecs : NULL, nr_vecs, opf);
    455         bio->bi_pool = bs;
    456         return bio;
    457 }

regards,
dan carpenter



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux