Blame SOURCES/0067-daemon-xattr-Filter-out-user.WofCompressedData-from-.patch

da373f
From fb3136e8abe5fec9e8a749e5879b75c696f7ba0e Mon Sep 17 00:00:00 2001
3efd08
From: "Richard W.M. Jones" <rjones@redhat.com>
3efd08
Date: Thu, 12 Mar 2020 14:40:05 +0000
3efd08
Subject: [PATCH] daemon: xattr: Filter out user.WofCompressedData from xattrs
3efd08
 (RHBZ#1811539).
3efd08
3efd08
See comment in code for justification.
3efd08
3efd08
Thanks: Yongkui Guo for finding the bug.
3efd08
(cherry picked from commit c2c11382bbeb4500f3388a31ffd08cfc18b0de40)
3efd08
---
3efd08
 daemon/xattr.c | 43 ++++++++++++++++++++++++++++++++++++++++---
3efd08
 1 file changed, 40 insertions(+), 3 deletions(-)
3efd08
3efd08
diff --git a/daemon/xattr.c b/daemon/xattr.c
3efd08
index 3e1144963..43e49384f 100644
3efd08
--- a/daemon/xattr.c
3efd08
+++ b/daemon/xattr.c
3efd08
@@ -19,6 +19,8 @@
3efd08
 #include <config.h>
3efd08
 
3efd08
 #include <stdio.h>
3efd08
+#include <stdlib.h>
3efd08
+#include <stdbool.h>
3efd08
 #include <limits.h>
3efd08
 #include <unistd.h>
3efd08
 
3efd08
@@ -119,6 +121,29 @@ split_attr_names (char *buf, size_t len)
3efd08
   return take_stringsbuf (&ret;;
3efd08
 }
3efd08
 
3efd08
+/* We hide one extended attribute automatically.  This is used by NTFS
3efd08
+ * to store the compressed contents of a file when using "CompactOS"
3efd08
+ * (per-file compression).  I justify this by:
3efd08
+ *
3efd08
+ * (1) The attribute is only used internally by NTFS.  The actual file
3efd08
+ * contents are still available.
3efd08
+ *
3efd08
+ * (2) It's probably not valid to copy this attribute when copying the
3efd08
+ * other attributes of a file.  ntfs-3g-system-compression doesn't
3efd08
+ * support writing compressed files.
3efd08
+ *
3efd08
+ * (3) This file isn't readable by the Linux kernel.  Reading it will
3efd08
+ * always return -E2BIG (RHBZ#1811539).  So we can't read it even if
3efd08
+ * we wanted to.
3efd08
+ *
3efd08
+ * (4) The Linux kernel itself hides other attributes.
3efd08
+ */
3efd08
+static bool
3efd08
+not_hidden_xattr (const char *attrname)
3efd08
+{
3efd08
+  return STRNEQ (attrname, "user.WofCompressedData");
3efd08
+}
3efd08
+
3efd08
 static int
3efd08
 compare_xattrs (const void *vxa1, const void *vxa2)
3efd08
 {
3efd08
@@ -136,6 +161,7 @@ getxattrs (const char *path,
3efd08
 {
3efd08
   ssize_t len, vlen;
3efd08
   CLEANUP_FREE char *buf = NULL;
3efd08
+  CLEANUP_FREE /* not string list */ char **names_unfiltered = NULL;
3efd08
   CLEANUP_FREE /* not string list */ char **names = NULL;
3efd08
   size_t i;
3efd08
   guestfs_int_xattr_list *r = NULL;
3efd08
@@ -145,7 +171,10 @@ getxattrs (const char *path,
3efd08
     /* _listxattrs issues reply_with_perror already. */
3efd08
     goto error;
3efd08
 
3efd08
-  names = split_attr_names (buf, len);
3efd08
+  names_unfiltered = split_attr_names (buf, len);
3efd08
+  if (names_unfiltered == NULL)
3efd08
+    goto error;
3efd08
+  names = filter_list (not_hidden_xattr, names_unfiltered);
3efd08
   if (names == NULL)
3efd08
     goto error;
3efd08
 
3efd08
@@ -323,6 +352,7 @@ do_internal_lxattrlist (const char *path, char *const *names)
3efd08
     void *newptr;
3efd08
     CLEANUP_FREE char *pathname = NULL;
3efd08
     CLEANUP_FREE char *buf = NULL;
3efd08
+    CLEANUP_FREE /* not string list */ char **attrnames_unfiltered = NULL;
3efd08
     CLEANUP_FREE /* not string list */ char **attrnames = NULL;
3efd08
 
3efd08
     /* Be careful in this loop about which errors cause the whole call
3efd08
@@ -381,7 +411,10 @@ do_internal_lxattrlist (const char *path, char *const *names)
3efd08
     if (len == -1)
3efd08
       continue; /* not fatal */
3efd08
 
3efd08
-    attrnames = split_attr_names (buf, len);
3efd08
+    attrnames_unfiltered = split_attr_names (buf, len);
3efd08
+    if (attrnames_unfiltered == NULL)
3efd08
+      goto error;
3efd08
+    attrnames = filter_list (not_hidden_xattr, attrnames_unfiltered);
3efd08
     if (attrnames == NULL)
3efd08
       goto error;
3efd08
     nr_attrs = guestfs_int_count_strings (attrnames);
3efd08
@@ -539,6 +572,7 @@ copy_xattrs (const char *src, const char *dest)
3efd08
 {
3efd08
   ssize_t len, vlen, ret, attrval_len = 0;
3efd08
   CLEANUP_FREE char *buf = NULL, *attrval = NULL;
3efd08
+  CLEANUP_FREE /* not string list */ char **names_unfiltered = NULL;
3efd08
   CLEANUP_FREE /* not string list */ char **names = NULL;
3efd08
   size_t i;
3efd08
 
3efd08
@@ -547,7 +581,10 @@ copy_xattrs (const char *src, const char *dest)
3efd08
     /* _listxattrs issues reply_with_perror already. */
3efd08
     goto error;
3efd08
 
3efd08
-  names = split_attr_names (buf, len);
3efd08
+  names_unfiltered = split_attr_names (buf, len);
3efd08
+  if (names_unfiltered == NULL)
3efd08
+    goto error;
3efd08
+  names = filter_list (not_hidden_xattr, names_unfiltered);
3efd08
   if (names == NULL)
3efd08
     goto error;
3efd08
 
3efd08
-- 
da373f
2.18.4
3efd08