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