All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Heming Zhao <heming.zhao@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ocfs2: retain all security xattrs during inode creation
Date: Thu, 17 Sep 2026 09:34:51 +0800	[thread overview]
Message-ID: <2d65e5ee-7381-4230-baef-e5c34fb95806@linux.alibaba.com> (raw)
In-Reply-To: <aqqe10w7OONy6pcI@p15>



On 9/16/26 9:54 PM, Heming Zhao wrote:
> On Wed, Sep 16, 2026 at 08:02:58PM +0800, Joseph Qi wrote:
>> When creating a new inode, ocfs2_init_security_get() stores the
>> security xattr returned by the LSM framework in
>> ocfs2_security_xattr_info so that it can be written later within the
>> same transaction.  But ocfs2_initxattrs() only ever looks at the
>> first element of the xattr array, and it keeps the name as a bare
>> pointer into memory owned by the security layer instead of copying
>> it.  The value, by contrast, is already duplicated with kmemdup().
>>
>> With stacked LSMs, security_inode_init_security() provides one xattr
>> per LSM, so all labels but the first are silently dropped and never
>> written to disk, leaving newly created files without the security
>> xattrs the other LSMs rely on.
>>
>> The borrowed name is not an outright bug with the LSMs in tree
>> today: security_inode_init_security() frees only ->value once the
>> callback returns, and documents ->name as the attribute name
>> suffix, so the pointer stays valid for as long as ocfs2 uses it.
>> It is fragile though, as an LSM that allocates the name together
>> with the value would turn it into a use-after-free, so the rework
>> below copies the names as well.
>>
>> Fix this by storing copies of all the security xattrs: allocate an
>> array in ocfs2_initxattrs(), copy the names and values, account for
>> all of them in the credit calculations, and write each one in
>> ocfs2_init_security_set().
>>
>> While at it, switch the allocations from GFP_KERNEL to GFP_NOFS.
>> The callback runs in the inode creation path with the parent
>> directory locked, and the security layer allocates the very same
>> xattr array with GFP_NOFS, so direct reclaim must not be allowed to
>> recurse into the filesystem from here.
>>
>> Fixes: de3004c874e7 ("ocfs2: Switch to security_inode_init_security()")
>> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> 
> The code looks good to me.
> Reviewed-by: Heming Zhao <heming.zhao@suse.com>

Thanks, sashiko has review comments for the case of 512B block size:
https://sashiko.dev/#/patchset/20260916120258.3583355-1-joseph.qi@linux.alibaba.com?part=1

It looks simple and I'll address it in v2.

BTW, I've sent the update policy including cc ocfs2-devel, but It hasn't
been merged yet.

Thanks,
Joseph

      reply	other threads:[~2026-09-17  1:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 12:02 [PATCH] ocfs2: retain all security xattrs during inode creation Joseph Qi
2026-09-16 13:54 ` Heming Zhao
2026-09-17  1:34   ` Joseph Qi [this message]

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=2d65e5ee-7381-4230-baef-e5c34fb95806@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=daniel@iogearbox.net \
    --cc=heming.zhao@suse.com \
    --cc=jlbec@evilplan.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=ocfs2-devel@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.