linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Sakkinen, Jarkko" <jarkko.sakkinen@intel.com>
To: Hugh Dickins <hughd@google.com>
Cc: "Ware, Ryan R" <ryan.r.ware@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	James Morris <jmorris@namei.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org
Subject: Re: [PATCH] tmpfs: security xattr setting on inode creation
Date: Tue, 28 Feb 2012 07:51:26 +0200	[thread overview]
Message-ID: <CADjiTvCViw4tZ9HvH-s8a2_8uW82BwfXz3PLQmEEVAVC0PbDwg@mail.gmail.com> (raw)
In-Reply-To: <alpine.LSU.2.00.1202272003380.1574@eggly.anvils>

On Tue, Feb 28, 2012 at 6:10 AM, Hugh Dickins <hughd@google.com> wrote:
> On Tue, 28 Feb 2012, Ware, Ryan R wrote:
>> On Tue, Feb 28, 2012 at 7:46 AM, Andrew Morton <akpm@linux-foundation.org>wrote:
>> > On Fri, 24 Feb 2012 19:19:22 -0800 (PST)
>> > Hugh Dickins <hughd@google.com> 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

  reply	other threads:[~2012-02-28  5:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23  9:46 [PATCH] tmpfs: security xattr setting on inode creation Jarkko Sakkinen
2012-02-24  8:13 ` James Morris
2012-02-25  3:19   ` Hugh Dickins
2012-02-25  7:03     ` Sakkinen, Jarkko
2012-02-27 22:46     ` Andrew Morton
2012-02-28  3:46       ` Ware, Ryan R
     [not found]       ` <CAGGTEhPQ6OLgqZbbAwE=3Xj8qE2iNhLOk5LdkGU13WxbY=qb2w@mail.gmail.com>
2012-02-28  4:10         ` Hugh Dickins
2012-02-28  5:51           ` Sakkinen, Jarkko [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-02-22  7:48 Jarkko Sakkinen
2012-02-22 17:46 ` Sakkinen, Jarkko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADjiTvCViw4tZ9HvH-s8a2_8uW82BwfXz3PLQmEEVAVC0PbDwg@mail.gmail.com \
    --to=jarkko.sakkinen@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=ryan.r.ware@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).