fix fs-integrity for non-PI metadata v3
Subsystems (2)
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
PATCH 1/3 block: remove bip_should_check
There is no benefit in using this helper over the simple flags check.
--- block/bio-integrity-auto.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
block/bio-integrity-auto.c +2 -6
@@ -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;
Signature · 1 line
2.53.0
Re: [PATCH 1/3] block: remove bip_should_check
Quoted 1 line · Christoph Hellwig
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: 3bf9a21e7bccfd8c35b440efd114c61cc9838a41Best regards,
Signature · 1 line
Jens Axboe
PATCH 2/3 block: lift BIP_CHECK_FLAGS to include/linux/bio-integrity.h
In reply to Christoph HellwigTo allow for users outside of bio-integrity-auto.c. Also add a little comment explaining it.
--- block/bio-integrity-auto.c | 2 -- include/linux/bio-integrity.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
block/bio-integrity-auto.c +0 -2
@@ -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
include/linux/bio-integrity.h +3 -0
@@ -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;
Signature · 1 line
2.53.0
PATCH 3/3 block: handle nogenerate/noverify properly in fs-integrity
In reply to Christoph HellwigCheck 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.
--- block/bio-integrity-fs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/bio-integrity-fs.c +5 -1
@@ -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. *
Signature · 1 line
2.53.0
Re: [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity
Pretty sure I reviewed this patch before, but FWIW:
Re: [PATCH 3/3] block: handle nogenerate/noverify properly in fs-integrity
Quoted 2 lines · Anuj gupta
Pretty sure I reviewed this patch before, but FWIW:
Reviewed-by Anuj Gupta <[email protected]>
And I'm pretty sure I picked up your review, but I guess I messed it up :)
Thanks!
Martin K. Petersen
Reviewed-byChristoph,
Quoted 3 lines
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.
Signature · 1 line
Martin K. Petersen