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] [day] [month] [year] [list]
Message-Id: <1250611386.7335.8.camel@nimitz>
Date:	Tue, 18 Aug 2009 09:03:06 -0700
From:	Dave Hansen <dave@...ux.vnet.ibm.com>
To:	David Rientjes <rientjes@...gle.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org
Subject: Re: [patch 1/3] flex_array: fix get function for elements in base
 starting at non-zero

On Mon, 2009-08-17 at 16:46 -0700, David Rientjes wrote:
> If all array elements fit into the base structure and data is copied
> using flex_array_put() starting at a non-zero index, flex_array_get()
> will fail to return the data.
> 
> This fixes the bug by only checking for NULL parts when all elements do
> not fit in the base structure when flex_array_get() is used.  Otherwise,
> fa_element_to_part_nr() will always be 0 since there are no parts
> structures needed and such element may never have been put.  Thus, it
> will remain NULL due to the kzalloc() of the base.
> 
> Additionally, flex_array_put() now only checks for a NULL part when all
> elements do not fit in the base structure.  This is otherwise unnecessary
> since the base structure is guaranteed to exist (or we would have already
> hit a NULL pointer).
> 
> Cc: Dave Hansen <dave@...ux.vnet.ibm.com>
> Signed-off-by: David Rientjes <rientjes@...gle.com>
> ---
>  lib/flex_array.c |   14 ++++++++------
>  1 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/flex_array.c b/lib/flex_array.c
> --- a/lib/flex_array.c
> +++ b/lib/flex_array.c
> @@ -198,10 +198,11 @@ int flex_array_put(struct flex_array *fa, int element_nr, void *src, gfp_t flags
>  		return -ENOSPC;
>  	if (elements_fit_in_base(fa))
>  		part = (struct flex_array_part *)&fa->parts[0];
> -	else
> +	else {
>  		part = __fa_get_part(fa, part_nr, flags);
> -	if (!part)
> -		return -ENOMEM;
> +		if (!part)
> +			return -ENOMEM;
> +	}
>  	dst = &part->elements[index_inside_part(fa, element_nr)];
>  	memcpy(dst, src, fa->element_size);
>  	return 0;
> @@ -257,11 +258,12 @@ void *flex_array_get(struct flex_array *fa, int element_nr)
> 
>  	if (element_nr >= fa->total_nr_elements)
>  		return NULL;
> -	if (!fa->parts[part_nr])
> -		return NULL;
>  	if (elements_fit_in_base(fa))
>  		part = (struct flex_array_part *)&fa->parts[0];
> -	else
> +	else {
>  		part = fa->parts[part_nr];
> +		if (!part)
> +			return NULL;
> +	}
>  	return &part->elements[index_inside_part(fa, element_nr)];
>  }

This is fine with me, and fixes the bug you describe.

-- 

Signed-off-by: Dave Hansen <dave@...ux.vnet.ibm.com>

-- Dave

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