From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Roberto Sassu <roberto.sassu@huawei.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Steve French <smfrench@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
CIFS <linux-cifs@vger.kernel.org>,
Paulo Alcantara <pc@manguebit.com>,
Christian Brauner <christian@brauner.io>,
Mimi Zohar <zohar@linux.ibm.com>,
Paul Moore <paul@paul-moore.com>,
"linux-integrity@vger.kernel.org"
<linux-integrity@vger.kernel.org>,
"linux-security-module@vger.kernel.org"
<linux-security-module@vger.kernel.org>
Subject: Re: kernel crash in mknod
Date: Thu, 28 Mar 2024 13:24:25 +0200 [thread overview]
Message-ID: <4ad908dc-ddc5-492e-8ed4-d304156b5810@huaweicloud.com> (raw)
In-Reply-To: <20240328-raushalten-krass-cb040068bde9@brauner>
On 3/28/2024 12:08 PM, Christian Brauner wrote:
> On Thu, Mar 28, 2024 at 12:53:40PM +0200, Roberto Sassu wrote:
>> On 3/26/2024 12:40 PM, Christian Brauner wrote:
>>>> we can change the parameter of security_path_post_mknod() from
>>>> dentry to inode?
>>>
>>> If all current callers only operate on the inode then it seems the best
>>> to only pass the inode. If there's some reason someone later needs a
>>> dentry the hook can always be changed.
>>
>> Ok, so the crash is likely caused by:
>>
>> void security_path_post_mknod(struct mnt_idmap *idmap, struct dentry
>> *dentry)
>> {
>> if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
>>
>> I guess we can also simply check if there is an inode attached to the
>> dentry, to minimize the changes. I can do both.
>>
>> More technical question, do I need to do extra checks on the dentry before
>> calling security_path_post_mknod()?
>
> Why do you need the dentry? The two users I see are ima in [1] and evm in [2].
> Both of them don't care about the dentry. They only care about the
> inode. So why is that hook not just:
Sure, I can definitely do that. Seems an easier fix to do an extra check
in security_path_post_mknod(), rather than changing the parameter
everywhere.
Next time, when we introduce new LSM hooks we can try to introduce more
specific parameters.
Also, consider that the pre hook security_path_mknod() has the dentry as
parameter. For symmetry, we could keep it in the post hook.
What I was also asking is if I can still call d_backing_inode() on the
dentry without extra checks, and avoiding the IS_PRIVATE() check if the
former returns NULL.
> diff --git a/security/security.c b/security/security.c
> index 7e118858b545..025689a7e912 100644
> --- a/security/security.c
> +++ b/security/security.c
> @@ -1799,11 +1799,11 @@ EXPORT_SYMBOL(security_path_mknod);
> *
> * Update inode security field after a file has been created.
> */
> -void security_path_post_mknod(struct mnt_idmap *idmap, struct dentry *dentry)
> +void security_inode_post_mknod(struct mnt_idmap *idmap, struct inode *inode)
> {
> - if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
> + if (unlikely(IS_PRIVATE(inode)))
> return;
> - call_void_hook(path_post_mknod, idmap, dentry);
> + call_void_hook(path_post_mknod, idmap, inode);
> }
>
> /**
>
> And one another thing I'd like to point out is that the security hook is
> called "security_path_post_mknod()" while the evm and ima hooks are
> called evm_post_path_mknod() and ima_post_path_mknod() respectively. In
> other words:
>
> git grep _path_post_mknod() doesn't show the implementers of that hook
> which is rather unfortunate. It would be better if the pattern were:
>
> <specific LSM>_$some_$ordered_$words()
I know, yes. Didn't want to change just yet since people familiar with
the IMA code know the current function name. I don't see any problem to
rename the functions.
Thanks
Roberto
> [1]:
> static void evm_post_path_mknod(struct mnt_idmap *idmap, struct dentry *dentry)
> {
> struct inode *inode = d_backing_inode(dentry);
> struct evm_iint_cache *iint = evm_iint_inode(inode);
>
> if (!S_ISREG(inode->i_mode))
> return;
>
> if (iint)
> iint->flags |= EVM_NEW_FILE;
> }
>
> [2]:
> static void ima_post_path_mknod(struct mnt_idmap *idmap, struct dentry *dentry)
> {
> struct ima_iint_cache *iint;
> struct inode *inode = dentry->d_inode;
> int must_appraise;
>
> if (!ima_policy_flag || !S_ISREG(inode->i_mode))
> return;
>
> must_appraise = ima_must_appraise(idmap, inode, MAY_ACCESS,
> FILE_CHECK);
> if (!must_appraise)
> return;
>
> /* Nothing to do if we can't allocate memory */
> iint = ima_inode_get(inode);
> if (!iint)
> return;
>
> /* needed for re-opening empty files */
> iint->flags |= IMA_NEW_FILE;
> }
>
>
>
>>
>> Thanks
>>
>> Roberto
>>
>>> For bigger changes it's also worthwhile if the object that's passed down
>>> into the hook-based LSM layer is as specific as possible. If someone
>>> does a change that affects lifetime rules of mounts then any hook that
>>> takes a struct path argument that's unused means going through each LSM
>>> that implements the hook only to find out it's not actually used.
>>> Similar for dentry vs inode imho.
>>
next prev parent reply other threads:[~2024-03-28 11:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-24 5:00 kernel crash in mknod Steve French
2024-03-24 5:46 ` Al Viro
2024-03-24 6:31 ` Al Viro
2024-03-24 16:50 ` Roberto Sassu
2024-03-24 21:02 ` Al Viro
2024-03-25 16:06 ` Christian Brauner
2024-03-25 17:18 ` Roberto Sassu
2024-03-26 11:40 ` Christian Brauner
2024-03-26 12:53 ` Paul Moore
2024-03-28 10:53 ` Roberto Sassu
2024-03-28 11:08 ` Christian Brauner
2024-03-28 11:24 ` Roberto Sassu [this message]
2024-03-28 12:07 ` Christian Brauner
2024-03-28 13:03 ` Paul Moore
2024-03-28 12:43 ` Paul Moore
2024-03-25 17:21 ` Paul Moore
[not found] ` <CAH2r5muL4NEwLxq_qnPOCTHunLB_vmDA-1jJ152POwBv+aTcXg@mail.gmail.com>
2024-03-25 19:54 ` Al Viro
2024-03-25 20:46 ` Al Viro
2024-03-25 20:47 ` Paulo Alcantara
2024-03-25 21:13 ` Al Viro
2024-03-25 21:31 ` Paulo Alcantara
2024-03-25 17:05 ` Paul Moore
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=4ad908dc-ddc5-492e-8ed4-d304156b5810@huaweicloud.com \
--to=roberto.sassu@huaweicloud.com \
--cc=brauner@kernel.org \
--cc=christian@brauner.io \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=pc@manguebit.com \
--cc=roberto.sassu@huawei.com \
--cc=smfrench@gmail.com \
--cc=viro@zeniv.linux.org.uk \
--cc=zohar@linux.ibm.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).