Skip to content

Commit f7e3f85

Browse files
shauryarane05axboe
authored andcommitted
block: fix memory leak in __blkdev_issue_zero_pages
Move the fatal signal check before bio_alloc() to prevent a memory leak when BLKDEV_ZERO_KILLABLE is set and a fatal signal is pending. Previously, the bio was allocated before checking for a fatal signal. If a signal was pending, the code would break out of the loop without freeing or chaining the just-allocated bio, causing a memory leak. This matches the pattern already used in __blkdev_issue_write_zeroes() where the signal check precedes the allocation. Fixes: bf86bcd ("blk-lib: check for kill signal in ioctl BLKZEROOUT") Reported-by: syzbot+527a7e48a3d3d315d862@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=527a7e48a3d3d315d862 Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in> Reviewed-by: Keith Busch <kbusch@kernel.org> Tested-by: syzbot+527a7e48a3d3d315d862@syzkaller.appspotmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8a32282 commit f7e3f85

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

block/blk-lib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ static void __blkdev_issue_zero_pages(struct block_device *bdev,
202202
unsigned int nr_vecs = __blkdev_sectors_to_bio_pages(nr_sects);
203203
struct bio *bio;
204204

205-
bio = bio_alloc(bdev, nr_vecs, REQ_OP_WRITE, gfp_mask);
206-
bio->bi_iter.bi_sector = sector;
207-
208205
if ((flags & BLKDEV_ZERO_KILLABLE) &&
209206
fatal_signal_pending(current))
210207
break;
211208

209+
bio = bio_alloc(bdev, nr_vecs, REQ_OP_WRITE, gfp_mask);
210+
bio->bi_iter.bi_sector = sector;
211+
212212
do {
213213
unsigned int len;
214214

0 commit comments

Comments
 (0)