On Wed, Oct 17, 2012 at 08:41:15PM -0700, David Rientjes wrote:
> Commit 38f38657444d ("xattr: extract simple_xattr code from tmpfs") moved
> some code from tmpfs but introduced a subtle bug along the way.
> 
> If the name passed to simple_xattr_remove() does not exist in the list of
> xattrs, then it is possible to call kfree(new_xattr) when new_xattr is
> actually initialized to itself on the stack via uninitialized_var().
> 
> This causes a BUG() since the memory was not allocated via the slab
> allocator and was not bypassed through to the page allocator because it
> was too large.
> 
> Initialize the local variable to NULL so the kfree() never takes place.
> 
> Reported-by: Fengguang Wu <fengguang...@intel.com>
> Signed-off-by: David Rientjes <rient...@google.com>
> ---
>  fs/xattr.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/xattr.c b/fs/xattr.c
> --- a/fs/xattr.c
> +++ b/fs/xattr.c
> @@ -846,7 +846,7 @@ static int __simple_xattr_set(struct simple_xattrs 
> *xattrs, const char *name,
>                             const void *value, size_t size, int flags)
>  {
>       struct simple_xattr *xattr;
> -     struct simple_xattr *uninitialized_var(new_xattr);
> +     struct simple_xattr *new_xattr = NULL;
>       int err = 0;
>  
>       /* value == NULL means remove */

I think Sasha Levin was working on that (Cc'd) along with the smatch fix.
Anyway, __simple_xattr_set is too confusing and rewriting it is in my TODO list
which will shut up smatch too.

Acked-by: Aristeu Rozanski <a...@redhat.com>

-- 
Aristeu

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

Reply via email to