All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <mchristi@redhat.com>
To: Laura Abbott <labbott@redhat.com>,
	"Nicholas A. Bellinger" <nab@linux-iscsi.org>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Hannes Reinecke <hare@suse.com>
Cc: target-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Maurizio Lombardi <mlombard@redhat.com>
Subject: Re: [PATCH] iscsi-target: Don't use stack buffer for scatterlist
Date: Thu, 23 Aug 2018 05:11:21 +0000	[thread overview]
Message-ID: <5B7E41F9.4070101@redhat.com> (raw)
In-Reply-To: <20180822173709.5886-1-labbott@redhat.com>

ccing Maurizio because he was working on the same issue.

On 08/22/2018 12:37 PM, Laura Abbott wrote:
> Fedora got a bug report of a crash with iSCSI:
> 
> kernel BUG at include/linux/scatterlist.h:143!
> ...
> RIP: 0010:iscsit_do_crypto_hash_buf+0x154/0x180 [iscsi_target_mod]
> ...
>  Call Trace:
>   ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod]
>   iscsit_get_rx_pdu+0x4cd/0xa90 [iscsi_target_mod]
>   ? native_sched_clock+0x3e/0xa0
>   ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod]
>   iscsi_target_rx_thread+0x81/0xf0 [iscsi_target_mod]
>   kthread+0x120/0x140
>   ? kthread_create_worker_on_cpu+0x70/0x70
>   ret_from_fork+0x3a/0x50
> 
> This is a BUG_ON for using a stack buffer with a scatterlist.
> There are two cases that trigger this bug. Switch to using a
> dynamically allocated buffer for one case and do not assign
> a NULL buffer in another case.
> 
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id\x1615258
> Signed-off-by: Laura Abbott <labbott@redhat.com>
> ---
>  drivers/target/iscsi/iscsi_target.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 8e223799347a..8b40f0e99e2c 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -1419,7 +1419,8 @@ static void iscsit_do_crypto_hash_buf(struct ahash_request *hash,
>  
>  	sg_init_table(sg, ARRAY_SIZE(sg));
>  	sg_set_buf(sg, buf, payload_length);
> -	sg_set_buf(sg + 1, pad_bytes, padding);
> +	if (padding)
> +		sg_set_buf(sg + 1, pad_bytes, padding);
>  
>  	ahash_request_set_crypt(hash, sg, data_crc, payload_length + padding);
>  
> @@ -3913,10 +3914,14 @@ static bool iscsi_target_check_conn_state(struct iscsi_conn *conn)
>  static void iscsit_get_rx_pdu(struct iscsi_conn *conn)
>  {
>  	int ret;
> -	u8 buffer[ISCSI_HDR_LEN], opcode;
> +	u8 *buffer, opcode;
>  	u32 checksum = 0, digest = 0;
>  	struct kvec iov;
>  
> +	buffer = kmalloc_array(ISCSI_HDR_LEN, sizeof(*buffer), GFP_KERNEL);
> +	if (!buffer)
> +		return;
> +
>  	while (!kthread_should_stop()) {
>  		/*
>  		 * Ensure that both TX and RX per connection kthreads
> @@ -3985,6 +3990,8 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn)
>  		if (ret < 0)
>  			return;
>  	}

You need to also change all the returns to breaks between the kmalloc
above and kfree here.

> +	kfree(buffer);
>  }
>  
>  int iscsi_target_rx_thread(void *arg)
> 

WARNING: multiple messages have this Message-ID (diff)
From: Mike Christie <mchristi@redhat.com>
To: Laura Abbott <labbott@redhat.com>,
	"Nicholas A. Bellinger" <nab@linux-iscsi.org>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Hannes Reinecke <hare@suse.com>
Cc: target-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Maurizio Lombardi <mlombard@redhat.com>
Subject: Re: [PATCH] iscsi-target: Don't use stack buffer for scatterlist
Date: Thu, 23 Aug 2018 00:11:21 -0500	[thread overview]
Message-ID: <5B7E41F9.4070101@redhat.com> (raw)
In-Reply-To: <20180822173709.5886-1-labbott@redhat.com>

ccing Maurizio because he was working on the same issue.

On 08/22/2018 12:37 PM, Laura Abbott wrote:
> Fedora got a bug report of a crash with iSCSI:
> 
> kernel BUG at include/linux/scatterlist.h:143!
> ...
> RIP: 0010:iscsit_do_crypto_hash_buf+0x154/0x180 [iscsi_target_mod]
> ...
>  Call Trace:
>   ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod]
>   iscsit_get_rx_pdu+0x4cd/0xa90 [iscsi_target_mod]
>   ? native_sched_clock+0x3e/0xa0
>   ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod]
>   iscsi_target_rx_thread+0x81/0xf0 [iscsi_target_mod]
>   kthread+0x120/0x140
>   ? kthread_create_worker_on_cpu+0x70/0x70
>   ret_from_fork+0x3a/0x50
> 
> This is a BUG_ON for using a stack buffer with a scatterlist.
> There are two cases that trigger this bug. Switch to using a
> dynamically allocated buffer for one case and do not assign
> a NULL buffer in another case.
> 
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1615258
> Signed-off-by: Laura Abbott <labbott@redhat.com>
> ---
>  drivers/target/iscsi/iscsi_target.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
> index 8e223799347a..8b40f0e99e2c 100644
> --- a/drivers/target/iscsi/iscsi_target.c
> +++ b/drivers/target/iscsi/iscsi_target.c
> @@ -1419,7 +1419,8 @@ static void iscsit_do_crypto_hash_buf(struct ahash_request *hash,
>  
>  	sg_init_table(sg, ARRAY_SIZE(sg));
>  	sg_set_buf(sg, buf, payload_length);
> -	sg_set_buf(sg + 1, pad_bytes, padding);
> +	if (padding)
> +		sg_set_buf(sg + 1, pad_bytes, padding);
>  
>  	ahash_request_set_crypt(hash, sg, data_crc, payload_length + padding);
>  
> @@ -3913,10 +3914,14 @@ static bool iscsi_target_check_conn_state(struct iscsi_conn *conn)
>  static void iscsit_get_rx_pdu(struct iscsi_conn *conn)
>  {
>  	int ret;
> -	u8 buffer[ISCSI_HDR_LEN], opcode;
> +	u8 *buffer, opcode;
>  	u32 checksum = 0, digest = 0;
>  	struct kvec iov;
>  
> +	buffer = kmalloc_array(ISCSI_HDR_LEN, sizeof(*buffer), GFP_KERNEL);
> +	if (!buffer)
> +		return;
> +
>  	while (!kthread_should_stop()) {
>  		/*
>  		 * Ensure that both TX and RX per connection kthreads
> @@ -3985,6 +3990,8 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn)
>  		if (ret < 0)
>  			return;
>  	}

You need to also change all the returns to breaks between the kmalloc
above and kfree here.

> +	kfree(buffer);
>  }
>  
>  int iscsi_target_rx_thread(void *arg)
> 


  reply	other threads:[~2018-08-23  5:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 17:37 [PATCH] iscsi-target: Don't use stack buffer for scatterlist Laura Abbott
2018-08-22 17:37 ` Laura Abbott
2018-08-23  5:11 ` Mike Christie [this message]
2018-08-23  5:11   ` Mike Christie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5B7E41F9.4070101@redhat.com \
    --to=mchristi@redhat.com \
    --cc=bart.vanassche@wdc.com \
    --cc=hare@suse.com \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlombard@redhat.com \
    --cc=nab@linux-iscsi.org \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.