($INBOX_DIR/description missing)
 help / color / Atom feed
* [PATCH] ovl: skip getxattr of security labels
@ 2020-12-19 10:16 Amir Goldstein
  2021-01-20 12:23 ` Amir Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2020-12-19 10:16 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-unionfs, Michael Labriola

When inode has no listxattr op of its own (e.g. squashfs) vfs_listxattr
calls the LSM inode_listsecurity hooks to list the xattrs that LSMs will
intercept in inode_getxattr hooks.

When selinux LSM is installed but not initialized, it will list the
security.selinux xattr in inode_listsecurity, but will not intercept it
in inode_getxattr.  This results in -ENODATA for a getxattr call for an
xattr returned by listxattr.

This situation was manifested as overlayfs failure to copy up lower
files from squashfs when selinux is built-in but not initialized,
because ovl_copy_xattr() iterates the lower inode xattrs by
vfs_listxattr() and vfs_getxattr().

ovl_copy_xattr() skips copy up of security labels that are indentified by
inode_copy_up_xattr LSM hooks, but it does that after vfs_getxattr().
Since we are not going to copy them, skip vfs_getxattr() of the security
labels.

Reported-by: Michael Labriola <michael.d.labriola@gmail.com>
Tested-by: Michael Labriola <michael.d.labriola@gmail.com>
Link: https://lore.kernel.org/linux-unionfs/2nv9d47zt7.fsf@aldarion.sourceruckus.org/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Miklos,

This is a workaround for a v5.9 selinux related regression reported by
Michael that caused copy up failure is a very specific configuration
involving lower squashfs and built-in but disabled selinux.

I've sent the bug fix to selinux list, so this patch is complementary.
I removed the stable/Fixes tags, because this patch does not cleanly
apply to v5.9 and is not the real bug fix.

Thanks,
Amir.

 fs/overlayfs/copy_up.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index e5b616c93e11..0fed532efa68 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -84,6 +84,14 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
 
 		if (ovl_is_private_xattr(sb, name))
 			continue;
+
+		error = security_inode_copy_up_xattr(name);
+		if (error < 0 && error != -EOPNOTSUPP)
+			break;
+		if (error == 1) {
+			error = 0;
+			continue; /* Discard */
+		}
 retry:
 		size = vfs_getxattr(old, name, value, value_size);
 		if (size == -ERANGE)
@@ -107,13 +115,6 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
 			goto retry;
 		}
 
-		error = security_inode_copy_up_xattr(name);
-		if (error < 0 && error != -EOPNOTSUPP)
-			break;
-		if (error == 1) {
-			error = 0;
-			continue; /* Discard */
-		}
 		error = vfs_setxattr(new, name, value, size, 0);
 		if (error) {
 			if (error != -EOPNOTSUPP || ovl_must_copy_xattr(name))
-- 
2.25.1


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

* Re: [PATCH] ovl: skip getxattr of security labels
  2020-12-19 10:16 [PATCH] ovl: skip getxattr of security labels Amir Goldstein
@ 2021-01-20 12:23 ` Amir Goldstein
  2021-01-20 12:37   ` Miklos Szeredi
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2021-01-20 12:23 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: overlayfs, Michael Labriola

On Sat, Dec 19, 2020 at 12:16 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> When inode has no listxattr op of its own (e.g. squashfs) vfs_listxattr
> calls the LSM inode_listsecurity hooks to list the xattrs that LSMs will
> intercept in inode_getxattr hooks.
>
> When selinux LSM is installed but not initialized, it will list the
> security.selinux xattr in inode_listsecurity, but will not intercept it
> in inode_getxattr.  This results in -ENODATA for a getxattr call for an
> xattr returned by listxattr.
>
> This situation was manifested as overlayfs failure to copy up lower
> files from squashfs when selinux is built-in but not initialized,
> because ovl_copy_xattr() iterates the lower inode xattrs by
> vfs_listxattr() and vfs_getxattr().
>
> ovl_copy_xattr() skips copy up of security labels that are indentified by
> inode_copy_up_xattr LSM hooks, but it does that after vfs_getxattr().
> Since we are not going to copy them, skip vfs_getxattr() of the security
> labels.
>
> Reported-by: Michael Labriola <michael.d.labriola@gmail.com>
> Tested-by: Michael Labriola <michael.d.labriola@gmail.com>
> Link: https://lore.kernel.org/linux-unionfs/2nv9d47zt7.fsf@aldarion.sourceruckus.org/
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>
> Miklos,
>
> This is a workaround for a v5.9 selinux related regression reported by
> Michael that caused copy up failure is a very specific configuration
> involving lower squashfs and built-in but disabled selinux.
>
> I've sent the bug fix to selinux list, so this patch is complementary.
> I removed the stable/Fixes tags, because this patch does not cleanly
> apply to v5.9 and is not the real bug fix.
>

Ping.

FWIW, the selinux bug fix should already be in next.

Thanks,
Amir.

>
>  fs/overlayfs/copy_up.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
> index e5b616c93e11..0fed532efa68 100644
> --- a/fs/overlayfs/copy_up.c
> +++ b/fs/overlayfs/copy_up.c
> @@ -84,6 +84,14 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
>
>                 if (ovl_is_private_xattr(sb, name))
>                         continue;
> +
> +               error = security_inode_copy_up_xattr(name);
> +               if (error < 0 && error != -EOPNOTSUPP)
> +                       break;
> +               if (error == 1) {
> +                       error = 0;
> +                       continue; /* Discard */
> +               }
>  retry:
>                 size = vfs_getxattr(old, name, value, value_size);
>                 if (size == -ERANGE)
> @@ -107,13 +115,6 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
>                         goto retry;
>                 }
>
> -               error = security_inode_copy_up_xattr(name);
> -               if (error < 0 && error != -EOPNOTSUPP)
> -                       break;
> -               if (error == 1) {
> -                       error = 0;
> -                       continue; /* Discard */
> -               }
>                 error = vfs_setxattr(new, name, value, size, 0);
>                 if (error) {
>                         if (error != -EOPNOTSUPP || ovl_must_copy_xattr(name))
> --
> 2.25.1
>

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

* Re: [PATCH] ovl: skip getxattr of security labels
  2021-01-20 12:23 ` Amir Goldstein
@ 2021-01-20 12:37   ` Miklos Szeredi
  0 siblings, 0 replies; 3+ messages in thread
From: Miklos Szeredi @ 2021-01-20 12:37 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: overlayfs, Michael Labriola

On Wed, Jan 20, 2021 at 1:23 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Sat, Dec 19, 2020 at 12:16 PM Amir Goldstein <amir73il@gmail.com> wrote:

> > This is a workaround for a v5.9 selinux related regression reported by
> > Michael that caused copy up failure is a very specific configuration
> > involving lower squashfs and built-in but disabled selinux.
> >
> > I've sent the bug fix to selinux list, so this patch is complementary.
> > I removed the stable/Fixes tags, because this patch does not cleanly
> > apply to v5.9 and is not the real bug fix.
> >
>
> Ping.

Queued, thanks.

Miklos

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-19 10:16 [PATCH] ovl: skip getxattr of security labels Amir Goldstein
2021-01-20 12:23 ` Amir Goldstein
2021-01-20 12:37   ` Miklos Szeredi

($INBOX_DIR/description missing)

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-unionfs/0 linux-unionfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-unionfs linux-unionfs/ https://lore.kernel.org/linux-unionfs \
		linux-unionfs@vger.kernel.org
	public-inbox-index linux-unionfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-unionfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git