Commit 8cb6af7b authored by Keith Busch's avatar Keith Busch Committed by Sagi Grimberg

nvme: Fix discard buffer overrun

This patch checks the discard range array bounds before setting it in
case the driver gets a badly formed request.
Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
Reviewed-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
parent 3096a739
...@@ -518,9 +518,11 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req, ...@@ -518,9 +518,11 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
u64 slba = nvme_block_nr(ns, bio->bi_iter.bi_sector); u64 slba = nvme_block_nr(ns, bio->bi_iter.bi_sector);
u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift; u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
range[n].cattr = cpu_to_le32(0); if (n < segments) {
range[n].nlb = cpu_to_le32(nlb); range[n].cattr = cpu_to_le32(0);
range[n].slba = cpu_to_le64(slba); range[n].nlb = cpu_to_le32(nlb);
range[n].slba = cpu_to_le64(slba);
}
n++; n++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment