Linux XFS filesystem development
 help / color / mirror / Atom feed
* fix fs-integrity for non-PI metadata v3
@ 2026-08-04 12:39 Christoph Hellwig
  2026-08-04 12:39 ` [PATCH 1/3] block: remove bip_should_check Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-08-04 12:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Martin K. Petersen, Kanchan Joshi, Anuj Gupta, Christian Brauner,
	Darrick J. Wong, linux-block, linux-xfs, linux-fsdevel

Hi all,

this series fixes incorrect calls into the PI generation helpers
when using fs-integrity on devics with non-PI metadata, which can
cause kernel crashes.

Changes since v2:
 - split the iomap patch into a separate series.

Changes since v1:
 - fix two more null pointer dereferences

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] block: remove bip_should_check
  2026-08-04 12:39 fix fs-integrity for non-PI metadata v3 Christoph Hellwig
@ 2026-08-04 12:39 ` Christoph Hellwig
  2026-08-04 13:22   ` Jens Axboe
  2026-08-04 12:39 ` [PATCH 2/3] block: lift BIP_CHECK_FLAGS to include/linux/bio-integrity.h Christoph Hellwig
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2026-08-04 12:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Martin K. Petersen, Kanchan Joshi, Anuj Gupta, Christian Brauner,
	Darrick J. Wong, linux-block, linux-xfs, linux-fsdevel

There is no benefit in using this helper over the simple flags check.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
---
 block/bio-integrity-auto.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/block/bio-integrity-auto.c b/block/bio-integrity-auto.c
index b1c733ecfd2e..43ac9f338183 100644
--- a/block/bio-integrity-auto.c
+++ b/block/bio-integrity-auto.c
@@ -45,10 +45,6 @@ static void bio_integrity_verify_fn(struct work_struct *work)
 }
 
 #define BIP_CHECK_FLAGS (BIP_CHECK_GUARD | BIP_CHECK_REFTAG | BIP_CHECK_APPTAG)
-static bool bip_should_check(struct bio_integrity_payload *bip)
-{
-	return bip->bip_flags & BIP_CHECK_FLAGS;
-}
 
 /**
  * __bio_integrity_endio - Integrity I/O completion function
@@ -66,7 +62,7 @@ bool __bio_integrity_endio(struct bio *bio)
 		container_of(bip, struct bio_integrity_data, bip);
 
 	if (bio_op(bio) == REQ_OP_READ && !bio->bi_status &&
-	    bip_should_check(bip)) {
+	    (bip->bip_flags & BIP_CHECK_FLAGS)) {
 		INIT_WORK(&bid->work, bio_integrity_verify_fn);
 		queue_work(kintegrityd_wq, &bid->work);
 		return false;
@@ -99,7 +95,7 @@ void bio_integrity_prep(struct bio *bio, unsigned int action)
 		bio_integrity_setup_default(bio);
 
 	/* Auto-generate integrity metadata if this is a write */
-	if (bio_data_dir(bio) == WRITE && bip_should_check(&bid->bip))
+	if (bio_data_dir(bio) == WRITE && (bid->bip.bip_flags & BIP_CHECK_FLAGS))
 		bio_integrity_generate(bio);
 	else
 		bid->saved_bio_iter = bio->bi_iter;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] block: lift BIP_CHECK_FLAGS to include/linux/bio-integrity.h
  2026-08-04 12:39 fix fs-integrity for non-PI metadata v3 Christoph Hellwig
  2026-08-04 12:39 ` [PATCH 1/3] block: remove bip_should_check Christoph Hellwig
@ 2026-08-04 12:39 ` Christoph Hellwig
  2026-08-04 12:39 ` [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity Christoph Hellwig
  2026-08-04 12:55 ` fix fs-integrity for non-PI metadata v3 Martin K. Petersen
  3 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-08-04 12:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Martin K. Petersen, Kanchan Joshi, Anuj Gupta, Christian Brauner,
	Darrick J. Wong, linux-block, linux-xfs, linux-fsdevel

To allow for users outside of bio-integrity-auto.c.  Also add a little
comment explaining it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
---
 block/bio-integrity-auto.c    | 2 --
 include/linux/bio-integrity.h | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/bio-integrity-auto.c b/block/bio-integrity-auto.c
index 43ac9f338183..9456dcffd17a 100644
--- a/block/bio-integrity-auto.c
+++ b/block/bio-integrity-auto.c
@@ -44,8 +44,6 @@ static void bio_integrity_verify_fn(struct work_struct *work)
 	bio_endio(bio);
 }
 
-#define BIP_CHECK_FLAGS (BIP_CHECK_GUARD | BIP_CHECK_REFTAG | BIP_CHECK_APPTAG)
-
 /**
  * __bio_integrity_endio - Integrity I/O completion function
  * @bio:	Protected bio
diff --git a/include/linux/bio-integrity.h b/include/linux/bio-integrity.h
index c3dda32fd803..0ea2a8bf7efb 100644
--- a/include/linux/bio-integrity.h
+++ b/include/linux/bio-integrity.h
@@ -17,6 +17,9 @@ enum bip_flags {
 	BIP_MEMPOOL		= 1 << 15, /* buffer backed by mempool */
 };
 
+/* flags that require generate/verify action. */
+#define BIP_CHECK_FLAGS (BIP_CHECK_GUARD | BIP_CHECK_REFTAG | BIP_CHECK_APPTAG)
+
 struct bio_integrity_payload {
 	struct bvec_iter	bip_iter;
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity
  2026-08-04 12:39 fix fs-integrity for non-PI metadata v3 Christoph Hellwig
  2026-08-04 12:39 ` [PATCH 1/3] block: remove bip_should_check Christoph Hellwig
  2026-08-04 12:39 ` [PATCH 2/3] block: lift BIP_CHECK_FLAGS to include/linux/bio-integrity.h Christoph Hellwig
@ 2026-08-04 12:39 ` Christoph Hellwig
  2026-08-04 12:56   ` Anuj gupta
  2026-08-04 12:55 ` fix fs-integrity for non-PI metadata v3 Martin K. Petersen
  3 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2026-08-04 12:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Martin K. Petersen, Kanchan Joshi, Anuj Gupta, Christian Brauner,
	Darrick J. Wong, linux-block, linux-xfs, linux-fsdevel

Check the BIP_CHECK flags before generating or verifying PI information,
otherwise this can be incorrectly called for non-PI metadata and
cause generation of incorrect metadata and crashed in the verification
handler.

The new behavior matches that of the block layer auto-generated
metadata.

Fixes: 0bde8a12b554 ("block: add fs_bio_integrity helpers")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
---
 block/bio-integrity-fs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/bio-integrity-fs.c b/block/bio-integrity-fs.c
index 9c5fe5fa8f0d..692403dfa047 100644
--- a/block/bio-integrity-fs.c
+++ b/block/bio-integrity-fs.c
@@ -46,7 +46,8 @@ void fs_bio_integrity_free(struct bio *bio)
 
 void fs_bio_integrity_generate(struct bio *bio)
 {
-	if (fs_bio_integrity_alloc(bio))
+	if (fs_bio_integrity_alloc(bio) &&
+	    (bio_integrity(bio)->bip_flags & BIP_CHECK_FLAGS))
 		bio_integrity_generate(bio);
 }
 EXPORT_SYMBOL_GPL(fs_bio_integrity_generate);
@@ -60,6 +61,9 @@ int fs_bio_integrity_verify(struct bio *bio, sector_t sector, unsigned int size)
 		.bi_size	= size,
 	};
 
+	if (!bip || !(bip->bip_flags & BIP_CHECK_FLAGS))
+		return 0;
+
 	/*
 	 * Reinitialize bip->bip_iter.
 	 *
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: fix fs-integrity for non-PI metadata v3
  2026-08-04 12:39 fix fs-integrity for non-PI metadata v3 Christoph Hellwig
                   ` (2 preceding siblings ...)
  2026-08-04 12:39 ` [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity Christoph Hellwig
@ 2026-08-04 12:55 ` Martin K. Petersen
  3 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2026-08-04 12:55 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
	Christian Brauner, Darrick J. Wong, linux-block, linux-xfs,
	linux-fsdevel


Christoph,

> this series fixes incorrect calls into the PI generation helpers when
> using fs-integrity on devics with non-PI metadata, which can cause
> kernel crashes.

Looks fine.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity
  2026-08-04 12:39 ` [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity Christoph Hellwig
@ 2026-08-04 12:56   ` Anuj gupta
  2026-08-04 13:04     ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Anuj gupta @ 2026-08-04 12:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Martin K. Petersen, Kanchan Joshi, Anuj Gupta,
	Christian Brauner, Darrick J. Wong, linux-block, linux-xfs,
	linux-fsdevel

Pretty sure I reviewed this patch before, but FWIW:
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity
  2026-08-04 12:56   ` Anuj gupta
@ 2026-08-04 13:04     ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-08-04 13:04 UTC (permalink / raw)
  To: Anuj gupta
  Cc: Christoph Hellwig, Jens Axboe, Martin K. Petersen, Kanchan Joshi,
	Anuj Gupta, Christian Brauner, Darrick J. Wong, linux-block,
	linux-xfs, linux-fsdevel

On Tue, Aug 04, 2026 at 06:26:58PM +0530, Anuj gupta wrote:
> Pretty sure I reviewed this patch before, but FWIW:
> Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>

And I'm pretty sure I picked up your review, but I guess I messed
it up :)

Thanks!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] block: remove bip_should_check
  2026-08-04 12:39 ` [PATCH 1/3] block: remove bip_should_check Christoph Hellwig
@ 2026-08-04 13:22   ` Jens Axboe
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2026-08-04 13:22 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Martin K. Petersen, Kanchan Joshi, Anuj Gupta, Christian Brauner,
	Darrick J. Wong, linux-block, linux-xfs, linux-fsdevel


On Tue, 04 Aug 2026 05:39:23 -0700, Christoph Hellwig wrote:
> There is no benefit in using this helper over the simple flags check.

Applied, thanks!

[1/3] block: remove bip_should_check
      commit: 6c13180dba60f835d6909e2a3b4f50862de156c6
[2/3] block: lift BIP_CHECK_FLAGS to include/linux/bio-integrity.h
      commit: 738f01912a1ad68c81a6aed06cac94e09b5f609d
[3/3] block: handle nogenerate/noverify properly in fs-integrity
      commit: 3bf9a21e7bccfd8c35b440efd114c61cc9838a41

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-08-04 13:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04 12:39 fix fs-integrity for non-PI metadata v3 Christoph Hellwig
2026-08-04 12:39 ` [PATCH 1/3] block: remove bip_should_check Christoph Hellwig
2026-08-04 13:22   ` Jens Axboe
2026-08-04 12:39 ` [PATCH 2/3] block: lift BIP_CHECK_FLAGS to include/linux/bio-integrity.h Christoph Hellwig
2026-08-04 12:39 ` [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity Christoph Hellwig
2026-08-04 12:56   ` Anuj gupta
2026-08-04 13:04     ` Christoph Hellwig
2026-08-04 12:55 ` fix fs-integrity for non-PI metadata v3 Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox