From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: Mimi Zohar <zohar@linux.ibm.com>, Paul Moore <paul@paul-moore.com>
Cc: dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com,
jmorris@namei.org, serge@hallyn.com,
linux-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
ebpqwerty472123@gmail.com,
Roberto Sassu <roberto.sassu@huawei.com>
Subject: Re: [PATCH 2/3] ima: Ensure lock is held when setting iint pointer in inode security blob
Date: Wed, 16 Oct 2024 15:08:16 +0200 [thread overview]
Message-ID: <33fefedfbdc44ea9c58a14030d58bff20b2c7d86.camel@huaweicloud.com> (raw)
In-Reply-To: <3ab95195af7db9d2bd482f46a69305f2f386cc32.camel@huaweicloud.com>
On Mon, 2024-10-14 at 13:45 +0200, Roberto Sassu wrote:
> On Fri, 2024-10-11 at 15:30 -0400, Mimi Zohar wrote:
> > On Wed, 2024-10-09 at 17:43 +0200, Roberto Sassu wrote:
> > > On Wed, 2024-10-09 at 11:41 -0400, Paul Moore wrote:
> > > > On Tue, Oct 8, 2024 at 12:57 PM Roberto Sassu
> > > > <roberto.sassu@huaweicloud.com> wrote:
> > > > >
> > > > > From: Roberto Sassu <roberto.sassu@huawei.com>
> > > > >
> > > > > IMA stores a pointer of the ima_iint_cache structure, containing integrity
> > > > > metadata, in the inode security blob. However, check and assignment of this
> > > > > pointer is not atomic, and it might happen that two tasks both see that the
> > > > > iint pointer is NULL and try to set it, causing a memory leak.
> > > > >
> > > > > Ensure that the iint check and assignment is guarded, by adding a lockdep
> > > > > assertion in ima_inode_get().
> > > > >
> > > > > Consequently, guard the remaining ima_inode_get() calls, in
> > > > > ima_post_create_tmpfile() and ima_post_path_mknod(), to avoid the lockdep
> > > > > warnings.
> > > > >
> > > > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> > > > > ---
> > > > > security/integrity/ima/ima_iint.c | 5 +++++
> > > > > security/integrity/ima/ima_main.c | 14 ++++++++++++--
> > > > > 2 files changed, 17 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/security/integrity/ima/ima_iint.c b/security/integrity/ima/ima_iint.c
> > > > > index c176fd0faae7..fe676ccec32f 100644
> > > > > --- a/security/integrity/ima/ima_iint.c
> > > > > +++ b/security/integrity/ima/ima_iint.c
> > > > > @@ -87,8 +87,13 @@ static void ima_iint_free(struct ima_iint_cache *iint)
> > > > > */
> > > > > struct ima_iint_cache *ima_inode_get(struct inode *inode)
> > > > > {
> > > > > + struct ima_iint_cache_lock *iint_lock;
> > > > > struct ima_iint_cache *iint;
> > > > >
> > > > > + iint_lock = ima_inode_security(inode->i_security);
> > > > > + if (iint_lock)
> > > > > + lockdep_assert_held(&iint_lock->mutex);
> > > > > +
> > > > > iint = ima_iint_find(inode);
> > > > > if (iint)
> > > > > return iint;
> > > >
> > > > Can you avoid the ima_iint_find() call here and just do the following?
> > > >
> > > > /* not sure if you need to check !iint_lock or not? */
> > > > if (!iint_lock)
> > > > return NULL;
> > > > iint = iint_lock->iint;
> > > > if (!iint)
> > > > return NULL;
> > >
> > > Yes, I also like it much more.
> >
> > Yes, testing iint_lock and then iint_lock->iint should be fine, but the logic
> > needs to be inverted. ima_inode_get() should return the existing iint, if it
> > exists, or allocate the memory.
>
> Right, I checked the patches I'm about to send, they do that.
I think Paul's point was that we should not create a iint anyway, if
the inode does not have a security blob. That check I think it is fine
to keep.
Roberto
next prev parent reply other threads:[~2024-10-16 13:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 16:57 [PATCH 1/3] ima: Remove inode lock Roberto Sassu
2024-10-08 16:57 ` [PATCH 2/3] ima: Ensure lock is held when setting iint pointer in inode security blob Roberto Sassu
2024-10-09 15:41 ` Paul Moore
2024-10-09 15:43 ` Roberto Sassu
2024-10-11 19:30 ` Mimi Zohar
2024-10-14 11:45 ` Roberto Sassu
2024-10-16 13:08 ` Roberto Sassu [this message]
2024-10-08 16:57 ` [PATCH 3/3] ima: Mark concurrent accesses to the iint pointer in the " Roberto Sassu
2024-10-09 15:36 ` [PATCH 1/3] ima: Remove inode lock Paul Moore
2024-10-09 15:37 ` Paul Moore
2024-10-09 16:25 ` Roberto Sassu
2024-10-09 16:32 ` Roberto Sassu
2024-10-09 16:43 ` Roberto Sassu
2024-10-11 13:30 ` Roberto Sassu
2024-10-16 9:59 ` Roberto Sassu
2024-10-18 9:24 ` Roberto Sassu
2024-10-18 10:49 ` Kirill A. Shutemov
2024-10-18 10:52 ` Kirill A. Shutemov
2024-10-18 10:55 ` Kirill A. Shutemov
2024-10-18 11:00 ` Lorenzo Stoakes
2024-10-18 11:05 ` Kirill A. Shutemov
2024-10-18 11:22 ` Roberto Sassu
2024-10-18 11:54 ` Kirill A. Shutemov
2024-10-18 11:56 ` Roberto Sassu
2024-10-18 13:29 ` Roberto Sassu
2024-10-18 14:36 ` Jann Horn
2024-10-18 14:48 ` Lorenzo Stoakes
2024-10-09 16:24 ` Roberto Sassu
2024-10-09 15:59 ` Shu Han
2024-11-27 15:57 ` Roberto Sassu
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=33fefedfbdc44ea9c58a14030d58bff20b2c7d86.camel@huaweicloud.com \
--to=roberto.sassu@huaweicloud.com \
--cc=bpf@vger.kernel.org \
--cc=dmitry.kasatkin@gmail.com \
--cc=ebpqwerty472123@gmail.com \
--cc=eric.snowberg@oracle.com \
--cc=jmorris@namei.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=roberto.sassu@huawei.com \
--cc=serge@hallyn.com \
--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).