* [PATCH] nvme: Fix discard buffer overrun
@ 2018-02-01 0:01 Keith Busch
2018-02-01 14:55 ` jianchao.wang
2018-02-02 3:19 ` Jens Axboe
0 siblings, 2 replies; 7+ messages in thread
From: Keith Busch @ 2018-02-01 0:01 UTC (permalink / raw)
This patch checks the discard range array bounds before setting it in
case the driver gets a badly formed request.
Signed-off-by: Keith Busch <keith.busch at intel.com>
Cc: Jens Axboe <axboe at kernel.dk>
---
drivers/nvme/host/core.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4bfb4ba6cd14..d02906a6dabe 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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);
u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
- range[n].cattr = cpu_to_le32(0);
- range[n].nlb = cpu_to_le32(nlb);
- range[n].slba = cpu_to_le64(slba);
+ if (n < segments) {
+ range[n].cattr = cpu_to_le32(0);
+ range[n].nlb = cpu_to_le32(nlb);
+ range[n].slba = cpu_to_le64(slba);
+ }
n++;
}
--
2.14.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH] nvme: Fix discard buffer overrun
2018-02-01 0:01 [PATCH] nvme: Fix discard buffer overrun Keith Busch
@ 2018-02-01 14:55 ` jianchao.wang
2018-02-01 15:05 ` Keith Busch
2018-02-01 15:27 ` Jens Axboe
2018-02-02 3:19 ` Jens Axboe
1 sibling, 2 replies; 7+ messages in thread
From: jianchao.wang @ 2018-02-01 14:55 UTC (permalink / raw)
Hi Keith
Since each discard bio merged into a request is counted as one segment,
why not let blk_rq_nr_discard_segments return numbers of bios directly.
On 02/01/2018 08:01 AM, Keith Busch wrote:
> This patch checks the discard range array bounds before setting it in
> case the driver gets a badly formed request.
>
> Signed-off-by: Keith Busch <keith.busch at intel.com>
> Cc: Jens Axboe <axboe at kernel.dk>
> ---
> drivers/nvme/host/core.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 4bfb4ba6cd14..d02906a6dabe 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -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);
> u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
>
> - range[n].cattr = cpu_to_le32(0);
> - range[n].nlb = cpu_to_le32(nlb);
> - range[n].slba = cpu_to_le64(slba);
> + if (n < segments) {
> + range[n].cattr = cpu_to_le32(0);
> + range[n].nlb = cpu_to_le32(nlb);
> + range[n].slba = cpu_to_le64(slba);
> + }
> n++;
> }
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH] nvme: Fix discard buffer overrun
2018-02-01 14:55 ` jianchao.wang
@ 2018-02-01 15:05 ` Keith Busch
2018-02-01 15:07 ` jianchao.wang
2018-02-01 15:27 ` Jens Axboe
1 sibling, 1 reply; 7+ messages in thread
From: Keith Busch @ 2018-02-01 15:05 UTC (permalink / raw)
On Thu, Feb 01, 2018@10:55:30PM +0800, jianchao.wang wrote:
> Hi Keith
>
> Since each discard bio merged into a request is counted as one segment,
> why not let blk_rq_nr_discard_segments return numbers of bios directly.
Right, I'm all for fixing the discard segment count. At the same time,
I don't want to depend on it's correctness to not access out-of-bounds
array indices.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] nvme: Fix discard buffer overrun
2018-02-01 15:05 ` Keith Busch
@ 2018-02-01 15:07 ` jianchao.wang
0 siblings, 0 replies; 7+ messages in thread
From: jianchao.wang @ 2018-02-01 15:07 UTC (permalink / raw)
Hi Keith
Thanks for your kindly response.
On 02/01/2018 11:05 PM, Keith Busch wrote:
> On Thu, Feb 01, 2018@10:55:30PM +0800, jianchao.wang wrote:
>> Hi Keith
>>
>> Since each discard bio merged into a request is counted as one segment,
>> why not let blk_rq_nr_discard_segments return numbers of bios directly.
>
> Right, I'm all for fixing the discard segment count. At the same time,
> I don't want to depend on it's correctness to not access out-of-bounds
> array indices.
>
Actually, if we use iterating request bio list to return discard segments count,
we won't have any out-of-bounds error any more. And things will be simpler. :)
Thanks
Jianchao
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] nvme: Fix discard buffer overrun
2018-02-01 14:55 ` jianchao.wang
2018-02-01 15:05 ` Keith Busch
@ 2018-02-01 15:27 ` Jens Axboe
2018-02-02 1:50 ` jianchao.wang
1 sibling, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2018-02-01 15:27 UTC (permalink / raw)
On 2/1/18 7:55 AM, jianchao.wang wrote:
> Hi Keith
>
> Since each discard bio merged into a request is counted as one segment,
> why not let blk_rq_nr_discard_segments return numbers of bios directly.
That's a good idea, but for now this looks fine. Both this and the
core block hole can be fixed, and then someone can hopefully work
on making discards behave a bit more nicely after that.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] nvme: Fix discard buffer overrun
2018-02-01 15:27 ` Jens Axboe
@ 2018-02-02 1:50 ` jianchao.wang
0 siblings, 0 replies; 7+ messages in thread
From: jianchao.wang @ 2018-02-02 1:50 UTC (permalink / raw)
Hi Jens
Thanks for your kindly response.
On 02/01/2018 11:27 PM, Jens Axboe wrote:
> On 2/1/18 7:55 AM, jianchao.wang wrote:
>> Hi Keith
>>
>> Since each discard bio merged into a request is counted as one segment,
>> why not let blk_rq_nr_discard_segments return numbers of bios directly.
>
> That's a good idea, but for now this looks fine. Both this and the
> core block hole can be fixed, and then someone can hopefully work
> on making discards behave a bit more nicely after that.
>
Yes, got it.
Thanks
Jianchao
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] nvme: Fix discard buffer overrun
2018-02-01 0:01 [PATCH] nvme: Fix discard buffer overrun Keith Busch
2018-02-01 14:55 ` jianchao.wang
@ 2018-02-02 3:19 ` Jens Axboe
1 sibling, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2018-02-02 3:19 UTC (permalink / raw)
On 1/31/18 5:01 PM, Keith Busch wrote:
> This patch checks the discard range array bounds before setting it in
> case the driver gets a badly formed request.
>
> Signed-off-by: Keith Busch <keith.busch at intel.com>
> Cc: Jens Axboe <axboe at kernel.dk>
> ---
> drivers/nvme/host/core.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 4bfb4ba6cd14..d02906a6dabe 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -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);
> u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift;
>
> - range[n].cattr = cpu_to_le32(0);
> - range[n].nlb = cpu_to_le32(nlb);
> - range[n].slba = cpu_to_le64(slba);
> + if (n < segments) {
> + range[n].cattr = cpu_to_le32(0);
> + range[n].nlb = cpu_to_le32(nlb);
> + range[n].slba = cpu_to_le64(slba);
> + }
> n++;
> }
Reviewed-by: Jens Axboe <axboe at kernel.dk>
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-02-02 3:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-01 0:01 [PATCH] nvme: Fix discard buffer overrun Keith Busch
2018-02-01 14:55 ` jianchao.wang
2018-02-01 15:05 ` Keith Busch
2018-02-01 15:07 ` jianchao.wang
2018-02-01 15:27 ` Jens Axboe
2018-02-02 1:50 ` jianchao.wang
2018-02-02 3:19 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox