summaryrefslogtreecommitdiff
path: root/tools/lib/python
diff options
context:
space:
mode:
authorChris Mason <mason@kernel.org>2026-11-20 08:37:16 +0100
committerPaul Moore <paul@paul-moore.com>2026-11-20 20:23:29 -0500
commit1868b4bac64325bf0059bd141d0185c0de5469c7 (patch)
tree864a386b7dcfe38c299c588c40644deb1f4ff1f3 /tools/lib/python
parent6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 (diff)
lsm: put the copy up creds when an LSM hook fails
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. Cc: stable@vger.kernel.org Fixes: d8ad8b496184 ("security, overlayfs: provide copy up security hook for unioned files") 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> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions