All of lore.kernel.org
 help / color / mirror / Atom feed
* 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
  2026-12-03 15:05 ` Amir Goldstein
  1 sibling, 0 replies; 5+ 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] 5+ 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
  2026-12-03 15:05 ` Amir Goldstein
  0 siblings, 2 replies; 5+ 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, &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 related	[flat|nested] 5+ messages in thread

* 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
@ 2026-12-03 15:05 ` Amir Goldstein
  2026-12-03 15:12   ` Anton Protopopov
  1 sibling, 1 reply; 5+ messages in thread
From: Amir Goldstein @ 2026-12-03 15:05 UTC (permalink / raw)
  To: Anton Protopopov
  Cc: Miklos Szeredi, Christian Brauner, Paul Moore, Stephen Smalley,
	Vivek Goyal, linux-unionfs, linux-security-module, linux-kernel

On Thu, Dec 3, 2026 at 11:31 AM Anton Protopopov
<a.s.protopopov@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@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

Hi Anton,

A fix is already staged, by the LSM maintainer:

https://lore.kernel.org/linux-fsdevel/7695c09e696343176f9d1e1c3a3f4105@paul-moore.com/

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ovl: put the copy-up credentials when the copy_up hook fails
  2026-12-03 15:05 ` Amir Goldstein
@ 2026-12-03 15:12   ` Anton Protopopov
  2026-12-03 17:42     ` Paul Moore
  0 siblings, 1 reply; 5+ messages in thread
From: Anton Protopopov @ 2026-12-03 15:12 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Miklos Szeredi, Christian Brauner, Paul Moore, Stephen Smalley,
	Vivek Goyal, linux-unionfs, linux-security-module, linux-kernel

On Thu, Dec 3, 2026 at 4:05 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Thu, Dec 3, 2026 at 11:31 AM Anton Protopopov
> <a.s.protopopov@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@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
>
> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ovl: put the copy-up credentials when the copy_up hook fails
  2026-12-03 15:12   ` Anton Protopopov
@ 2026-12-03 17:42     ` Paul Moore
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Moore @ 2026-12-03 17:42 UTC (permalink / raw)
  To: Anton Protopopov
  Cc: Amir Goldstein, Miklos Szeredi, Christian Brauner,
	Stephen Smalley, Vivek Goyal, linux-unionfs,
	linux-security-module, linux-kernel

On Thu, Dec 3, 2026 at 10:12 AM Anton Protopopov
<a.s.protopopov@gmail.com> wrote:
> On Thu, Dec 3, 2026 at 4:05 PM Amir Goldstein <amir73il@gmail.com> wrote:
> > On Thu, Dec 3, 2026 at 11:31 AM Anton Protopopov
> > <a.s.protopopov@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@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
> >
> > Hi Anton,
> >
> > A fix is already staged, by the LSM maintainer:
> >
> > https://lore.kernel.org/linux-fsdevel/7695c09e696343176f9d1e1c3a3f4105@paul-moore.com/
>
> Great, thanks!

FYI, it's in Linus' tree as of December 1st.

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-03 17:43 UTC | newest]

Thread overview: 5+ 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
2026-12-03 15:05 ` Amir Goldstein
2026-12-03 15:12   ` Anton Protopopov
2026-12-03 17:42     ` Paul Moore

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.