From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>, Amir Goldstein <amir73il@gmail.com>
Cc: Anton Protopopov <a.s.protopopov@gmail.com>,
Christian Brauner <brauner@kernel.org>,
Paul Moore <paul@paul-moore.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Vivek Goyal <vgoyal@redhat.com>,
linux-unionfs@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] ovl: put the copy-up credentials when the copy_up hook fails
Date: Thu, 3 Dec 2026 10:42:43 +0000 [thread overview]
Message-ID: <20261203104244.1015716-1-a.s.protopopov@gmail.com> (raw)
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
next reply other threads:[~2026-12-03 10:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 10:42 Anton Protopopov [this message]
2026-12-03 10:41 ` [PATCH] ovl: put the copy-up credentials when the copy_up hook fails sashiko-bot
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=20261203104244.1015716-1-a.s.protopopov@gmail.com \
--to=a.s.protopopov@gmail.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=paul@paul-moore.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