* Re: [PATCH] ovl: put the copy-up credentials when the copy_up hook fails
2026-12-03 10:42 [PATCH] ovl: put the copy-up credentials when the copy_up hook fails Anton Protopopov
@ 2026-12-03 10:41 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 10:41 UTC (permalink / raw)
Cc: linux-security-module
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203104244.1015716-1-a.s.protopopov@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] ovl: put the copy-up credentials when the copy_up hook fails
@ 2026-12-03 10:42 Anton Protopopov
2026-12-03 10:41 ` sashiko-bot
0 siblings, 1 reply; 2+ messages 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, ©_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 related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 10:41 UTC | newest]
Thread overview: 2+ messages (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
2026-12-03 10:41 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox