mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void *
@ 2013-05-03 21:15 Geert Uytterhoeven
  2013-05-03 21:22 ` Geert Uytterhoeven
  2013-05-03 23:54 ` Nicholas A. Bellinger
  0 siblings, 2 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2013-05-03 21:15 UTC (permalink / raw)
  To: Nicholas A. Bellinger
  Cc: linux-scsi, target-devel, linux-kernel, Geert Uytterhoeven

Make the "buf" input param of iscsit_do_crypto_hash_buf() "const void *".
This allows to remove lots of casts in its callers.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/target/iscsi/iscsi_target.c |   57 ++++++++++++++---------------------
 1 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index ffbc6a9..721ecc5 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -1250,7 +1250,7 @@ static u32 iscsit_do_crypto_hash_sg(
 
 static void iscsit_do_crypto_hash_buf(
 	struct hash_desc *hash,
-	unsigned char *buf,
+	const void *buf,
 	u32 payload_length,
 	u32 padding,
 	u8 *pad_bytes,
@@ -2524,9 +2524,8 @@ static int iscsit_send_conn_drop_async_message(
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		cmd->tx_size += ISCSI_CRC_LEN;
 		pr_debug("Attaching CRC32C HeaderDigest to"
@@ -2662,9 +2661,8 @@ static int iscsit_send_datain(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)cmd->pdu, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->pdu,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		iov[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -2841,9 +2839,8 @@ iscsit_send_logout(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)&cmd->pdu[0], ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, &cmd->pdu[0],
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		iov[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -2900,9 +2897,8 @@ static int iscsit_send_unsolicited_nopin(
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		tx_size += ISCSI_CRC_LEN;
 		pr_debug("Attaching CRC32C HeaderDigest to"
@@ -2949,9 +2945,8 @@ iscsit_send_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		iov[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -3040,9 +3035,8 @@ static int iscsit_send_r2t(
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		cmd->iov_misc[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -3256,9 +3250,8 @@ static int iscsit_send_response(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)cmd->pdu, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->pdu,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		iov[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -3329,9 +3322,8 @@ iscsit_send_task_mgt_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		cmd->iov_misc[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -3504,9 +3496,8 @@ static int iscsit_send_text_rsp(
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		iov[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -3574,9 +3565,8 @@ static int iscsit_send_reject(
 	if (conn->conn_ops->HeaderDigest) {
 		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
 
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)hdr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)header_digest);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
 
 		iov[0].iov_len += ISCSI_CRC_LEN;
 		tx_size += ISCSI_CRC_LEN;
@@ -3585,9 +3575,8 @@ static int iscsit_send_reject(
 	}
 
 	if (conn->conn_ops->DataDigest) {
-		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
-				(unsigned char *)cmd->buf_ptr, ISCSI_HDR_LEN,
-				0, NULL, (u8 *)&cmd->data_crc);
+		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->buf_ptr,
+				ISCSI_HDR_LEN, 0, NULL, (u8 *)&cmd->data_crc);
 
 		iov[iov_count].iov_base = &cmd->data_crc;
 		iov[iov_count++].iov_len  = ISCSI_CRC_LEN;
-- 
1.7.0.4


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

* Re: [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void *
  2013-05-03 21:15 [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void * Geert Uytterhoeven
@ 2013-05-03 21:22 ` Geert Uytterhoeven
  2013-05-04  0:16   ` Nicholas A. Bellinger
  2013-05-03 23:54 ` Nicholas A. Bellinger
  1 sibling, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2013-05-03 21:22 UTC (permalink / raw)
  To: Nicholas A. Bellinger
  Cc: scsi, target-devel, linux-kernel, Geert Uytterhoeven

On Fri, May 3, 2013 at 11:15 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c

> @@ -3585,9 +3575,8 @@ static int iscsit_send_reject(
>         }
>
>         if (conn->conn_ops->DataDigest) {
> -               iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -                               (unsigned char *)cmd->buf_ptr, ISCSI_HDR_LEN,
> -                               0, NULL, (u8 *)&cmd->data_crc);
> +               iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->buf_ptr,
> +                               ISCSI_HDR_LEN, 0, NULL, (u8 *)&cmd->data_crc);

BTW, there are serious issues with casting pointers to u32s to pointers to u8s
for the last two output parameters of iscsit_do_crypto_hash_buf() (pad_bytes
and data_crc):
  1. It's not endian-safe,
  2. In many cases, the original u32 was not initialized at all, so the other 24
      bits contain garbage. This will cause 32-bit comparisons like

        if (checksum != data_crc)

     to fail in unpredictable ways.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void *
  2013-05-03 21:15 [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void * Geert Uytterhoeven
  2013-05-03 21:22 ` Geert Uytterhoeven
@ 2013-05-03 23:54 ` Nicholas A. Bellinger
  1 sibling, 0 replies; 5+ messages in thread
From: Nicholas A. Bellinger @ 2013-05-03 23:54 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: linux-scsi, target-devel, linux-kernel

On Fri, 2013-05-03 at 23:15 +0200, Geert Uytterhoeven wrote:
> Make the "buf" input param of iscsit_do_crypto_hash_buf() "const void *".
> This allows to remove lots of casts in its callers.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---

Applied to target-pending/queue.

Thanks Geert!

--nab

>  drivers/target/iscsi/iscsi_target.c |   57 ++++++++++++++---------------------
>  1 files changed, 23 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index ffbc6a9..721ecc5 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -1250,7 +1250,7 @@ static u32 iscsit_do_crypto_hash_sg(
>  
>  static void iscsit_do_crypto_hash_buf(
>  	struct hash_desc *hash,
> -	unsigned char *buf,
> +	const void *buf,
>  	u32 payload_length,
>  	u32 padding,
>  	u8 *pad_bytes,
> @@ -2524,9 +2524,8 @@ static int iscsit_send_conn_drop_async_message(
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		cmd->tx_size += ISCSI_CRC_LEN;
>  		pr_debug("Attaching CRC32C HeaderDigest to"
> @@ -2662,9 +2661,8 @@ static int iscsit_send_datain(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)cmd->pdu, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->pdu,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		iov[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -2841,9 +2839,8 @@ iscsit_send_logout(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)&cmd->pdu[0], ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, &cmd->pdu[0],
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		iov[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -2900,9 +2897,8 @@ static int iscsit_send_unsolicited_nopin(
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		tx_size += ISCSI_CRC_LEN;
>  		pr_debug("Attaching CRC32C HeaderDigest to"
> @@ -2949,9 +2945,8 @@ iscsit_send_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		iov[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -3040,9 +3035,8 @@ static int iscsit_send_r2t(
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		cmd->iov_misc[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -3256,9 +3250,8 @@ static int iscsit_send_response(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)cmd->pdu, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->pdu,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		iov[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -3329,9 +3322,8 @@ iscsit_send_task_mgt_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		cmd->iov_misc[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -3504,9 +3496,8 @@ static int iscsit_send_text_rsp(
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		iov[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -3574,9 +3565,8 @@ static int iscsit_send_reject(
>  	if (conn->conn_ops->HeaderDigest) {
>  		u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN];
>  
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)hdr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)header_digest);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest);
>  
>  		iov[0].iov_len += ISCSI_CRC_LEN;
>  		tx_size += ISCSI_CRC_LEN;
> @@ -3585,9 +3575,8 @@ static int iscsit_send_reject(
>  	}
>  
>  	if (conn->conn_ops->DataDigest) {
> -		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> -				(unsigned char *)cmd->buf_ptr, ISCSI_HDR_LEN,
> -				0, NULL, (u8 *)&cmd->data_crc);
> +		iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->buf_ptr,
> +				ISCSI_HDR_LEN, 0, NULL, (u8 *)&cmd->data_crc);
>  
>  		iov[iov_count].iov_base = &cmd->data_crc;
>  		iov[iov_count++].iov_len  = ISCSI_CRC_LEN;



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

* Re: [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void *
  2013-05-03 21:22 ` Geert Uytterhoeven
@ 2013-05-04  0:16   ` Nicholas A. Bellinger
  2013-05-05  9:35     ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Nicholas A. Bellinger @ 2013-05-04  0:16 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: scsi, target-devel, linux-kernel

On Fri, 2013-05-03 at 23:22 +0200, Geert Uytterhoeven wrote:
> On Fri, May 3, 2013 at 11:15 PM, Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
> > --- a/drivers/target/iscsi/iscsi_target.c
> > +++ b/drivers/target/iscsi/iscsi_target.c
> 
> > @@ -3585,9 +3575,8 @@ static int iscsit_send_reject(
> >         }
> >
> >         if (conn->conn_ops->DataDigest) {
> > -               iscsit_do_crypto_hash_buf(&conn->conn_tx_hash,
> > -                               (unsigned char *)cmd->buf_ptr, ISCSI_HDR_LEN,
> > -                               0, NULL, (u8 *)&cmd->data_crc);
> > +               iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->buf_ptr,
> > +                               ISCSI_HDR_LEN, 0, NULL, (u8 *)&cmd->data_crc);
> 
> BTW, there are serious issues with casting pointers to u32s to pointers to u8s
> for the last two output parameters of iscsit_do_crypto_hash_buf() (pad_bytes
> and data_crc):
>   1. It's not endian-safe,
>   2. In many cases, the original u32 was not initialized at all, so the other 24
>       bits contain garbage. This will cause 32-bit comparisons like
> 
>         if (checksum != data_crc)
> 
>      to fail in unpredictable ways.
> 

Ugh, I can see how that would be problematic for BE..

Changing these to use u8 data_crc[ISCSI_DIGEST_SIZE] and
pad_bytes[ISCSI_PAD_LEN] now, and will post a patch soon.

Thanks again,

--nab



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

* Re: [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void *
  2013-05-04  0:16   ` Nicholas A. Bellinger
@ 2013-05-05  9:35     ` Geert Uytterhoeven
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2013-05-05  9:35 UTC (permalink / raw)
  To: Nicholas A. Bellinger; +Cc: scsi, target-devel, linux-kernel

On Sat, May 4, 2013 at 2:16 AM, Nicholas A. Bellinger
<nab@linux-iscsi.org> wrote:
>> BTW, there are serious issues with casting pointers to u32s to pointers to u8s
>> for the last two output parameters of iscsit_do_crypto_hash_buf() (pad_bytes
>> and data_crc):
>>   1. It's not endian-safe,
>>   2. In many cases, the original u32 was not initialized at all, so the other 24
>>       bits contain garbage. This will cause 32-bit comparisons like
>>
>>         if (checksum != data_crc)
>>
>>      to fail in unpredictable ways.

Upon closer look, this issue is moot. But the code is confusing for the casual
reader, due to the casts
Changing the "u8 *pad_bytes" parameters to "const void *pad_bytes"
(which is what sg_init_one() takes anyway) should allow you to get rid of the
casts for pad_bytes.
For data_crc, the issue is that crypto_hash_final() takes a "u8 *out",
instead of a "void *out". Still, it's better to move the cast inside
iscsit_do_crypto_hash_buf(), so it's in one place only.

> Ugh, I can see how that would be problematic for BE..
>
> Changing these to use u8 data_crc[ISCSI_DIGEST_SIZE] and
> pad_bytes[ISCSI_PAD_LEN] now, and will post a patch soon.

That's another good idea.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2013-05-05  9:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-03 21:15 [PATCH] iscsi-target: Make buf param of iscsit_do_crypto_hash_buf() const void * Geert Uytterhoeven
2013-05-03 21:22 ` Geert Uytterhoeven
2013-05-04  0:16   ` Nicholas A. Bellinger
2013-05-05  9:35     ` Geert Uytterhoeven
2013-05-03 23:54 ` Nicholas A. Bellinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®