From 54c192868399626112d37ba6d243bef8632cd2e1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 15 Sep 2026 13:05:32 +0100 Subject: [PATCH] Revert "xattrs: Use /proc/self/fd path in glnx_fd_set_all_xattrs" We can't use fsetxattr() to get the extended attributes of a symlink via the magic symlink in /proc/self/fd, because opening with O_NOFOLLOW would try to set the extended attributes on the magic symlink /proc/self/fd/N, and opening without O_NOFOLLOW would dereference the symlink. This reverts commit 128578be4de770675a8f51eca4fc8b7105da2b2d. Helps: https://github.com/flatpak/flatpak/issues/6818 Signed-off-by: Simon McVittie --- glnx-xattrs.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/glnx-xattrs.c b/glnx-xattrs.c index a5b3b2804..43423ac3c 100644 --- a/glnx-xattrs.c +++ b/glnx-xattrs.c @@ -338,12 +338,25 @@ glnx_dfd_name_set_all_xattrs (int dfd, gboolean glnx_fd_set_all_xattrs (int fd, GVariant *xattrs, - GCancellable *cancellable, + G_GNUC_UNUSED GCancellable *cancellable, GError **error) { - char buf[PATH_MAX]; - snprintf (buf, sizeof (buf), "/proc/self/fd/%d", fd); - return set_all_xattrs_for_path (buf, xattrs, cancellable, error); + const guint n = g_variant_n_children (xattrs); + for (guint i = 0; i < n; i++) + { + const guint8* name; + g_autoptr(GVariant) value = NULL; + g_variant_get_child (xattrs, i, "(^&ay@ay)", + &name, &value); + + gsize value_len; + const guint8* value_data = g_variant_get_fixed_array (value, &value_len, 1); + + if (TEMP_FAILURE_RETRY (fsetxattr (fd, (char*)name, (char*)value_data, value_len, 0)) < 0) + return glnx_throw_errno_prefix (error, "Setting xattrs: fsetxattr(%s)", name); + } + + return TRUE; } /**