From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.15 commit 783a40a1b3ac7f3714d2776fa8ac8cce3535e4f6 category: bugfix bugzilla: 181328 CVE: NA
-----------------------------------------------
While clearing the profile itself is harmless, we really should not clear the stable writes flag if it wasn't set due to a registered integrity profile.
Reported-by: Lihong Kou koulihong@huawei.com Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Sagi Grimberg sagi@grimberg.me Link: https://lore.kernel.org/r/20210914070657.87677-2-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- block/blk-integrity.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 6121611e13164..0638f4868f705 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -431,8 +431,13 @@ EXPORT_SYMBOL(blk_integrity_register); */ void blk_integrity_unregister(struct gendisk *disk) { + struct blk_integrity *bi = &disk->queue->integrity; + + if (!bi->profile) + return; + disk->queue->backing_dev_info->capabilities &= ~BDI_CAP_STABLE_WRITES; - memset(&disk->queue->integrity, 0, sizeof(struct blk_integrity)); + memset(bi, 0, sizeof(*bi)); } EXPORT_SYMBOL(blk_integrity_unregister);
From: Lihong Kou koulihong@huawei.com
mainline inclusion from mainline-v5.15 commit 3df49967f6f1d2121b0c27c381ca1c8386b1dab9 category: bugfix bugzilla: 181328 CVE: NA
-----------------------------------------------
When the integrity profile is unregistered there can still be integrity reads queued up which could see a NULL verify_fn as shown by the race window below:
CPU0 CPU1 process_one_work nvme_validate_ns bio_integrity_verify_fn nvme_update_ns_info nvme_update_disk_info blk_integrity_unregister ---set queue->integrity as 0 bio_integrity_process --access bi->profile->verify_fn(bi is a pointer of queue->integity)
Before calling blk_integrity_unregister in nvme_update_disk_info, we must make sure that there is no work item in the kintegrityd_wq. Just call blk_flush_integrity to flush the work queue so the bug can be resolved.
Signed-off-by: Lihong Kou koulihong@huawei.com [hch: split up and shortened the changelog] Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Sagi Grimberg sagi@grimberg.me Link: https://lore.kernel.org/r/20210914070657.87677-3-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- block/blk-integrity.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 0638f4868f705..0b01fa972f1fc 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -436,6 +436,8 @@ void blk_integrity_unregister(struct gendisk *disk) if (!bi->profile) return;
+ /* ensure all bios are off the integrity workqueue */ + blk_flush_integrity(); disk->queue->backing_dev_info->capabilities &= ~BDI_CAP_STABLE_WRITES; memset(bi, 0, sizeof(*bi)); }
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.15 commit 9da4c7276ec5d167972d8f6670d64b59838b4ed2 category: bugfix bugzilla: 181328 CVE: NA
-----------------------------------------------
There is no need to explicitly unregister the integrity profile when deleting the gendisk.
Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Sagi Grimberg sagi@grimberg.me Link: https://lore.kernel.org/r/20210914070657.87677-4-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk
Conflict: drivers/nvme/host/core.c Signed-off-by: Yu Kuai yukuai3@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/nvme/host/core.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 7982818763835..522ab9c0133ca 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3370,8 +3370,6 @@ static void nvme_ns_remove(struct nvme_ns *ns) if (ns->disk && ns->disk->flags & GENHD_FL_UP) { del_gendisk(ns->disk); blk_cleanup_queue(ns->queue); - if (blk_get_integrity(ns->disk)) - blk_integrity_unregister(ns->disk); }
down_write(&ns->ctrl->namespaces_rwsem);