[PATCH] ovl: put the copy-up credentials when the copy_up hook fails
Anton Protopopov
a.s.protopopov at gmail.com
Thu Dec 3 15:12:26 UTC 2026
On Thu, Dec 3, 2026 at 4:05 PM Amir Goldstein <amir73il at gmail.com> wrote:
>
> On Thu, Dec 3, 2026 at 11:31 AM Anton Protopopov
> <a.s.protopopov at gmail.com> wrote:
> >
> > 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 at 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
>
> Hi Anton,
>
> A fix is already staged, by the LSM maintainer:
>
> https://lore.kernel.org/linux-fsdevel/7695c09e696343176f9d1e1c3a3f4105@paul-moore.com/
Great, thanks!
> Thanks,
> Amir.
More information about the Linux-security-module-archive
mailing list