target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: target: iscsi: Fix data digest calculation
@ 2020-08-25 12:47 Varun Prakash
  2020-09-01 17:55 ` Mike Christie
  2020-09-03  3:01 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Varun Prakash @ 2020-08-25 12:47 UTC (permalink / raw)
  To: martin.petersen
  Cc: linux-scsi, target-devel, michael.christie, bvanassche, nab,
	varun, stable

Current code does not consider 'page_off' in data digest
calculation, to fix this add a local variable 'first_sg' and
set first_sg.offset to sg->offset + page_off.

Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
Cc: <stable@vger.kernel.org>
Signed-off-by: Varun Prakash <varun@chelsio.com>
---
 drivers/target/iscsi/iscsi_target.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index c968961..2ec778e 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -1389,14 +1389,27 @@ static u32 iscsit_do_crypto_hash_sg(
 	sg = cmd->first_data_sg;
 	page_off = cmd->first_data_sg_off;
 
+	if (data_length && page_off) {
+		struct scatterlist first_sg;
+		u32 len = min_t(u32, data_length, sg->length - page_off);
+
+		sg_init_table(&first_sg, 1);
+		sg_set_page(&first_sg, sg_page(sg), len, sg->offset + page_off);
+
+		ahash_request_set_crypt(hash, &first_sg, NULL, len);
+		crypto_ahash_update(hash);
+
+		data_length -= len;
+		sg = sg_next(sg);
+	}
+
 	while (data_length) {
-		u32 cur_len = min_t(u32, data_length, (sg->length - page_off));
+		u32 cur_len = min_t(u32, data_length, sg->length);
 
 		ahash_request_set_crypt(hash, sg, NULL, cur_len);
 		crypto_ahash_update(hash);
 
 		data_length -= cur_len;
-		page_off = 0;
 		/* iscsit_map_iovec has already checked for invalid sg pointers */
 		sg = sg_next(sg);
 	}
-- 
2.0.2

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

* Re: [PATCH] scsi: target: iscsi: Fix data digest calculation
  2020-08-25 12:47 [PATCH] scsi: target: iscsi: Fix data digest calculation Varun Prakash
@ 2020-09-01 17:55 ` Mike Christie
  2020-09-03  3:01 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Christie @ 2020-09-01 17:55 UTC (permalink / raw)
  To: Varun Prakash, martin.petersen
  Cc: linux-scsi, target-devel, bvanassche, nab, stable

On 8/25/20 7:35 AM, Varun Prakash wrote:
> Current code does not consider 'page_off' in data digest
> calculation, to fix this add a local variable 'first_sg' and
> set first_sg.offset to sg->offset + page_off.
> 
> Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Varun Prakash <varun@chelsio.com>
> ---
>  drivers/target/iscsi/iscsi_target.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index c968961..2ec778e 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -1389,14 +1389,27 @@ static u32 iscsit_do_crypto_hash_sg(
>  	sg = cmd->first_data_sg;
>  	page_off = cmd->first_data_sg_off;
>  
> +	if (data_length && page_off) {
> +		struct scatterlist first_sg;
> +		u32 len = min_t(u32, data_length, sg->length - page_off);
> +
> +		sg_init_table(&first_sg, 1);
> +		sg_set_page(&first_sg, sg_page(sg), len, sg->offset + page_off);
> +
> +		ahash_request_set_crypt(hash, &first_sg, NULL, len);
> +		crypto_ahash_update(hash);
> +
> +		data_length -= len;
> +		sg = sg_next(sg);
> +	}
> +
>  	while (data_length) {
> -		u32 cur_len = min_t(u32, data_length, (sg->length - page_off));
> +		u32 cur_len = min_t(u32, data_length, sg->length);
>  
>  		ahash_request_set_crypt(hash, sg, NULL, cur_len);
>  		crypto_ahash_update(hash);
>  
>  		data_length -= cur_len;
> -		page_off = 0;
>  		/* iscsit_map_iovec has already checked for invalid sg pointers */
>  		sg = sg_next(sg);
>  	}
> 

Looks ok to me.

Reviewed-by: Mike Christie <michael.christie@oralce.com>

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

* Re: [PATCH] scsi: target: iscsi: Fix data digest calculation
  2020-08-25 12:47 [PATCH] scsi: target: iscsi: Fix data digest calculation Varun Prakash
  2020-09-01 17:55 ` Mike Christie
@ 2020-09-03  3:01 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2020-09-03  3:01 UTC (permalink / raw)
  To: Varun Prakash
  Cc: Martin K . Petersen, linux-scsi, bvanassche, stable,
	michael.christie, nab, target-devel

On Tue, 25 Aug 2020 18:05:10 +0530, Varun Prakash wrote:

> Current code does not consider 'page_off' in data digest
> calculation, to fix this add a local variable 'first_sg' and
> set first_sg.offset to sg->offset + page_off.

Applied to 5.9/scsi-fixes, thanks!

[1/1] scsi: target: iscsi: Fix data digest calculation
      https://git.kernel.org/mkp/scsi/c/5528d03183fe

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-09-03  3:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 12:47 [PATCH] scsi: target: iscsi: Fix data digest calculation Varun Prakash
2020-09-01 17:55 ` Mike Christie
2020-09-03  3:01 ` Martin K. Petersen

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).