Skip to content

Commit 899ee2c

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: initialize integrity buffer to zero before writing it to media
Metadata added by bio_integrity_prep is using plain kmalloc, which leads to random kernel memory being written media. For PI metadata this is limited to the app tag that isn't used by kernel generated metadata, but for non-PI metadata the entire buffer leaks kernel memory. Fix this by adding the __GFP_ZERO flag to allocations for writes. Fixes: 7ba1ba1 ("block: Block layer data integrity support") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Kanchan Joshi <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 73e3715 commit 899ee2c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

block/bio-integrity.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ bool bio_integrity_prep(struct bio *bio)
432432
unsigned long start, end;
433433
unsigned int len, nr_pages;
434434
unsigned int bytes, offset, i;
435+
gfp_t gfp = GFP_NOIO;
435436

436437
if (!bi)
437438
return true;
@@ -454,11 +455,19 @@ bool bio_integrity_prep(struct bio *bio)
454455
if (!bi->profile->generate_fn ||
455456
!(bi->flags & BLK_INTEGRITY_GENERATE))
456457
return true;
458+
459+
/*
460+
* Zero the memory allocated to not leak uninitialized kernel
461+
* memory to disk. For PI this only affects the app tag, but
462+
* for non-integrity metadata it affects the entire metadata
463+
* buffer.
464+
*/
465+
gfp |= __GFP_ZERO;
457466
}
458467

459468
/* Allocate kernel buffer for protection data */
460469
len = bio_integrity_bytes(bi, bio_sectors(bio));
461-
buf = kmalloc(len, GFP_NOIO);
470+
buf = kmalloc(len, gfp);
462471
if (unlikely(buf == NULL)) {
463472
printk(KERN_ERR "could not allocate integrity buffer\n");
464473
goto err_end_io;

0 commit comments

Comments
 (0)