From: Paul Moore <paul@paul-moore.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: James Morris <jmorris@namei.org>,
"Serge E . Hallyn" <serge@hallyn.com>,
Miklos Szeredi <miklos@szeredi.hu>,
linux-security-module@vger.kernel.org,
linux-unionfs@vger.kernel.org,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Vivek Goyal <vgoyal@redhat.com>,
Christian Brauner <brauner@kernel.org>,
Chris Mason <mason@kernel.org>,
Josef Bacik <josef@toxicpanda.com>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] lsm: put the copy up creds when an LSM hook fails
Date: Fri, 20 Nov 2026 20:23:28 -0500 [thread overview]
Message-ID: <7695c09e696343176f9d1e1c3a3f4105@paul-moore.com> (raw)
In-Reply-To: <20261120073717.1588080-1-amir73il@gmail.com>
On Nov 20, 2026 sashiko-bot@kernel.org wrote:
>
> security_inode_copy_up() leaks a struct cred when one LSM allocates new
> creds for an overlayfs copy up and a later LSM then denies the copy up.
> One such pair is SELinux and a BPF LSM program that denies
> inode_copy_up. Enabling both LSMs and loading the program requires
> root. After that, each denied copy up leaks one struct cred, no matter
> which user triggers it.
>
> The hook calls each enabled LSM in turn. SELinux or Smack allocates the
> creds and returns them through a pointer argument of the hook. A later
> LSM can still return an error, and the hook then returns that error with
> the creds still allocated. Its kernel-doc does not say that the caller
> owns them on error, and the only caller, overlayfs, does not put them.
>
> Reproduced with SELinux and such a BPF LSM program: 36000 failed opens
> and chmods by an unprivileged user on an overlayfs mount left 36000
> struct cred objects allocated, which kmemleak reported.
>
> Fix this by putting the creds in security_inode_copy_up() when the hook
> fails, so the caller gets either creds that it owns or none.
>
> Fixes: d8ad8b496184 ("security, overlayfs: provide copy up security hook for unioned files")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chris Mason <mason@kernel.org>
> [amir: put the creds in security_inode_copy_up() instead of in overlayfs]
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> Hi Paul,
>
> Apologies for missed the LSM list and maintainers in first posting [1].
> Resending with proper Cc list.
>
> I think this LSM hook was introduced with confusing contact for chained
> LSMs and this change makes the hook contract more sane in this case.
>
> Thanks,
> Amir.
>
> [1] https://lore.kernel.org/r/20261104082128.3573690-1-amir73il@gmail.com/
>
> security/security.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
Thanks Amir, Chris - this looks good to me, I'm going to merge this into
lsm/stable-7.4 and I'll send it up to Linus after it has had a few days
in linux-next.
--
paul-moore.com
prev parent reply other threads:[~2026-11-21 1:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:37 [PATCH RESEND] lsm: put the copy up creds when an LSM hook fails Amir Goldstein
2026-11-20 7:40 ` sashiko-bot
2026-11-21 1:23 ` Paul Moore [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=7695c09e696343176f9d1e1c3a3f4105@paul-moore.com \
--to=paul@paul-moore.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jmorris@namei.org \
--cc=josef@toxicpanda.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=mason@kernel.org \
--cc=miklos@szeredi.hu \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
--cc=vgoyal@redhat.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