public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/flatpak] f43: Fix CVE-2026-96807
@ 2026-10-23 22:25 Adrian Vovk
0 siblings, 0 replies; only message in thread
From: Adrian Vovk @ 2026-10-23 22:25 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/flatpak
Branch : f43
Commit : ce872dcc3331cceb03937b23f66b8b753c570bd1
Author : Adrian Vovk <avovk@redhat.com>
Date : 2026-10-23T18:24:14-04:00
Stats : +859/-0 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/flatpak/c/ce872dcc3331cceb03937b23f66b8b753c570bd1?branch=f43
Log:
Fix CVE-2026-96807
rhbz#2539621
---
diff --git a/CVE-2026-96807.patch b/CVE-2026-96807.patch
new file mode 100644
index 0000000..6940541
--- /dev/null
+++ b/CVE-2026-96807.patch
@@ -0,0 +1,857 @@
+From 3d43a0f5fa602cc3edc557d8ab835030140792b1 Mon Sep 17 00:00:00 2001
+From: Sebastian Wick <sebastian.wick@redhat.com>
+Date: Fri, 12 Jun 2026 13:42:13 +0200
+Subject: [PATCH] chase: Add internal glnx_chaseat_full for a strategic
+ callback
+
+It takes a callback which gets called every time we try to open the next
+segment of the path. This allows implementing more specific and advanced
+use cases to be implemented without adding more complexity to the chase
+algorithm itself.
+
+[This is required for various later security fixes in Flatpak -smcv]
+
+(cherry-picked from commit 4f8674709dce57e7f5422a475f61556162f930d8)
+---
+ subprojects/libglnx/glnx-chase.c | 110 ++++++++++++++++++++-----------
+ 1 file changed, 73 insertions(+), 37 deletions(-)
+
+diff --git a/subprojects/libglnx/glnx-chase.c b/subprojects/libglnx/glnx-chase.c
+index 9ad2fe3b3e..d7edf34e57 100644
+--- a/subprojects/libglnx/glnx-chase.c
++++ b/subprojects/libglnx/glnx-chase.c
+@@ -46,6 +46,13 @@
+ #define GLNX_CHASE_ALL_FLAGS \
+ (GLNX_CHASE_ALL_DEBUG_FLAGS | GLNX_CHASE_ALL_REGULAR_FLAGS)
+
++typedef int (* GlnxChaseCallback)(int next_fd,
++ int current_fd,
++ const char *segment,
++ int open_tree_flags,
++ gpointer user_data,
++ GError **error);
++
+ typedef GQueue GlnxStatxQueue;
+
+ static void
+@@ -328,10 +335,12 @@ extract_next_segment (const char **remaining,
+ * we're in full control over the resolving.
+ */
+ static int
+-chase_manual (int dirfd,
+- const char *path,
+- GlnxChaseFlags flags,
+- GError **error)
++chase_manual (int dirfd,
++ const char *path,
++ GlnxChaseFlags flags,
++ GlnxChaseCallback callback,
++ gpointer user_data,
++ GError **error)
+ {
+ gboolean is_absolute;
+ g_autofree char *buffer = NULL;
+@@ -349,6 +358,7 @@ chase_manual (int dirfd,
+ * - none of the resolve flags are set (they would require work here)
+ * - NO_AUTOMOUNT is set (chase_open_tree only triggers the automount for
+ * last component in some cases)
++ * - there is no callback
+ *
+ * TODO: if we have a guarantee that the open_tree syscall works, we can
+ * shortcut even without GLNX_CHASE_NO_AUTOMOUNT
+@@ -356,7 +366,8 @@ chase_manual (int dirfd,
+ if ((flags & (GLNX_CHASE_NO_AUTOMOUNT |
+ GLNX_CHASE_RESOLVE_BENEATH |
+ GLNX_CHASE_RESOLVE_IN_ROOT |
+- GLNX_CHASE_RESOLVE_NO_SYMLINKS)) == GLNX_CHASE_NO_AUTOMOUNT)
++ GLNX_CHASE_RESOLVE_NO_SYMLINKS)) == GLNX_CHASE_NO_AUTOMOUNT &&
++ callback == NULL)
+ {
+ GlnxChaseFlags open_tree_flags =
+ (flags & (GLNX_CHASE_NOFOLLOW | GLNX_CHASE_ALL_DEBUG_FLAGS));
+@@ -466,10 +477,25 @@ chase_manual (int dirfd,
+ GlnxChaseFlags open_tree_flags =
+ GLNX_CHASE_NOFOLLOW |
+ (flags & (GLNX_CHASE_NO_AUTOMOUNT | GLNX_CHASE_ALL_DEBUG_FLAGS));
++ g_autoptr(GError) local_error = NULL;
++
++ next_fd = chase_open_tree (fd, segment, open_tree_flags, &local_error);
++
++ /* Note that the callback can be called with next_fd < 0.
++ * If so, the error is already set, but may be cleared by
++ * the callback if it can recover from an error that already
++ * occurred. */
++ if (callback)
++ {
++ next_fd = callback (next_fd, fd, segment, open_tree_flags,
++ user_data, &local_error);
++ }
+
+- next_fd = chase_open_tree (fd, segment, open_tree_flags, error);
+ if (next_fd < 0)
+- return -1;
++ {
++ g_propagate_error (error, g_steal_pointer (&local_error));
++ return -1;
++ }
+ }
+
+ if (!glnx_chase_statx (next_fd, no_automount, &st, error))
+@@ -602,30 +628,13 @@ chase_manual (int dirfd,
+ return g_steal_fd (&owned_fd);
+ }
+
+-/**
+- * glnx_chaseat:
+- * @dirfd: a directory file descriptor
+- * @path: a path
+- * @flags: combination of GlnxChaseFlags flags
+- * @error: a #GError
+- *
+- * Behaves similar to openat, but with a number of differences:
+- *
+- * - All file descriptors which get returned are O_PATH and O_CLOEXEC. If you
+- * want to actually open the file for reading or writing, use glnx_fd_reopen,
+- * openat, or other at-style functions.
+- * - By default, automounts get triggered and the O_PATH fd will point to inodes
+- * in the newly mounted filesystem if an automount is encountered. This can be
+- * turned off with GLNX_CHASE_NO_AUTOMOUNT.
+- * - The GLNX_CHASE_RESOLVE_ flags can be used to safely deal with symlinks.
+- *
+- * Returns: the chased file, or -1 with @error set on error
+- */
+-int
+-glnx_chaseat (int dirfd,
+- const char *path,
+- GlnxChaseFlags flags,
+- GError **error)
++static int
++glnx_chaseat_full (int dirfd,
++ const char *path,
++ GlnxChaseFlags flags,
++ GlnxChaseCallback callback,
++ gpointer user_data,
++ GError **error)
+ {
+ static gboolean can_openat2 = TRUE;
+ glnx_autofd int fd = -1;
+@@ -643,15 +652,14 @@ glnx_chaseat (int dirfd,
+ g_return_val_if_fail ((must_flags & (must_flags - 1)) == 0, -1);
+ }
+
+- /* TODO: Add a callback which is called for every resolved path segment, to
+- * allow users to verify and expand the functionality safely. */
+-
+ /* We need the manual impl for NO_AUTOMOUNT, and we can skip this, if we don't
+ * have openat2 at all.
+ * Technically racy (static, not synced), but both paths work fine so it
+ * doesn't matter. */
+- if (can_openat2 && (flags & GLNX_CHASE_NO_AUTOMOUNT) == 0 &&
+- (flags & GLNX_CHASE_DEBUG_NO_OPENAT2) == 0)
++ if (can_openat2 &&
++ (flags & GLNX_CHASE_NO_AUTOMOUNT) == 0 &&
++ (flags & GLNX_CHASE_DEBUG_NO_OPENAT2) == 0 &&
++ callback == NULL)
+ {
+ uint64_t openat2_flags = 0;
+ uint64_t openat2_resolve = 0;
+@@ -690,7 +698,7 @@ glnx_chaseat (int dirfd,
+
+ if (fd < 0)
+ {
+- fd = chase_manual (dirfd, path, flags, error);
++ fd = chase_manual (dirfd, path, flags, callback, user_data, error);
+ if (fd < 0)
+ return -1;
+ }
+@@ -744,6 +752,34 @@ glnx_chaseat (int dirfd,
+ return g_steal_fd (&fd);
+ }
+
++/**
++ * glnx_chaseat:
++ * @dirfd: a directory file descriptor
++ * @path: a path
++ * @flags: combination of GlnxChaseFlags flags
++ * @error: a #GError
++ *
++ * Behaves similar to openat, but with a number of differences:
++ *
++ * - All file descriptors which get returned are O_PATH and O_CLOEXEC. If you
++ * want to actually open the file for reading or writing, use glnx_fd_reopen,
++ * openat, or other at-style functions.
++ * - By default, automounts get triggered and the O_PATH fd will point to inodes
++ * in the newly mounted filesystem if an automount is encountered. This can be
++ * turned off with GLNX_CHASE_NO_AUTOMOUNT.
++ * - The GLNX_CHASE_RESOLVE_ flags can be used to safely deal with symlinks.
++ *
++ * Returns: the chased file, or -1 with @error set on error
++ */
++int
++glnx_chaseat (int dirfd,
++ const char *path,
++ GlnxChaseFlags flags,
++ GError **error)
++{
++ return glnx_chaseat_full (dirfd, path, flags, NULL, NULL, error);
++}
++
+ /**
+ * glnx_chase_and_statxat:
+ * @dirfd: a directory file descriptor
+
+
+From 68c12b9695eee4a94d896f0cf2f388f0d3c63df1 Mon Sep 17 00:00:00 2001
+From: Sebastian Wick <sebastian.wick@redhat.com>
+Date: Fri, 12 Jun 2026 13:45:22 +0200
+Subject: [PATCH] chase: Add glnx_chase_and_mkdirat
+
+We found that there is a common use case where we need to get a
+subdirectory (potentially multiple levels) which might not exist yet.
+Adding another flag for this to GlnxChaseFlags is what systemd has done,
+but creating a directory takes a mode, so the flag creates directories
+with a fixed mode. This approach instead takes the mode as argument.
+
+[This is required for various later security fixes in Flatpak -smcv]
+
+(cherry-picked from commit ae7355612a68d39472ff3699104845d2cc5dfb4d)
+---
+ subprojects/libglnx/glnx-chase.c | 87 +++++++++++++++++++
+ subprojects/libglnx/glnx-chase.h | 6 ++
+ .../libglnx/tests/test-libglnx-chase.c | 69 +++++++++++++++
+ 3 files changed, 162 insertions(+)
+
+diff --git a/subprojects/libglnx/glnx-chase.c b/subprojects/libglnx/glnx-chase.c
+index d7edf34e57..2251cb71f8 100644
+--- a/subprojects/libglnx/glnx-chase.c
++++ b/subprojects/libglnx/glnx-chase.c
+@@ -17,6 +17,7 @@
+ #include <unistd.h>
+
+ #include <glnx-backports.h>
++#include <glnx-dirfd.h>
+ #include <glnx-errors.h>
+ #include <glnx-fdio.h>
+ #include <glnx-local-alloc.h>
+@@ -823,3 +824,89 @@ glnx_chase_and_statxat (int dirfd,
+
+ return g_steal_fd (&fd);
+ }
++
++static int
++chase_and_mkdir (int next_fd,
++ int current_fd,
++ const char *segment,
++ G_GNUC_UNUSED int open_tree_flags,
++ gpointer user_data,
++ GError **error)
++{
++ mode_t mode = GPOINTER_TO_INT (user_data);
++ glnx_autofd int new_fd = -1;
++
++ /* if chase managed to get the next segment, we already got our answer */
++ if (next_fd >= 0)
++ return next_fd;
++
++ /* if the problem isn't that the file doesn't exist, we propagate the error */
++ g_assert (*error != NULL);
++ if (!g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
++ return -1;
++ g_clear_error (error);
++
++ /* create the directory with the specified mode */
++ if (!glnx_ensure_dir (current_fd, segment, mode, error))
++ return -1;
++
++ /* Get a fd to the created dir.
++ * This is racy, meaning another process can modify the filesystem and we
++ * might open a directory that we did not create and might have a different
++ * mode. There isn't a kernel API which returns a fd or an inode which makes
++ * this race unavoidable. This is fine though because the semantics of
++ * `glnx_chase_and_mkdirat` accept arbitrary directories (even with different
++ * modes) when chasing the path.
++ */
++ new_fd = openat (current_fd, segment,
++ O_CLOEXEC | O_PATH | O_DIRECTORY | O_NOFOLLOW);
++ if (new_fd < 0)
++ return glnx_fd_throw_errno_prefix (error, "opening created dir failed");
++
++ return g_steal_fd (&new_fd);
++}
++
++/**
++ * glnx_chase_and_mkdirat:
++ * @dirfd: a directory file descriptor
++ * @path: a path
++ * @flags: restricted combination of GlnxChaseFlags flags
++ * @mode: the mode for new directories
++ * @error: a #GError
++ *
++ * Same as glnx_chase with `GLNX_CHASE_MUST_BE_DIRECTORY`, but when a path
++ * segment does not exist, a directory is created for the segment with the mode
++ * @mode.
++ * This essentially implement a fd-relative equivalent of g_mkdir_with_parents()
++ * or `mkdir -p`.
++ * Note, that directories in the path which already exist can have arbitrary
++ * modes.
++ *
++ * See glnx_chaseat for the meaning of @dirfd and @path.
++ *
++ * The @flags argument is the same as in glnx_chaseat, but setting
++ * `GLNX_CHASE_MUST_BE_REGULAR`, `GLNX_CHASE_MUST_BE_SOCKET`, or
++ * `GLNX_CHASE_MUST_BE_DIRECTORY` is an error.
++ *
++ * Returns: the chased file, or -1 with @error set on error
++ */
++int
++glnx_chase_and_mkdirat (int dirfd,
++ const char *path,
++ GlnxChaseFlags flags,
++ mode_t mode,
++ GError **error)
++{
++ g_return_val_if_fail ((flags & ~(GLNX_CHASE_ALL_FLAGS)) == 0, -1);
++ g_return_val_if_fail ((flags & (GLNX_CHASE_MUST_BE_REGULAR |
++ GLNX_CHASE_MUST_BE_SOCKET |
++ GLNX_CHASE_MUST_BE_DIRECTORY)) == 0, -1);
++ g_return_val_if_fail ((mode & ~((mode_t) 07777)) == 0, -1);
++
++ /* This function always implies GLNX_CHASE_MUST_BE_DIRECTORY */
++ flags |= GLNX_CHASE_MUST_BE_DIRECTORY;
++
++ return glnx_chaseat_full (dirfd, path, flags,
++ chase_and_mkdir, GINT_TO_POINTER (mode),
++ error);
++}
+diff --git a/subprojects/libglnx/glnx-chase.h b/subprojects/libglnx/glnx-chase.h
+index 05dac12dae..af5f2bf407 100644
+--- a/subprojects/libglnx/glnx-chase.h
++++ b/subprojects/libglnx/glnx-chase.h
+@@ -48,4 +48,10 @@ int glnx_chase_and_statxat (int dirfd,
+ struct glnx_statx *statbuf,
+ GError **error);
+
++int glnx_chase_and_mkdirat (int dirfd,
++ const char *path,
++ GlnxChaseFlags flags,
++ mode_t mode,
++ GError **error);
++
+ G_END_DECLS
+diff --git a/subprojects/libglnx/tests/test-libglnx-chase.c b/subprojects/libglnx/tests/test-libglnx-chase.c
+index b0ce1b4145..0a7a6551b2 100644
+--- a/subprojects/libglnx/tests/test-libglnx-chase.c
++++ b/subprojects/libglnx/tests/test-libglnx-chase.c
+@@ -50,6 +50,18 @@ path_get_ino (const char *path)
+ return st.st_ino;
+ }
+
++static mode_t
++get_mode (int fd)
++{
++ int r;
++ struct stat st;
++
++ r = fstatat (fd, "", &st, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
++ g_assert_cmpint (r, >=, 0);
++
++ return st.st_mode & 0777;
++}
++
+ static char *
+ get_abspath (int dfd,
+ const char *path)
+@@ -586,6 +598,62 @@ test_chase_and_statxat_permissions (void)
+ g_clear_fd (&chase_fd, NULL);
+ }
+
++static void
++test_chase_and_mkdir (void)
++{
++ g_autoptr(GError) error = NULL;
++ glnx_autofd int dfd = -1;
++ glnx_autofd int file_fd = -1;
++ glnx_autofd int chase_fd = -1;
++ ino_t expected_ino;
++
++ g_assert_true (glnx_shutil_mkdir_p_at_open (AT_FDCWD, "d1", 0755,
++ &dfd,
++ NULL, &error));
++ g_assert_no_error (error);
++
++ chase_fd = glnx_chase_and_mkdirat (AT_FDCWD, "d1/d2/d3",
++ GLNX_CHASE_DEFAULT,
++ 0755,
++ &error);
++ g_assert_cmpint (chase_fd, >=, 0);
++ g_assert_no_error (error);
++
++ file_fd = openat (AT_FDCWD, "d1/d2/d3", O_PATH | O_CLOEXEC | O_NOFOLLOW);
++ g_assert_cmpint (file_fd, >=, 0);
++ expected_ino = get_ino (file_fd);
++
++ g_assert_cmpint (get_ino (chase_fd), ==, expected_ino);
++
++ g_assert_cmpint (get_mode (dfd), ==, 0755);
++ g_assert_cmpint (get_mode (chase_fd), ==, 0755);
++
++ g_clear_fd (&chase_fd, NULL);
++ g_clear_fd (&file_fd, NULL);
++
++ chase_fd = glnx_chase_and_mkdirat (AT_FDCWD, "d1/d4/d5",
++ GLNX_CHASE_DEFAULT,
++ 0700,
++ &error);
++ g_assert_cmpint (chase_fd, >=, 0);
++ g_assert_no_error (error);
++
++ file_fd = openat (AT_FDCWD, "d1", O_PATH | O_CLOEXEC | O_NOFOLLOW);
++ g_assert_cmpint (file_fd, >=, 0);
++ g_assert_cmpint (get_mode (file_fd), ==, 0755);
++ g_clear_fd (&file_fd, NULL);
++
++ file_fd = openat (AT_FDCWD, "d1/d4", O_PATH | O_CLOEXEC | O_NOFOLLOW);
++ g_assert_cmpint (file_fd, >=, 0);
++ g_assert_cmpint (get_mode (file_fd), ==, 0700);
++ g_clear_fd (&file_fd, NULL);
++
++ file_fd = openat (AT_FDCWD, "d1/d4/d5", O_PATH | O_CLOEXEC | O_NOFOLLOW);
++ g_assert_cmpint (file_fd, >=, 0);
++ g_assert_cmpint (get_mode (file_fd), ==, 0700);
++ g_clear_fd (&file_fd, NULL);
++}
++
+ int main (int argc, char **argv)
+ {
+ _GLNX_TEST_SCOPED_TEMP_DIR;
+@@ -602,6 +670,7 @@ int main (int argc, char **argv)
+ g_test_add_func ("/chase-and-statxat-basic", test_chase_and_statxat_basic);
+ g_test_add_func ("/chase-and-statxat-symlink", test_chase_and_statxat_symlink);
+ g_test_add_func ("/chase-and-statxat-permissions", test_chase_and_statxat_permissions);
++ g_test_add_func ("/chase-and-mkdir", test_chase_and_mkdir);
+
+ ret = g_test_run();
+
+
+
+From d902a41b522db3268ab2687de60a93637f39ae12 Mon Sep 17 00:00:00 2001
+From: Sebastian Wick <sebastian.wick@redhat.com>
+Date: Thu, 18 Jun 2026 17:58:10 +0200
+Subject: [PATCH] common: Fix return value and typos in
+ flatpak_switch_symlink_and_remove
+
+One error path returned -1 instead of FALSE. Since gboolean is gint,
+-1 is truthy and the caller would skip error handling.
+
+Assisted-by: Claude:opus-4.6
+Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-99wv-m8rp-g58x
+---
+ common/flatpak-utils.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c
+index 09102fd8f9..e1f771200b 100644
+--- a/common/flatpak-utils.c
++++ b/common/flatpak-utils.c
+@@ -939,10 +939,10 @@ flatpak_str_is_alphanumeric (const char *arg)
+ }
+
+ /* This atomically replaces a symlink with a new value, removing the
+- * existing symlink target, if it exstis and is different from
++ * existing symlink target, if it exists and is different from
+ * @target. This is atomic in the sense that we're guaranteed to
+ * remove any existing symlink target (once), independent of how many
+- * processes do the same operation in parallele. However, it is still
++ * processes do the same operation in parallel. However, it is still
+ * possible that we remove the old and then fail to create the new
+ * symlink for some reason, ending up with neither the old or the new
+ * target. That is fine if the reason for the symlink is keeping a
+@@ -994,7 +994,7 @@ flatpak_switch_symlink_and_remove (const char *symlink_path,
+ if (old_target == NULL)
+ return FALSE;
+
+- /* Don't remove old file if its the same as the new one */
++ /* Don't remove old file if it's the same as the new one */
+ if (strcmp (old_target, target) != 0)
+ {
+ if (flatpak_str_is_alphanumeric (old_target))
+@@ -1014,7 +1014,7 @@ flatpak_switch_symlink_and_remove (const char *symlink_path,
+ {
+ glnx_set_error_from_errno (error);
+ unlink (tmp_path);
+- return -1;
++ return FALSE;
+ }
+ unlink (tmp_path);
+
+
+
+From a0f48ed52d004f0a0f093d9fd977a19ea09fea23 Mon Sep 17 00:00:00 2001
+From: Sebastian Wick <sebastian.wick@redhat.com>
+Date: Thu, 18 Jun 2026 17:59:23 +0200
+Subject: [PATCH] common: Use fd-based operations in
+ flatpak_switch_symlink_and_remove
+
+Replace path-based syscalls with fd-relative equivalents so callers
+can pin the directory identity and prevent symlink substitution by a
+concurrent process.
+
+Assisted-by: Claude:opus-4.6
+Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-99wv-m8rp-g58x
+---
+ common/flatpak-run.c | 10 +++-
+ common/flatpak-utils-private.h | 3 +-
+ common/flatpak-utils.c | 84 +++++++++++++++++++---------------
+ 3 files changed, 56 insertions(+), 41 deletions(-)
+
+diff --git a/common/flatpak-run.c b/common/flatpak-run.c
+index 7d46dd6be6..cc9edca5ce 100644
+--- a/common/flatpak-run.c
++++ b/common/flatpak-run.c
+@@ -2801,7 +2801,7 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ }
+ else
+ {
+- g_autoptr(GFile) active = g_file_get_child (ld_so_dir, "active");
++ glnx_autofd int ld_so_dir_fd = -1;
+
+ /* For app-dirs we keep one checksum alive, by pointing the active symlink to it */
+
+@@ -2812,7 +2812,13 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ return -1;
+ }
+
+- if (!flatpak_switch_symlink_and_remove (flatpak_file_get_path_cached (active),
++ if (!glnx_opendirat (AT_FDCWD,
++ flatpak_file_get_path_cached (ld_so_dir),
++ FALSE, &ld_so_dir_fd,
++ error))
++ return -1;
++
++ if (!flatpak_switch_symlink_and_remove (ld_so_dir_fd, "active",
+ checksum, error))
+ return -1;
+ }
+diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h
+index 75538399ec..b071e7ea4a 100644
+--- a/common/flatpak-utils-private.h
++++ b/common/flatpak-utils-private.h
+@@ -154,7 +154,8 @@ flatpak_auto_lock_helper (GMutex *mutex)
+ return mutex;
+ }
+
+-gboolean flatpak_switch_symlink_and_remove (const char *symlink_path,
++gboolean flatpak_switch_symlink_and_remove (int dir_fd,
++ const char *symlink_name,
+ const char *target,
+ GError **error);
+
+diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c
+index e1f771200b..2a4b0024f7 100644
+--- a/common/flatpak-utils.c
++++ b/common/flatpak-utils.c
+@@ -938,34 +938,38 @@ flatpak_str_is_alphanumeric (const char *arg)
+ return TRUE;
+ }
+
+-/* This atomically replaces a symlink with a new value, removing the
+- * existing symlink target, if it exists and is different from
+- * @target. This is atomic in the sense that we're guaranteed to
+- * remove any existing symlink target (once), independent of how many
+- * processes do the same operation in parallel. However, it is still
+- * possible that we remove the old and then fail to create the new
+- * symlink for some reason, ending up with neither the old or the new
+- * target. That is fine if the reason for the symlink is keeping a
+- * cache though.
+- * The target shall only be a file in the same directory as the symlink, and
+- * shall only contain the characters a-zA-Z0-9. This is so that the target of
+- * the symlink that gets removed is in the same directory as the link.
++/* Atomically replace the @symlink_name symlink in @dir_fd with one
++ * pointing to @target, removing the previous target file (if it
++ * exists and differs from @target).
++ *
++ * This is atomic in the sense that we're guaranteed to remove any
++ * existing symlink target (once), independent of how many processes
++ * do the same operation in parallel. However, it is still possible
++ * that we remove the old and then fail to create the new symlink for
++ * some reason, ending up with neither the old or the new target.
++ * That is fine if the reason for the symlink is keeping a cache
++ * though.
++ *
++ * All filesystem operations go through @dir_fd so the caller can
++ * guarantee the directory identity even if the path to it is
++ * attacker-controlled.
++ *
++ * @target shall only contain the characters a-zA-Z0-9 so that the
++ * old target file to be removed is always in the same directory.
+ */
+ gboolean
+-flatpak_switch_symlink_and_remove (const char *symlink_path,
++flatpak_switch_symlink_and_remove (int dir_fd,
++ const char *symlink_name,
+ const char *target,
+ GError **error)
+ {
+- g_autofree char *symlink_dir = g_path_get_dirname (symlink_path);
+- int try;
+-
+- for (try = 0; try < 100; try++)
++ for (size_t try = 0; try < 100; try++)
+ {
+- g_autofree char *tmp_path = NULL;
+- int fd;
++ g_autofree char *tmp_name = NULL;
++ glnx_autofd int fd = -1;
+
+ /* Try to atomically create the symlink */
+- if (TEMP_FAILURE_RETRY (symlink (target, symlink_path)) == 0)
++ if (TEMP_FAILURE_RETRY (symlinkat (target, dir_fd, symlink_name)) == 0)
+ return TRUE;
+
+ if (errno != EEXIST)
+@@ -975,22 +979,32 @@ flatpak_switch_symlink_and_remove (const char *symlink_path,
+ return FALSE;
+ }
+
+- /* The symlink existed, move it to a temporary name atomically, and remove target
+- if that succeeded. */
+- tmp_path = g_build_filename (symlink_dir, ".switched-symlink-XXXXXX", NULL);
++ /* The symlink existed, move it to a temporary name atomically,
++ * and remove its target if that succeeded.
++ * This generated filename doesn't need to be securely unique:
++ * we're only protecting against accidental collisions if two
++ * processes try to regenerate ld.so.cache at the same time. */
++ tmp_name = g_strdup_printf (".switched-symlink-%08X", g_random_int ());
+
+- fd = g_mkstemp_full (tmp_path, O_RDWR, 0644);
++ fd = openat (dir_fd, tmp_name,
++ O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC | O_NOFOLLOW, 0644);
+ if (fd == -1)
+ {
++ if (errno == EEXIST)
++ continue;
++
+ glnx_set_error_from_errno (error);
+ return FALSE;
+ }
+- close (fd);
++ g_clear_fd (&fd, NULL);
+
+- if (TEMP_FAILURE_RETRY (rename (symlink_path, tmp_path)) == 0)
++ if (TEMP_FAILURE_RETRY (renameat (dir_fd, symlink_name,
++ dir_fd, tmp_name)) == 0)
+ {
+ /* The move succeeded, now we can remove the old target */
+- g_autofree char *old_target = flatpak_readlink (tmp_path, error);
++ g_autofree char *old_target = NULL;
++
++ old_target = glnx_readlinkat_malloc (dir_fd, tmp_name, NULL, error);
+ if (old_target == NULL)
+ return FALSE;
+
+@@ -998,25 +1012,19 @@ flatpak_switch_symlink_and_remove (const char *symlink_path,
+ if (strcmp (old_target, target) != 0)
+ {
+ if (flatpak_str_is_alphanumeric (old_target))
+- {
+- g_autofree char *old_target_path = NULL;
+-
+- old_target_path = g_build_filename (symlink_dir, old_target, NULL);
+- unlink (old_target_path);
+- }
++ unlinkat (dir_fd, old_target, 0);
+ else
+- {
+- g_warning ("Refusing to delete old link target %s", old_target);
+- }
++ g_warning ("Refusing to delete old link target %s", old_target);
+ }
+ }
+ else if (errno != ENOENT)
+ {
+ glnx_set_error_from_errno (error);
+- unlink (tmp_path);
++ unlinkat (dir_fd, tmp_name, 0);
+ return FALSE;
+ }
+- unlink (tmp_path);
++
++ unlinkat (dir_fd, tmp_name, 0);
+
+ /* An old target was removed, try again */
+ }
+
+
+From aa35286d1f8ca5ab04de01560aaef349108cc356 Mon Sep 17 00:00:00 2001
+From: Sebastian Wick <sebastian.wick@redhat.com>
+Date: Thu, 18 Jun 2026 17:59:47 +0200
+Subject: [PATCH] run: Harden regenerate_ld_cache against symlink attacks
+
+A sandboxed app can replace ~/.var/app/$appid/.ld.so with a symlink,
+causing regenerate_ld_cache to write files at an arbitrary location.
+A concurrent app instance makes this a TOCTOU even after the initial
+directory verification.
+
+Replace all path-based operations with fd-based equivalents using
+ld_so_dir_fd obtained via glnx_chase_and_mkdirat, and pass the
+directory to bwrap via --bind-fd instead of --bind.
+
+Assisted-by: Claude:opus-4.6
+Resolves: https://github.com/flatpak/flatpak/security/advisories/GHSA-99wv-m8rp-g58x
+---
+ common/flatpak-run.c | 88 ++++++++++++++++++++++++++++++--------------
+ 1 file changed, 61 insertions(+), 27 deletions(-)
+
+diff --git a/common/flatpak-run.c b/common/flatpak-run.c
+index cc9edca5ce..2793d1a984 100644
+--- a/common/flatpak-run.c
++++ b/common/flatpak-run.c
+@@ -2691,33 +2691,72 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ {
+ g_autoptr(FlatpakBwrap) bwrap = NULL;
+ g_autoptr(GArray) combined_fd_array = NULL;
+- g_autoptr(GFile) ld_so_cache = NULL;
+- g_autoptr(GFile) ld_so_cache_tmp = NULL;
+ g_autofree char *sandbox_cache_path = NULL;
+ g_autofree char *tmp_basename = NULL;
+ g_auto(GStrv) minimal_envp = NULL;
+ g_autofree char *commandline = NULL;
+ int exit_status;
+ glnx_autofd int ld_so_fd = -1;
+- g_autoptr(GFile) ld_so_dir = NULL;
++ glnx_autofd int ld_so_dir_fd = -1;
++ g_autofree char *ld_so_dir_path = NULL;
+
+ if (app_id_dir)
+- ld_so_dir = g_file_get_child (app_id_dir, ".ld.so");
++ {
++ glnx_autofd int app_id_dir_fd = -1;
++
++ app_id_dir_fd = glnx_chase_and_mkdirat (AT_FDCWD,
++ flatpak_file_get_path_cached (app_id_dir),
++ GLNX_CHASE_DEFAULT,
++ 0700, error);
++ if (app_id_dir_fd < 0)
++ {
++ g_prefix_error (error, "cannot open %s: ",
++ flatpak_file_get_path_cached (app_id_dir));
++ return -1;
++ }
++
++ ld_so_dir_fd = glnx_chase_and_mkdirat (app_id_dir_fd, ".ld.so",
++ GLNX_CHASE_RESOLVE_NO_SYMLINKS,
++ 0755, error);
++
++ ld_so_dir_path = g_build_filename (flatpak_file_get_path_cached (app_id_dir),
++ ".ld.so",
++ NULL);
++ }
+ else
+ {
+- g_autoptr(GFile) base_dir = g_file_new_for_path (g_get_user_cache_dir ());
+- ld_so_dir = g_file_resolve_relative_path (base_dir, "flatpak/ld.so");
++ glnx_autofd int cache_dir_fd = -1;
++
++ cache_dir_fd = glnx_chase_and_mkdirat (AT_FDCWD,
++ g_get_user_cache_dir (),
++ GLNX_CHASE_DEFAULT,
++ 0700, error);
++ if (cache_dir_fd < 0)
++ {
++ g_prefix_error (error, "cannot open %s: ",
++ g_get_user_cache_dir ());
++ return -1;
++ }
++
++ ld_so_dir_fd = glnx_chase_and_mkdirat (cache_dir_fd, "flatpak/ld.so",
++ GLNX_CHASE_RESOLVE_NO_SYMLINKS,
++ 0755, error);
++
++ ld_so_dir_path = g_build_filename (g_get_user_cache_dir (),
++ "flatpak/ld.so",
++ NULL);
+ }
+
+- ld_so_cache = g_file_get_child (ld_so_dir, checksum);
+- ld_so_fd = open (flatpak_file_get_path_cached (ld_so_cache), O_RDONLY);
+- if (ld_so_fd >= 0)
+- return g_steal_fd (&ld_so_fd);
++ if (ld_so_dir_fd < 0)
++ {
++ g_prefix_error (error, "cannot open %s: ", ld_so_dir_path);
++ return -1;
++ }
+
+- g_info ("Regenerating ld.so.cache %s", flatpak_file_get_path_cached (ld_so_cache));
++ if (glnx_openat_rdonly (ld_so_dir_fd, checksum, FALSE, &ld_so_fd, NULL))
++ return g_steal_fd (&ld_so_fd);
+
+- if (!flatpak_mkdir_p (ld_so_dir, cancellable, error))
+- return FALSE;
++ g_info ("Regenerating ld.so.cache %s/%s", ld_so_dir_path, checksum);
+
+ minimal_envp = flatpak_run_get_minimal_env (FALSE, FALSE);
+ bwrap = flatpak_bwrap_new (minimal_envp);
+@@ -2740,7 +2779,6 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ glnx_gen_temp_name (tmp_basename);
+
+ sandbox_cache_path = g_build_filename ("/run/ld-so-cache-dir", tmp_basename, NULL);
+- ld_so_cache_tmp = g_file_get_child (ld_so_dir, tmp_basename);
+
+ flatpak_bwrap_add_args (bwrap,
+ "--unshare-pid",
+@@ -2748,8 +2786,13 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ "--unshare-net",
+ "--proc", "/proc",
+ "--dev", "/dev",
+- "--bind", flatpak_file_get_path_cached (ld_so_dir), "/run/ld-so-cache-dir",
+ NULL);
++
++ if (!flatpak_bwrap_add_args_data_fd_dup (bwrap, "--bind-fd",
++ ld_so_dir_fd, "/run/ld-so-cache-dir",
++ error))
++ return -1;
++
+ flatpak_bwrap_sort_envp (bwrap);
+ flatpak_bwrap_envp_to_args (bwrap);
+
+@@ -2787,8 +2830,7 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ return -1;
+ }
+
+- ld_so_fd = open (flatpak_file_get_path_cached (ld_so_cache_tmp), O_RDONLY);
+- if (ld_so_fd < 0)
++ if (!glnx_openat_rdonly (ld_so_dir_fd, tmp_basename, FALSE, &ld_so_fd, NULL))
+ {
+ flatpak_fail_error (error, FLATPAK_ERROR_SETUP_FAILED, _("Can't open generated ld.so.cache"));
+ return -1;
+@@ -2797,27 +2839,19 @@ regenerate_ld_cache (GPtrArray *base_argv_array,
+ if (app_id_dir == NULL)
+ {
+ /* For runs without an app id dir we always regenerate the ld.so.cache */
+- unlink (flatpak_file_get_path_cached (ld_so_cache_tmp));
++ unlinkat (ld_so_dir_fd, tmp_basename, 0);
+ }
+ else
+ {
+- glnx_autofd int ld_so_dir_fd = -1;
+-
+ /* For app-dirs we keep one checksum alive, by pointing the active symlink to it */
+
+ /* Rename to known name, possibly overwriting existing ref if race */
+- if (rename (flatpak_file_get_path_cached (ld_so_cache_tmp), flatpak_file_get_path_cached (ld_so_cache)) == -1)
++ if (renameat (ld_so_dir_fd, tmp_basename, ld_so_dir_fd, checksum) == -1)
+ {
+ glnx_set_error_from_errno (error);
+ return -1;
+ }
+
+- if (!glnx_opendirat (AT_FDCWD,
+- flatpak_file_get_path_cached (ld_so_dir),
+- FALSE, &ld_so_dir_fd,
+- error))
+- return -1;
+-
+ if (!flatpak_switch_symlink_and_remove (ld_so_dir_fd, "active",
+ checksum, error))
+ return -1;
diff --git a/flatpak.spec b/flatpak.spec
index e5d0a96..a9f6004 100644
--- a/flatpak.spec
+++ b/flatpak.spec
@@ -25,6 +25,7 @@ Source1: flatpak-add-fedora-repos.service
%endif
Patch0: CVE-2026-96808.patch
+Patch1: CVE-2026-96807.patch
# ostree not on i686 for RHEL 10
# https://github.com/containers/composefs/pull/229#issuecomment-1838735764
@@ -294,6 +295,7 @@ fi
%changelog
* Fri Oct 23 2026 Adrian Vovk <avovk@redhat.com> - 1.16.6-2
- Fix CVE-2026-96808
+- Fix CVE-2026-96807
* Fri Apr 10 2026 Michael Catanzaro <mcatanzaro@redhat.com> - 1.16.6-1
- Update to 1.16.6
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 22:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 22:25 [rpms/flatpak] f43: Fix CVE-2026-96807 Adrian Vovk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox