Re: [PATCH 2/2 linux-next] FS/HFSPLUS: move xattr_name allocation in hfsplus_setxattr()

From: Fabian Frederick
Date: Tue Mar 03 2015 - 13:04:30 EST




> On 02 March 2015 at 23:25 Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> On Fri, 27 Feb 2015 18:38:26 +0100 Fabian Frederick <fabf@xxxxxxxxx> wrote:
>
> > security/trusted/user/osx setxattr did the same
> > xattr_name initialization. Move that operation in hfsplus_setxattr().
> >
> > Tested with security/trusted/user getfattr/setfattr
> >
> > --- a/fs/hfsplus/xattr.c
> > +++ b/fs/hfsplus/xattr.c
> > @@ -424,6 +424,28 @@ static int copy_name(char *buffer, const char
> > *xattr_name, int name_len)
> >Â Â Âreturn len;
> >Â }
>
> > +int hfsplus_setxattr(struct dentry *dentry, const char *name,
> > +Â Â Â Â Â Â Â Â const void *value, size_t size, int flags,
> > +Â Â Â Â Â Â Â Â const char *prefix, size_t prefixlen)
> > +{
> > +Â Âchar *xattr_name;
> > +Â Âint res;
> > +
> > +Â Âif (!strcmp(name, ""))
> > +Â Â Â Â Â Âreturn -EINVAL;
> > +
> > +Â Âxattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
> > +Â Â Â Â Â ÂGFP_KERNEL);
> > +Â Âif (!xattr_name)
> > +Â Â Â Â Â Âreturn -ENOMEM;
> > +Â Âstrcpy(xattr_name, prefix);
> > +Â Âstrcpy(xattr_name + prefixlen, name);
>
> Can we use kasprintf(GFP_KERNEL, "%s%s", prefix, name) and zap `prefixlen'?
Of course :) Thanks Andrew, I'll send a small patchset for relevant filesystems.

Regards,
Fabian
>
> > +Â Âres = __hfsplus_setxattr(dentry->d_inode, xattr_name, value, size,
> > +Â Â Â Â Â Â Â Â Â Â Â Â Â Â flags);
> > +Â Âkfree(xattr_name);
> > +Â Âreturn res;
> > +}
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/