summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2024-06-13 10:48:11 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-08-03 08:48:53 +0200
commitd418313bd8f55c079a7da12651951b489a638ac1 (patch)
tree39df2425a8d4bec87db4b2269c0a00d34cf8b4cf
parenta9a99a1ca1b8fba9398f475716937c74c994e12e (diff)
downloadlinux-d418313bd8f55c079a7da12651951b489a638ac1.tar.gz
linux-d418313bd8f55c079a7da12651951b489a638ac1.tar.bz2
linux-d418313bd8f55c079a7da12651951b489a638ac1.zip
block: initialize integrity buffer to zero before writing it to media
[ Upstream commit 899ee2c3829c5ac14bfc7d3c4a5846c0b709b78f ] 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: 7ba1ba12eeef ("block: Block layer data integrity support") Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Kanchan Joshi <joshi.k@samsung.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Link: https://lore.kernel.org/r/20240613084839.1044015-2-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--block/bio-integrity.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 045553a164e0..adbc00449a9c 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -199,6 +199,7 @@ bool bio_integrity_prep(struct bio *bio)
unsigned long start, end;
unsigned int len, nr_pages;
unsigned int bytes, offset, i;
+ gfp_t gfp = GFP_NOIO;
if (!bi)
return true;
@@ -221,11 +222,19 @@ bool bio_integrity_prep(struct bio *bio)
if (!bi->profile->generate_fn ||
!(bi->flags & BLK_INTEGRITY_GENERATE))
return true;
+
+ /*
+ * Zero the memory allocated to not leak uninitialized kernel
+ * memory to disk. For PI this only affects the app tag, but
+ * for non-integrity metadata it affects the entire metadata
+ * buffer.
+ */
+ gfp |= __GFP_ZERO;
}
/* Allocate kernel buffer for protection data */
len = bio_integrity_bytes(bi, bio_sectors(bio));
- buf = kmalloc(len, GFP_NOIO);
+ buf = kmalloc(len, gfp);
if (unlikely(buf == NULL)) {
printk(KERN_ERR "could not allocate integrity buffer\n");
goto err_end_io;