Re: [PATCH] tmpfs: security xattr setting on inode creation

From: Sakkinen, Jarkko
Date: Tue Feb 28 2012 - 00:51:25 EST


On Tue, Feb 28, 2012 at 6:10 AM, Hugh Dickins <hughd@xxxxxxxxxx> wrote:
> On Tue, 28 Feb 2012, Ware, Ryan R wrote:
>> On Tue, Feb 28, 2012 at 7:46 AM, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>wrote:
>> > On Fri, 24 Feb 2012 19:19:22 -0800 (PST)
>> > Hugh Dickins <hughd@xxxxxxxxxx> wrote:
>> >...
>> > > + Â Â Â Â Â Â if (!new_xattr->name) {
>> > > + Â Â Â Â Â Â Â Â Â Â kfree(new_xattr);
>> > > + Â Â Â Â Â Â Â Â Â Â return -ENOMEM;
>> > > + Â Â Â Â Â Â }
>> > > +
>> > > + Â Â Â Â Â Â memcpy(new_xattr->name, XATTR_SECURITY_PREFIX,
>> > > + Â Â Â Â Â Â Â Â Â ÂXATTR_SECURITY_PREFIX_LEN);
>> > > + Â Â Â Â Â Â memcpy(new_xattr->name + XATTR_SECURITY_PREFIX_LEN,
>> > > + Â Â Â Â Â Â Â Â Â Âxattr->name, len);
>> > > +
>> > > + Â Â Â Â Â Â spin_lock(&info->lock);
>> > > + Â Â Â Â Â Â list_add(&new_xattr->list, &info->xattr_list);
>> > > + Â Â Â Â Â Â spin_unlock(&info->lock);
>> > > + Â Â }
>> > > +
>> > > + Â Â return 0;
>> > > +}
>> >
>> > So if there's a kmalloc failure partway through the array, we leave a
>> > partially xattrified inode in place.
>> >
>> > Are we sure this is OK?
>> >
>>
>> I'm guessing Jarkko can clean that up a bit. ÂIt wouldn't be a good idea to
>> leave inaccurate data structures laying around during failure cases.
>
> Andrew raises a good concern, but Jarkko got it just right and no
> change is needed: any xattrs already allocated are properly linked
> on info->xattr_list, then when security_inode_init_security() fails
> (with an error other than EOPNOTSUPP) the failing inode is iput(),
> which ends up in shmem_evict_inode(), which kfree()s those xattrs
> (and their names) on info->xattr_list.

Yeah, that's how I understood it too. These the are places where
security_inode_init_security() is called:

- http://lxr.free-electrons.com/source/mm/shmem.c#L1459
- http://lxr.free-electrons.com/source/mm/shmem.c#L1590

>
> Hugh

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