* [PATCH] block: initialize integrity buffer to zero before writing it to media
@ 2024-06-06 5:27 Christoph Hellwig
2024-06-06 14:08 ` Martin K. Petersen
2024-06-10 2:51 ` Chaitanya Kulkarni
0 siblings, 2 replies; 6+ messages in thread
From: Christoph Hellwig @ 2024-06-06 5:27 UTC (permalink / raw)
To: axboe; +Cc: martin.petersen, linux-block
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>
---
block/bio-integrity.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 2e3e8e04961eae..af7f71d16114de 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -432,6 +432,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;
@@ -454,11 +455,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;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] block: initialize integrity buffer to zero before writing it to media
2024-06-06 5:27 [PATCH] block: initialize integrity buffer to zero before writing it to media Christoph Hellwig
@ 2024-06-06 14:08 ` Martin K. Petersen
2024-06-06 14:10 ` Christoph Hellwig
2024-06-10 2:51 ` Chaitanya Kulkarni
1 sibling, 1 reply; 6+ messages in thread
From: Martin K. Petersen @ 2024-06-06 14:08 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: axboe, martin.petersen, linux-block
Christoph,
> 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.
We do explicitly set the app_tag to 0 for PI so it's only non-PI
metadata that's affected.
> Fix this by adding the __GFP_ZERO flag to allocations for writes.
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: initialize integrity buffer to zero before writing it to media
2024-06-06 14:08 ` Martin K. Petersen
@ 2024-06-06 14:10 ` Christoph Hellwig
2024-06-07 5:40 ` Christoph Hellwig
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2024-06-06 14:10 UTC (permalink / raw)
To: Martin K. Petersen; +Cc: Christoph Hellwig, axboe, linux-block
On Thu, Jun 06, 2024 at 10:08:20AM -0400, Martin K. Petersen wrote:
>
> Christoph,
>
> > 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.
>
> We do explicitly set the app_tag to 0 for PI so it's only non-PI
> metadata that's affected.
Ah, true. I could switch to then just zeroing the buffer in
->generate_fn for non-PI metadata only. That's actually the
first version I prototyped.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: initialize integrity buffer to zero before writing it to media
2024-06-06 14:10 ` Christoph Hellwig
@ 2024-06-07 5:40 ` Christoph Hellwig
2024-06-10 10:39 ` Kanchan Joshi
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2024-06-07 5:40 UTC (permalink / raw)
To: Martin K. Petersen; +Cc: Christoph Hellwig, axboe, linux-block
On Thu, Jun 06, 2024 at 04:10:17PM +0200, Christoph Hellwig wrote:
> > We do explicitly set the app_tag to 0 for PI so it's only non-PI
> > metadata that's affected.
>
> Ah, true. I could switch to then just zeroing the buffer in
> ->generate_fn for non-PI metadata only. That's actually the
> first version I prototyped.
So that would cause a fair amout of conflicts with moving the integrity
information to the limits. So unless someone objets I'd like to go
with this simple version, and with that series we can then easily
relax the zeroing check to only cover the non-PI case.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: initialize integrity buffer to zero before writing it to media
2024-06-06 5:27 [PATCH] block: initialize integrity buffer to zero before writing it to media Christoph Hellwig
2024-06-06 14:08 ` Martin K. Petersen
@ 2024-06-10 2:51 ` Chaitanya Kulkarni
1 sibling, 0 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2024-06-10 2:51 UTC (permalink / raw)
To: Christoph Hellwig, axboe@kernel.dk
Cc: martin.petersen@oracle.com, linux-block@vger.kernel.org
On 6/5/2024 10:27 PM, Christoph Hellwig wrote:
> 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>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-10 10:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-06 5:27 [PATCH] block: initialize integrity buffer to zero before writing it to media Christoph Hellwig
2024-06-06 14:08 ` Martin K. Petersen
2024-06-06 14:10 ` Christoph Hellwig
2024-06-07 5:40 ` Christoph Hellwig
2024-06-10 10:39 ` Kanchan Joshi
2024-06-10 2:51 ` Chaitanya Kulkarni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).