From: Song Liu <songliubraving@meta.com>
To: Dave Chinner <david@fromorbit.com>
Cc: Song Liu <song@kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
"linux-xfs@vger.kernel.org" <linux-xfs@vger.kernel.org>,
"linux-security-module@vger.kernel.org"
<linux-security-module@vger.kernel.org>,
"willy@infradead.org" <willy@infradead.org>,
"corbet@lwn.net" <corbet@lwn.net>, Chris Mason <clm@meta.com>,
Josef Bacik <josef@toxicpanda.com>,
"dsterba@suse.com" <dsterba@suse.com>,
"brauner@kernel.org" <brauner@kernel.org>,
"jack@suse.cz" <jack@suse.cz>, "cem@kernel.org" <cem@kernel.org>,
"djwong@kernel.org" <djwong@kernel.org>,
"paul@paul-moore.com" <paul@paul-moore.com>,
"jmorris@namei.org" <jmorris@namei.org>,
"serge@hallyn.com" <serge@hallyn.com>,
"fdmanana@suse.com" <fdmanana@suse.com>,
"johannes.thumshirn@wdc.com" <johannes.thumshirn@wdc.com>,
Kernel Team <kernel-team@meta.com>
Subject: Re: [RFC v2] lsm: fs: Use inode_free_callback to free i_security in RCU callback
Date: Thu, 19 Dec 2024 03:03:46 +0000 [thread overview]
Message-ID: <EEEFDE10-07B5-47B5-BE6E-DAC2FE2B7576@fb.com> (raw)
In-Reply-To: <Z2N7Ibxnmm-KEvea@dread.disaster.area>
Hi Dave,
Thanks for your comments!
> On Dec 18, 2024, at 5:47 PM, Dave Chinner <david@fromorbit.com> wrote:
>
> On Wed, Dec 18, 2024 at 01:16:15PM -0800, Song Liu wrote:
>> inode->i_security needes to be freed from RCU callback. A rcu_head was
>> added to i_security to call the RCU callback. However, since struct inode
>> already has i_rcu, the extra rcu_head is wasteful. Specifically, when any
>> LSM uses i_security, a rcu_head (two pointers) is allocated for each
>> inode.
>>
>> Rename i_callback to inode_free_callback and call security_inode_free_rcu
>> from it to free i_security so that a rcu_head is saved for each inode.
>> Special care are needed for file systems that provide a destroy_inode()
>> callback, but not a free_inode() callback. Specifically, the following
>> logic are added to handle such cases:
>>
>> - XFS recycles inode after destroy_inode. The inodes are freed from
>> recycle logic. Let xfs_inode_free_callback() call inode_free_callback.
>
> NACK. That's a massive layering violation.
>
> LSMs are VFS layer functionality. They *must* be removed from the
> VFS inode before ->destroy_inode() is called. If a filesystem
> supplies ->destroy_inode(), then it -owns- the inode exclusively
> from that point onwards. All VFS and 3rd party stuff hanging off the
> inode must be removed from the inode before ->destroy_inode() is
> called.
To be honest, I am not sure this rule is true. Most filesystems
provide a free_inode() callback:
$ grep "\.free_inode.*=" fs/*/*.c | wc
54 221 2808
For all these cases, VFS layer is still in charge of freeing the
inode after a RCU grace period. From vfs.rst:
``free_inode``
this method is called from RCU callback. If you use call_rcu()
in ->destroy_inode to free 'struct inode' memory, then it's
better to release memory in this method.
> Them's the rules, and hacking around LSM object allocation/freeing
> to try to handle how filesystems manage inodes -underneath- the VFS
> is just asking for problems. LSM object management needs to be
> handled entirely by the generic LSM VFS hooks, not tightly coupled
> to VFS and/or low level filesystem inode lifecycle management.
Unfortunately, many filesystems already call various security_*
hooks directly:
$ grep "include <linux/security.h>" fs/*/*.c -rI | wc
46 92 2144
(46 files in various filesystems call into the security layer.)
Therefore, I don't feel this change alone is massive layering
violation. Instead, it is probably making existing layering
violation a bit worse. I personally think it is not making
things too worse. On the other hand, saving a rcu_head per
inode is non-trivial savings.
It worth note that many systems allocate memory on i_security,
even the user is not using any LSM. This is because some LSMs
can only be disabled at compile time. Distro kernels are more
likely to enable them to fit various users' needs. Therefore,
the i_security->rcu_head "tax" is not somebody else's problem.
We probably just don't know we are paying it.
That being said, I am not too attached to this change. If folks
think allocating an extra rcu_head per inode is the better
trade-off. I am OK with that answer. I put "RFC" there for
comments.
I hope this makes sense.
Thanks again for your comments.
Song
prev parent reply other threads:[~2024-12-19 3:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 21:16 Song Liu
2024-12-19 1:47 ` Dave Chinner
2024-12-19 3:03 ` Song Liu [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=EEEFDE10-07B5-47B5-BE6E-DAC2FE2B7576@fb.com \
--to=songliubraving@meta.com \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=clm@meta.com \
--cc=corbet@lwn.net \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=johannes.thumshirn@wdc.com \
--cc=josef@toxicpanda.com \
--cc=kernel-team@meta.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=song@kernel.org \
--cc=willy@infradead.org \
/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
all inboxes | Powered by JetHome®