lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1347041553.4162.628.camel@haakon2.linux-iscsi.org>
Date:	Fri, 07 Sep 2012 11:12:33 -0700
From:	"Nicholas A. Bellinger" <nab@...ux-iscsi.org>
To:	Paolo Bonzini <pbonzini@...hat.com>
Cc:	linux-kernel@...r.kernel.org, target-devel@...r.kernel.org,
	hch@....de, roland@...nel.org
Subject: Re: [PATCH 04/11] target: support zero-size allocation lengths in
 transport_kmap_data_sg

On Fri, 2012-09-07 at 17:30 +0200, Paolo Bonzini wrote:
> In order to support zero-size allocation lengths, do not assert
> that we have a scatterlist until after checking cmd->data_length.
> 
> But once we do this, we can have two cases of transport_kmap_data_sg
> returning NULL: a zero-size allocation length, or an out-of-memory
> condition.  Report the latter using sense codes, so that the SCSI
> command that triggered it will fail.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@...hat.com>
> ---

Applied to master for-3.6.

Nice work Paolo!

>  drivers/target/target_core_transport.c |   13 +++++++++----
>  1 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
> index 2e55aa9..8facb74 100644
> --- a/drivers/target/target_core_transport.c
> +++ b/drivers/target/target_core_transport.c
> @@ -2185,7 +2185,6 @@ void *transport_kmap_data_sg(struct se_cmd *cmd)
>  	struct page **pages;
>  	int i;
>  
> -	BUG_ON(!sg);
>  	/*
>  	 * We need to take into account a possible offset here for fabrics like
>  	 * tcm_loop who may be using a contig buffer from the SCSI midlayer for
> @@ -2193,13 +2192,17 @@ void *transport_kmap_data_sg(struct se_cmd *cmd)
>  	 */
>  	if (!cmd->t_data_nents)
>  		return NULL;
> -	else if (cmd->t_data_nents == 1)
> +
> +	BUG_ON(!sg);
> +	if (cmd->t_data_nents == 1)
>  		return kmap(sg_page(sg)) + sg->offset;
>  
>  	/* >1 page. use vmap */
>  	pages = kmalloc(sizeof(*pages) * cmd->t_data_nents, GFP_KERNEL);
> -	if (!pages)
> +	if (!pages) {
> +		cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>  		return NULL;
> +	}
>  
>  	/* convert sg[] to pages[] */
>  	for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) {
> @@ -2208,8 +2211,10 @@ void *transport_kmap_data_sg(struct se_cmd *cmd)
>  
>  	cmd->t_data_vmap = vmap(pages, cmd->t_data_nents,  VM_MAP, PAGE_KERNEL);
>  	kfree(pages);
> -	if (!cmd->t_data_vmap)
> +	if (!cmd->t_data_vmap) {
> +		cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>  		return NULL;
> +	}
>  
>  	return cmd->t_data_vmap + cmd->t_data_sg[0].offset;
>  }


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ