mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ovl: put the copy-up credentials when the copy_up hook fails
@ 2026-12-03 10:42 Anton Protopopov
  0 siblings, 0 replies; only message in thread
From: Anton Protopopov @ 2026-12-03 10:42 UTC (permalink / raw)
  To: Miklos Szeredi, Amir Goldstein
  Cc: Anton Protopopov, Christian Brauner, Paul Moore, Stephen Smalley,
	Vivek Goyal, linux-unionfs, linux-security-module, linux-kernel

The security_inode_copy_up() function calls the inode_copy_up hook of
every LSM in turn and stops at the first error. SELinux and Smack
allocate new credentials with prepare_creds() and return them in
*new. If an LSM which runs after them fails the hook, for example a
BPF LSM program which denies the copy-up, ovl_prepare_copy_up_creds()
returns the error and the credentials leak. Nobody puts them: the
cleanup of the copy_up_creds class skips error pointers.

Put the credentials before returning the error. put_cred() accepts
NULL, so this is also right when no LSM allocated them.

Fixes: d8ad8b496184 ("security, overlayfs: provide copy up security hook for unioned files")
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
 fs/overlayfs/copy_up.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index c147ad155b79..6195e5d47174 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -732,8 +732,10 @@ static const struct cred *ovl_prepare_copy_up_creds(struct dentry *dentry)
 	int err;
 
 	err = security_inode_copy_up(dentry, &copy_up_cred);
-	if (err < 0)
+	if (err < 0) {
+		put_cred(copy_up_cred);
 		return ERR_PTR(err);
+	}
 
 	if (!copy_up_cred)
 		return NULL;

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 10:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 10:42 [PATCH] ovl: put the copy-up credentials when the copy_up hook fails Anton Protopopov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®