Skip to contentSkip to conversation

memory leak in bio_clone_fast

DISCUSSION Hillf Danton 1 participant 1 message Aug 14, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

On Tue, 13 Aug 2019 14:08:06 -0700

Quoted 44 lines

Hello,

syzbot found the following crash on:

HEAD commit:    d45331b0 Linux 5.3-rc4
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1651e6d2600000
kernel config:  https://syzkaller.appspot.com/x/.config?x=6c5e70dcab57c6af
dashboard link: https://syzkaller.appspot.com/bug?extid=0265846a0cb9a0547905
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=12c9c336600000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1766156a600000

IMPORTANT: if you fix the bug, please add the following tag to the commit:

Reported-by [email protected]

executing program
executing program
executing program
executing program

BUG: memory leak
unreferenced object 0xffff8881226da6c0 (size 192):
   comm "syz-executor332", pid 6977, jiffies 4294941214 (age 15.840s)
   hex dump (first 32 bytes):
     00 00 00 00 00 00 00 00 00 f0 bc 28 81 88 ff ff  ...........(....
     01 c8 60 00 02 0b 00 00 00 00 00 00 00 00 00 00  ..`.............
   backtrace:
     [<00000000b06a638e>] kmemleak_alloc_recursive  include/linux/kmemleak.h:43 [inline]
     [<00000000b06a638e>] slab_post_alloc_hook mm/slab.h:522 [inline]
     [<00000000b06a638e>] slab_alloc mm/slab.c:3319 [inline]
     [<00000000b06a638e>] kmem_cache_alloc+0x13f/0x2c0 mm/slab.c:3483
     [<00000000950a289d>] mempool_alloc_slab+0x1e/0x30 mm/mempool.c:513
     [<00000000bfcc27e2>] mempool_alloc+0x64/0x1b0 mm/mempool.c:393
     [<00000000cdf95a4a>] bio_alloc_bioset+0x180/0x2c0 block/bio.c:477
     [<00000000b239bb68>] bio_clone_fast+0x25/0x90 block/bio.c:609
     [<000000005d58c2dc>] bio_split+0x4a/0xd0 block/bio.c:1856
     [<00000000ab943734>] blk_bio_segment_split block/blk-merge.c:250  [inline]
     [<00000000ab943734>] __blk_queue_split+0x355/0x730 block/blk-merge.c:272
     [<00000000e702c0ac>] blk_mq_make_request+0xb0/0x890 block/blk-mq.c:1943
     [<000000003c89773a>] generic_make_request block/blk-core.c:1052 [inline]
     [<000000003c89773a>] generic_make_request+0xf6/0x4a0   block/blk-core.c:994
     [<00000000a4dcaf78>] submit_bio+0x5a/0x1e0 block/blk-core.c:1163
     [<000000003e1ce7f8>] __blkdev_direct_IO fs/block_dev.c:459 [inline]
     [<000000003e1ce7f8>] blkdev_direct_IO+0x2b3/0x6d0 fs/block_dev.c:515
Quoted 8 lines
     [<0000000087ec76a4>] generic_file_direct_write+0xb0/0x1a0   mm/filemap.c:3230
     [<00000000ff259b44>] __generic_file_write_iter+0xec/0x230   mm/filemap.c:3413
     [<00000000223d9b6c>] blkdev_write_iter fs/block_dev.c:2026 [inline]
     [<00000000223d9b6c>] blkdev_write_iter+0xbe/0x160 fs/block_dev.c:2003
     [<000000003c4a5c94>] call_write_iter include/linux/fs.h:1870 [inline]
     [<000000003c4a5c94>] aio_write+0x10b/0x1d0 fs/aio.c:1583
     [<00000000581f0c84>] __io_submit_one fs/aio.c:1815 [inline]
     [<00000000581f0c84>] io_submit_one+0x59b/0xe50 fs/aio.c:1862

1, add BLK_QC_T_EAGAIN

block/blk-core.c +2 -1
@@ -1004,7 +1004,8 @@ blk_qc_t generic_make_request(struct bio
 	blk_qc_t ret = BLK_QC_T_NONE;
 
 	if (!generic_make_request_checks(bio))
-		goto out;
+		/* feed error back to __blkdev_direct_IO fs/block_dev.c:459 */
+		return BLK_QC_T_EAGAIN;
 
 	/*
 	 * We only want one ->make_request_fn to be active at a time, else

--

2, plan-B, check status if BLK_QC_T_EAGAIN is bad

fs/block_dev.c +1 -1
@@ -461,7 +461,7 @@ __blkdev_direct_IO(struct kiocb *iocb, s
 		}
 
 		qc = submit_bio(bio);
-		if (qc == BLK_QC_T_EAGAIN) {
+		if (qc == BLK_QC_T_EAGAIN || bio->bi_status) {
 			if (!ret)
 				ret = -EAGAIN;
 			goto error;

--