[PATCH] lsm: put the copy up creds when an LSM hook fails
Paul Moore
paul at paul-moore.com
Sat Nov 21 01:23:28 UTC 2026
On Nov 20, 2026 sashiko-bot at 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 at vger.kernel.org
> Signed-off-by: Chris Mason <mason at kernel.org>
> [amir: put the creds in security_inode_copy_up() instead of in overlayfs]
> Signed-off-by: Amir Goldstein <amir73il at 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
More information about the Linux-security-module-archive
mailing list