linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
@ 2020-01-24 17:39 Sagi Grimberg
  2020-01-24 18:28 ` Keith Busch
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sagi Grimberg @ 2020-01-24 17:39 UTC (permalink / raw)
  To: linux-nvme, Keith Busch, Christoph Hellwig; +Cc: Dakshaja Uppalapati

The host is allowed to pass the controller an sgl describing a buffer
that is larger than the dsm payload itself, allow it when executing
dsm.

Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
 drivers/nvme/target/core.c        | 12 ++++++++++++
 drivers/nvme/target/io-cmd-bdev.c |  2 +-
 drivers/nvme/target/io-cmd-file.c |  2 +-
 drivers/nvme/target/nvmet.h       |  1 +
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 28438b833c1b..9217c824620f 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -938,6 +938,18 @@ bool nvmet_check_data_len(struct nvmet_req *req, size_t data_len)
 }
 EXPORT_SYMBOL_GPL(nvmet_check_data_len);
 
+bool nvmet_check_data_len_lte(struct nvmet_req *req, size_t data_len)
+{
+	if (unlikely(data_len > req->transfer_len)) {
+		req->error_loc = offsetof(struct nvme_common_command, dptr);
+		nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR);
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(nvmet_check_data_len_lte);
+
 int nvmet_req_alloc_sgl(struct nvmet_req *req)
 {
 	struct pci_dev *p2p_dev = NULL;
diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index b6fca0e421ef..ea0e596be15d 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -280,7 +280,7 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)
 
 static void nvmet_bdev_execute_dsm(struct nvmet_req *req)
 {
-	if (!nvmet_check_data_len(req, nvmet_dsm_len(req)))
+	if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req)))
 		return;
 
 	switch (le32_to_cpu(req->cmd->dsm.attributes)) {
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index caebfce06605..cd5670b83118 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -336,7 +336,7 @@ static void nvmet_file_dsm_work(struct work_struct *w)
 
 static void nvmet_file_execute_dsm(struct nvmet_req *req)
 {
-	if (!nvmet_check_data_len(req, nvmet_dsm_len(req)))
+	if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req)))
 		return;
 	INIT_WORK(&req->f.work, nvmet_file_dsm_work);
 	schedule_work(&req->f.work);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 46df45e837c9..eda28b22a2c8 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -374,6 +374,7 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
 		struct nvmet_sq *sq, const struct nvmet_fabrics_ops *ops);
 void nvmet_req_uninit(struct nvmet_req *req);
 bool nvmet_check_data_len(struct nvmet_req *req, size_t data_len);
+bool nvmet_check_data_len_lte(struct nvmet_req *req, size_t data_len);
 void nvmet_req_complete(struct nvmet_req *req, u16 status);
 int nvmet_req_alloc_sgl(struct nvmet_req *req);
 void nvmet_req_free_sgl(struct nvmet_req *req);
-- 
2.20.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-01-24 17:39 [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor Sagi Grimberg
@ 2020-01-24 18:28 ` Keith Busch
  2020-01-24 18:35   ` Sagi Grimberg
  2020-01-25 21:23 ` Christoph Hellwig
  2020-03-19 17:23 ` Potnuri Bharat Teja
  2 siblings, 1 reply; 9+ messages in thread
From: Keith Busch @ 2020-01-24 18:28 UTC (permalink / raw)
  To: Sagi Grimberg; +Cc: Dakshaja Uppalapati, Christoph Hellwig, linux-nvme

On Fri, Jan 24, 2020 at 09:39:42AM -0800, Sagi Grimberg wrote:
> The host is allowed to pass the controller an sgl describing a buffer
> that is larger than the dsm payload itself, allow it when executing
> dsm.
> 
> Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>

Thanks, applied for 5.6.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-01-24 18:28 ` Keith Busch
@ 2020-01-24 18:35   ` Sagi Grimberg
  2020-01-24 18:55     ` Keith Busch
  0 siblings, 1 reply; 9+ messages in thread
From: Sagi Grimberg @ 2020-01-24 18:35 UTC (permalink / raw)
  To: Keith Busch; +Cc: Dakshaja Uppalapati, Christoph Hellwig, linux-nvme


>> The host is allowed to pass the controller an sgl describing a buffer
>> that is larger than the dsm payload itself, allow it when executing
>> dsm.
>>
>> Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
>> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> 
> Thanks, applied for 5.6.

Thanks Keith, this needs to be also in 5.5 as there the regression
was introduced, maybe add a tag on the commit?

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-01-24 18:35   ` Sagi Grimberg
@ 2020-01-24 18:55     ` Keith Busch
  0 siblings, 0 replies; 9+ messages in thread
From: Keith Busch @ 2020-01-24 18:55 UTC (permalink / raw)
  To: Sagi Grimberg; +Cc: Dakshaja Uppalapati, Christoph Hellwig, linux-nvme

On Fri, Jan 24, 2020 at 10:35:18AM -0800, Sagi Grimberg wrote:
> 
> > > The host is allowed to pass the controller an sgl describing a buffer
> > > that is larger than the dsm payload itself, allow it when executing
> > > dsm.
> > > 
> > > Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
> > > Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> > 
> > Thanks, applied for 5.6.
> 
> Thanks Keith, this needs to be also in 5.5 as there the regression
> was introduced, maybe add a tag on the commit?

Oh, is there an appropriate fixes tag? At this late point, though, I think
we should let stable pick it up in the 5.6 merge. Maybe we can sneak it
in if there's an rc8.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-01-24 17:39 [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor Sagi Grimberg
  2020-01-24 18:28 ` Keith Busch
@ 2020-01-25 21:23 ` Christoph Hellwig
  2020-01-27  7:23   ` Sagi Grimberg
  2020-03-19 17:23 ` Potnuri Bharat Teja
  2 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-01-25 21:23 UTC (permalink / raw)
  To: Sagi Grimberg
  Cc: Keith Busch, Dakshaja Uppalapati, Christoph Hellwig, linux-nvme

On Fri, Jan 24, 2020 at 09:39:42AM -0800, Sagi Grimberg wrote:
> The host is allowed to pass the controller an sgl describing a buffer
> that is larger than the dsm payload itself, allow it when executing
> dsm.
> 
> Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---
>  drivers/nvme/target/core.c        | 12 ++++++++++++
>  drivers/nvme/target/io-cmd-bdev.c |  2 +-
>  drivers/nvme/target/io-cmd-file.c |  2 +-
>  drivers/nvme/target/nvmet.h       |  1 +
>  4 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
> index 28438b833c1b..9217c824620f 100644
> --- a/drivers/nvme/target/core.c
> +++ b/drivers/nvme/target/core.c
> @@ -938,6 +938,18 @@ bool nvmet_check_data_len(struct nvmet_req *req, size_t data_len)
>  }
>  EXPORT_SYMBOL_GPL(nvmet_check_data_len);
>  
> +bool nvmet_check_data_len_lte(struct nvmet_req *req, size_t data_len)
> +{
> +	if (unlikely(data_len > req->transfer_len)) {
> +		req->error_loc = offsetof(struct nvme_common_command, dptr);
> +		nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR);
> +		return false;
> +	}
> +
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(nvmet_check_data_len_lte);

Why would this need an export??

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-01-25 21:23 ` Christoph Hellwig
@ 2020-01-27  7:23   ` Sagi Grimberg
  0 siblings, 0 replies; 9+ messages in thread
From: Sagi Grimberg @ 2020-01-27  7:23 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Keith Busch, Dakshaja Uppalapati, linux-nvme


>> +EXPORT_SYMBOL_GPL(nvmet_check_data_len_lte);
> 
> Why would this need an export??

Copy paste error, I'll send v2

Thanks.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-01-24 17:39 [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor Sagi Grimberg
  2020-01-24 18:28 ` Keith Busch
  2020-01-25 21:23 ` Christoph Hellwig
@ 2020-03-19 17:23 ` Potnuri Bharat Teja
  2020-03-19 21:06   ` Sagi Grimberg
  2 siblings, 1 reply; 9+ messages in thread
From: Potnuri Bharat Teja @ 2020-03-19 17:23 UTC (permalink / raw)
  To: Sagi Grimberg
  Cc: Keith Busch, Dakshaja Uppalapati, Christoph Hellwig, linux-nvme

On Friday, January 01/24/20, 2020 at 23:09:42 +0530, Sagi Grimberg wrote:
> The host is allowed to pass the controller an sgl describing a buffer
> that is larger than the dsm payload itself, allow it when executing
> dsm.
> 
> Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> ---

Hi Sagi,
I see this issue with 5.4 stable kernels. Can this be pushed to 5.4 stable?

Thanks.
>  drivers/nvme/target/core.c        | 12 ++++++++++++
>  drivers/nvme/target/io-cmd-bdev.c |  2 +-
>  drivers/nvme/target/io-cmd-file.c |  2 +-
>  drivers/nvme/target/nvmet.h       |  1 +
>  4 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
> index 28438b833c1b..9217c824620f 100644
> --- a/drivers/nvme/target/core.c
> +++ b/drivers/nvme/target/core.c
> @@ -938,6 +938,18 @@ bool nvmet_check_data_len(struct nvmet_req *req, size_t data_len)
>  }
>  EXPORT_SYMBOL_GPL(nvmet_check_data_len);
>  
> +bool nvmet_check_data_len_lte(struct nvmet_req *req, size_t data_len)
> +{
> +	if (unlikely(data_len > req->transfer_len)) {
> +		req->error_loc = offsetof(struct nvme_common_command, dptr);
> +		nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR);
> +		return false;
> +	}
> +
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(nvmet_check_data_len_lte);
> +
>  int nvmet_req_alloc_sgl(struct nvmet_req *req)
>  {
>  	struct pci_dev *p2p_dev = NULL;
> diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
> index b6fca0e421ef..ea0e596be15d 100644
> --- a/drivers/nvme/target/io-cmd-bdev.c
> +++ b/drivers/nvme/target/io-cmd-bdev.c
> @@ -280,7 +280,7 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)
>  
>  static void nvmet_bdev_execute_dsm(struct nvmet_req *req)
>  {
> -	if (!nvmet_check_data_len(req, nvmet_dsm_len(req)))
> +	if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req)))
>  		return;
>  
>  	switch (le32_to_cpu(req->cmd->dsm.attributes)) {
> diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
> index caebfce06605..cd5670b83118 100644
> --- a/drivers/nvme/target/io-cmd-file.c
> +++ b/drivers/nvme/target/io-cmd-file.c
> @@ -336,7 +336,7 @@ static void nvmet_file_dsm_work(struct work_struct *w)
>  
>  static void nvmet_file_execute_dsm(struct nvmet_req *req)
>  {
> -	if (!nvmet_check_data_len(req, nvmet_dsm_len(req)))
> +	if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req)))
>  		return;
>  	INIT_WORK(&req->f.work, nvmet_file_dsm_work);
>  	schedule_work(&req->f.work);
> diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
> index 46df45e837c9..eda28b22a2c8 100644
> --- a/drivers/nvme/target/nvmet.h
> +++ b/drivers/nvme/target/nvmet.h
> @@ -374,6 +374,7 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
>  		struct nvmet_sq *sq, const struct nvmet_fabrics_ops *ops);
>  void nvmet_req_uninit(struct nvmet_req *req);
>  bool nvmet_check_data_len(struct nvmet_req *req, size_t data_len);
> +bool nvmet_check_data_len_lte(struct nvmet_req *req, size_t data_len);
>  void nvmet_req_complete(struct nvmet_req *req, u16 status);
>  int nvmet_req_alloc_sgl(struct nvmet_req *req);
>  void nvmet_req_free_sgl(struct nvmet_req *req);
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-nvme mailing list
> linux-nvme@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-nvme

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-03-19 17:23 ` Potnuri Bharat Teja
@ 2020-03-19 21:06   ` Sagi Grimberg
  2020-03-20  5:48     ` Potnuri Bharat Teja
  0 siblings, 1 reply; 9+ messages in thread
From: Sagi Grimberg @ 2020-03-19 21:06 UTC (permalink / raw)
  To: Potnuri Bharat Teja
  Cc: Keith Busch, Dakshaja Uppalapati, Christoph Hellwig, linux-nvme


>> The host is allowed to pass the controller an sgl describing a buffer
>> that is larger than the dsm payload itself, allow it when executing
>> dsm.
>>
>> Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
>> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
>> ---
> 
> Hi Sagi,
> I see this issue with 5.4 stable kernels. Can this be pushed to 5.4 stable?

I can send this patch to stable.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor
  2020-03-19 21:06   ` Sagi Grimberg
@ 2020-03-20  5:48     ` Potnuri Bharat Teja
  0 siblings, 0 replies; 9+ messages in thread
From: Potnuri Bharat Teja @ 2020-03-20  5:48 UTC (permalink / raw)
  To: Sagi Grimberg
  Cc: Keith Busch, Dakshaja Uppalapati, Christoph Hellwig, linux-nvme

On Thursday, March 03/19/20, 2020 at 14:06:22 -0700, Sagi Grimberg wrote:
> 
> >>The host is allowed to pass the controller an sgl describing a buffer
> >>that is larger than the dsm payload itself, allow it when executing
> >>dsm.
> >>
> >>Reported-by: Dakshaja Uppalapati <dakshaja@chelsio.com>
> >>Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> >>---
> >
> >Hi Sagi,
> >I see this issue with 5.4 stable kernels. Can this be pushed to 5.4 stable?
> 
> I can send this patch to stable.
Thanks.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, other threads:[~2020-03-20  5:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 17:39 [PATCH] nvmet: fix dsm failure when payload does not match sgl descriptor Sagi Grimberg
2020-01-24 18:28 ` Keith Busch
2020-01-24 18:35   ` Sagi Grimberg
2020-01-24 18:55     ` Keith Busch
2020-01-25 21:23 ` Christoph Hellwig
2020-01-27  7:23   ` Sagi Grimberg
2020-03-19 17:23 ` Potnuri Bharat Teja
2020-03-19 21:06   ` Sagi Grimberg
2020-03-20  5:48     ` Potnuri Bharat Teja

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).