Version in base suite: 1.16.6-1~deb13u3 Base version: flatpak_1.16.6-1~deb13u3 Target version: flatpak_1.16.6-1~deb13u4 Base file: /srv/ftp-master.debian.org/ftp/pool/main/f/flatpak/flatpak_1.16.6-1~deb13u3.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/f/flatpak/flatpak_1.16.6-1~deb13u4.dsc changelog | 15 patches/CVE-2026-133842/tests-Assert-that-extra-data-can-t-normally-contain-setui.patch | 94 ++ patches/CVE-2026-133842/tests-Test-deeply-nested-files-in-apply_extra-output.patch | 314 +++++++++ patches/CVE-2026-133842/utils-Fail-closed-if-canonicalizing-permissions-can-t-ope.patch | 54 + patches/CVE-2026-133842/utils-Fail-closed-when-canonicalizing-permissions-if-read.patch | 43 + patches/CVE-2026-133845/common-Add-an-object-tracking-unique-fds-in-a-D-Bus-messa.patch | 341 ++++++++++ patches/CVE-2026-133845/portal-Exit-the-child-process-if-mapping-fds-fails.patch | 44 + patches/CVE-2026-133845/portal-Rename-app_fd-usr_fd-variables-to-indicate-that-th.patch | 78 ++ patches/CVE-2026-133845/portal-Use-FlatpakUniqueFDList-to-prevent-multiple-uses-o.patch | 241 +++++++ patches/CVE-2026-133845/session-helper-Use-FlatpakUniqueFDList-here-too.patch | 106 +++ patches/CVE-2026-133845/tests-Assert-we-get-an-error-when-mapping-1-handle-to-the.patch | 136 +++ patches/series | 11 patches/tests/tests-add-test-run-custom.sh-to-test-matrix-source.patch | 25 13 files changed, 1502 insertions(+) dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmpcu568u0r/flatpak_1.16.6-1~deb13u3.dsc: no acceptable signature found dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmpcu568u0r/flatpak_1.16.6-1~deb13u4.dsc: no acceptable signature found diff -Nru flatpak-1.16.6/debian/changelog flatpak-1.16.6/debian/changelog --- flatpak-1.16.6/debian/changelog 2026-09-28 13:13:01.000000000 +0000 +++ flatpak-1.16.6/debian/changelog 2026-11-24 14:26:21.000000000 +0000 @@ -1,3 +1,18 @@ +flatpak (1.16.6-1~deb13u4) trixie-security; urgency=high + + * d/patches: Backport security fixes from 1.18.6: + - d/p/tests/*.patch: Fix automatic generation of test matrix + - d/p/CVE-2026-133842/*.patch: + Prevent a malicious app/runtime/extension from creating setuid-root + executables in /var/lib/flatpak which a cooperating local user could + use for privilege escalation + (CVE-2026-133842, GHSA-p4mw-6jfq-r82r) + - d/p/CVE-2026-133845/*.patch: + Prevent a sandbox escape via crafted messages to flatpak-portal + (CVE-2026-133845, GHSA-5jrj-948r-2wx6) + + -- Simon McVittie Tue, 24 Nov 2026 14:26:21 +0000 + flatpak (1.16.6-1~deb13u3) trixie-security; urgency=high * d/patches: Backport security fixes from 1.18.4 (Closes: #1149218): diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Assert-that-extra-data-can-t-normally-contain-setui.patch flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Assert-that-extra-data-can-t-normally-contain-setui.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Assert-that-extra-data-can-t-normally-contain-setui.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Assert-that-extra-data-can-t-normally-contain-setui.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,94 @@ +From: Simon McVittie +Date: Mon, 16 Nov 2026 20:15:53 +0000 +Subject: tests: Assert that extra-data can't normally contain setuid/setgid + files + +In the common case where we are able to traverse the whole directory +hierarchy generated by apply_extra, we should find that there is nothing +setuid or setgid left in it. + +Helps: CVE-2026-133842 +Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-p4mw-6jfq-r82r +Signed-off-by: Simon McVittie +--- + tests/apply-extra-static.c | 28 +++++++++++++++++++++++++++- + tests/test-extra-data.sh | 17 +++++++++++++++++ + 2 files changed, 44 insertions(+), 1 deletion(-) + +diff --git a/tests/apply-extra-static.c b/tests/apply-extra-static.c +index 5be3993..1f6dcbb 100644 +--- a/tests/apply-extra-static.c ++++ b/tests/apply-extra-static.c +@@ -1,3 +1,4 @@ ++#include + #include + #include + #include +@@ -5,11 +6,36 @@ + static const char msg[] = "noruntime-extra-data\n"; + + int main(void) { ++ int dfd = -1; ++ int exe_fd = -1; ++ + mkdir("/app/extra", 0755); +- int fd = open("/app/extra/ran", O_WRONLY | O_CREAT | O_TRUNC, 0644); ++ int fd = open("/app/extra/ran", O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd < 0) + return 1; + write(fd, msg, sizeof(msg) - 1); + close(fd); ++ ++ dfd = open ("/app/extra", O_CLOEXEC | O_DIRECTORY | O_PATH | O_NOFOLLOW); ++ ++ if (dfd < 0) ++ err (1, "open /app/extra"); ++ ++ exe_fd = openat (dfd, "exe", O_CLOEXEC | O_CREAT | O_EXCL | O_RDWR, 02744); ++ ++ if (exe_fd < 0) ++ err (1, "openat /app/extra/exe"); ++ ++ if (fchmod (exe_fd, 06744) < 0) ++ err (1, "fchmod /app/extra/exe"); ++ ++ if (close (exe_fd) < 0) ++ err (1, "close /app/extra/exe"); ++ ++ exe_fd = -1; ++ ++ close (dfd); ++ dfd = -1; ++ + return 0; + } +diff --git a/tests/test-extra-data.sh b/tests/test-extra-data.sh +index 73fe3ce..374b32e 100755 +--- a/tests/test-extra-data.sh ++++ b/tests/test-extra-data.sh +@@ -95,8 +95,25 @@ if test -f "${G_TEST_BUILDDIR}/apply-extra-static"; then + build_extra_data_noruntime_app repos/test ${BRANCH} + update_repo ${REPONAME} ${COLLECTION_ID} + ${FLATPAK} ${U} install --or-update -y ${REPONAME}-repo org.test.ExtraDataNoRuntime ${BRANCH} >&2 ++ + DEPLOY_DIR="$(${FLATPAK} ${U} info --show-location org.test.ExtraDataNoRuntime)" ++ ( find "${DEPLOY_DIR}/files/extra" -not -type d -ls || true ) | sed -e 's/^/# /' >&2 ++ + assert_file_has_content "${DEPLOY_DIR}/files/extra/ran" "^noruntime-extra-data$" ++ ++ # Permissions of non-executable files are normalized to 0644 ++ assert_file_has_mode "${DEPLOY_DIR}/files/extra/ran" 644 ++ ++ # A setuid and/or setgid executable file is normalized to 0755 to avoid ++ # becoming a privilege escalation vector ++ assert_file_has_mode "${DEPLOY_DIR}/files/extra/exe" 755 ++ ++ # There must not be any setuid or setgid files in the deploy dir ++ find "${DEPLOY_DIR}/files/extra" -type f -perm -4000 > setuid-files ++ assert_not_file_has_content setuid-files . ++ find "${DEPLOY_DIR}/files/extra" -type f -perm -2000 > setgid-files ++ assert_not_file_has_content setgid-files . ++ + ${FLATPAK} ${U} uninstall -y org.test.ExtraDataNoRuntime >&2 + ok "install+run extra data app with NoRuntime" + else diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Test-deeply-nested-files-in-apply_extra-output.patch flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Test-deeply-nested-files-in-apply_extra-output.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Test-deeply-nested-files-in-apply_extra-output.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133842/tests-Test-deeply-nested-files-in-apply_extra-output.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,314 @@ +From: Simon McVittie +Date: Thu, 19 Nov 2026 16:03:01 +0000 +Subject: tests: Test deeply nested files in apply_extra output + +Check that if we can't prevent a file in a deeply nested directory from +being left setuid or setgid, then at least we leave one of its ancestors +with 0700 permissions, so that unprivileged processes can't reach into +the directory and use the setuid/setgid executable to escalate privileges. + +Helps: CVE-2026-133842 +Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-p4mw-6jfq-r82r +Signed-off-by: Simon McVittie +[backport to 1.18.x: resolve minor conflict in tests/meson.build] +[backport to 1.16.x: use tests/test-matrix/] +--- + common/flatpak-dir.c | 2 + + tests/apply-extra-deeply-nested-setuid.c | 75 +++++++++++++++++ + tests/meson.build | 9 +++ + tests/test-extra-data-defang.sh | 135 +++++++++++++++++++++++++++++++ + tests/test-matrix/meson.build | 6 +- + tests/update-test-matrix | 1 + + 6 files changed, 226 insertions(+), 2 deletions(-) + create mode 100644 tests/apply-extra-deeply-nested-setuid.c + create mode 100644 tests/test-extra-data-defang.sh + +diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c +index b9e95e6..a60c203 100644 +--- a/common/flatpak-dir.c ++++ b/common/flatpak-dir.c +@@ -9173,6 +9173,8 @@ flatpak_dir_deploy (FlatpakDir *self, + return flatpak_fail_error (error, FLATPAK_ERROR_ALREADY_INSTALLED, + _("%s commit %s already installed"), flatpak_decomposed_get_ref (ref), checksum); + ++ /* If you change how this directory is named, also update ++ * tests/test-extra-data-defang.sh */ + g_autofree char *template = g_strdup_printf (".%s-XXXXXX", checkout_basename); + + if (!glnx_mkdtempat (deploy_base_dfd, template, 0755, &tmp_dir_handle, NULL)) +diff --git a/tests/apply-extra-deeply-nested-setuid.c b/tests/apply-extra-deeply-nested-setuid.c +new file mode 100644 +index 0000000..4fc15e2 +--- /dev/null ++++ b/tests/apply-extra-deeply-nested-setuid.c +@@ -0,0 +1,75 @@ ++/* ++ * Copyright 2026 Collabora Ltd. ++ * SPDX-License-Identifier: LGPL-2.1-or-later ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++/* We want this to be more than the default RLIMIT_NOFILE, 1024. */ ++size_t depth = 1234; ++ ++int main(void) ++{ ++ int dfd = -1; ++ int exe_fd = -1; ++ ++ if (mkdir ("/app/extra", 0755) < 0 && errno != EEXIST) ++ err (1, "mkdir /app/extra"); ++ ++ dfd = open ("/app/extra", O_CLOEXEC | O_DIRECTORY | O_PATH | O_NOFOLLOW); ++ ++ if (dfd < 0) ++ err (1, "open /app/extra"); ++ ++ exe_fd = openat (dfd, "exe", O_CLOEXEC | O_CREAT | O_EXCL | O_RDWR, 02744); ++ ++ if (exe_fd < 0) ++ err (1, "openat /app/extra/exe"); ++ ++ if (fchmod (exe_fd, 06744) < 0) ++ err (1, "fchmod /app/extra/exe"); ++ ++ if (close (exe_fd) < 0) ++ err (1, "close /app/extra/exe"); ++ ++ exe_fd = -1; ++ ++ for (size_t i = 1; i <= depth; i++) ++ { ++ int child_dfd = -1; ++ ++ if (mkdirat (dfd, "d", 0755) < 0) ++ err (1, "mkdirat depth=%zu", i); ++ ++ child_dfd = openat (dfd, "d", O_CLOEXEC | O_DIRECTORY | O_PATH | O_NOFOLLOW); ++ ++ if (child_dfd < 0) ++ err (1, "openat depth=%zu", i); ++ ++ close (dfd); ++ dfd = child_dfd; ++ child_dfd = -1; ++ } ++ ++ exe_fd = openat (dfd, "exe", O_CLOEXEC | O_CREAT | O_EXCL | O_RDWR, 02744); ++ ++ if (exe_fd < 0) ++ err (1, "openat /app/extra/d/.../d/exe"); ++ ++ if (fchmod (exe_fd, 06744) < 0) ++ err (1, "fchmod /app/extra/d/.../d/exe"); ++ ++ if (close (exe_fd) < 0) ++ err (1, "close /app/extra/d/.../d/exe"); ++ ++ exe_fd = -1; ++ ++ close (dfd); ++ dfd = -1; ++ ++ return 0; ++} +diff --git a/tests/meson.build b/tests/meson.build +index 8a9db82..6f8b8c3 100644 +--- a/tests/meson.build ++++ b/tests/meson.build +@@ -303,6 +303,15 @@ if cc.links('#include \nint main(void) { printf("test"); return 0; }', + override_options : ['b_sanitize=none'], + link_args : ['-static'], + ) ++ ++ executable( ++ 'apply-extra-deeply-nested-setuid', ++ 'apply-extra-deeply-nested-setuid.c', ++ install : get_option('installed_tests'), ++ install_dir : installed_testdir, ++ override_options : ['b_sanitize=none'], ++ link_args : ['-static'], ++ ) + else + warning('static libc not available, apply-extra-static will be skipped') + endif +diff --git a/tests/test-extra-data-defang.sh b/tests/test-extra-data-defang.sh +new file mode 100644 +index 0000000..de12e7a +--- /dev/null ++++ b/tests/test-extra-data-defang.sh +@@ -0,0 +1,135 @@ ++#!/bin/bash ++# ++# Copyright (C) 2025 Red Hat, Inc ++# Copyright (C) 2026 Collabora Ltd. ++# ++# This library is free software; you can redistribute it and/or ++# modify it under the terms of the GNU Lesser General Public ++# License as published by the Free Software Foundation; either ++# version 2 of the License, or (at your option) any later version. ++# ++# This library is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# Lesser General Public License for more details. ++# ++# You should have received a copy of the GNU Lesser General Public ++# License along with this library; if not, write to the ++# Free Software Foundation, Inc., 59 Temple Place - Suite 330, ++# Boston, MA 02111-1307, USA. ++ ++set -euo pipefail ++ ++# shellcheck source=tests/libtest.sh ++. "$(dirname "$0")/libtest.sh" ++ ++skip_without_bwrap ++ ++REPONAME="test" ++BRANCH="master" ++COLLECTION_ID="org.test.Collection.${REPONAME}" ++ ++setup_repo ${REPONAME} ${COLLECTION_ID} ++ ++# create the extra data ++EXTRA_DATA_FILE="extra-data-test" ++EXTRA_DATA_DIR="${TEST_DATA_DIR}/extra-data-server/" ++mkdir -p "${EXTRA_DATA_DIR}" ++echo "extra-data-test-content" > "${EXTRA_DATA_DIR}/${EXTRA_DATA_FILE}" ++ ++# serve the extra data ++httpd web-server.py "${EXTRA_DATA_DIR}" ++EXTRA_DATA_URL="http://127.0.0.1:$(cat httpd-port)/${EXTRA_DATA_FILE}" ++ ++# download to get the size and sha256 sum ++DOWNLOADED_EXTRA_DATA="${TEST_DATA_DIR}/downloaded-extra-data" ++curl "${EXTRA_DATA_URL}" -o "${DOWNLOADED_EXTRA_DATA}" ++EXTRA_DATA_SIZE=$(stat --printf="%s" "${DOWNLOADED_EXTRA_DATA}") ++EXTRA_DATA_SHA256=$(sha256sum "${DOWNLOADED_EXTRA_DATA}" | cut -f1 -d' ') ++ ++flatpak_maybe_user() { ++ # shellcheck disable=SC2086 ++ ${FLATPAK} ${U} "$@" ++} ++ ++build_extra_data_noruntime_app() { ++ local repo="$1" ++ local branch="$2" ++ ++ DIR="$(mktemp -d)" ++ ARCH="$(flatpak --default-arch)" ++ ++ mkdir -p "${DIR}/files/bin" ++ ++ cp "${G_TEST_BUILDDIR}/apply-extra-deeply-nested-setuid" "${DIR}/files/bin/apply_extra" ++ chmod +x "${DIR}/files/bin/apply_extra" ++ ++ cat > "${DIR}/metadata" <&2 ++ # shellcheck disable=SC2086 ++ flatpak build-export ${FL_GPGARGS} "${repo}" "${DIR}" "${branch}" >&2 ++ rm -rf "${DIR}" ++} ++ ++if test -f "${G_TEST_BUILDDIR}/apply-extra-deeply-nested-setuid"; then ++ build_extra_data_noruntime_app repos/test "${BRANCH}" ++ update_repo "${REPONAME}" "${COLLECTION_ID}" ++ ++ if flatpak_maybe_user install --or-update -y "${REPONAME}-repo" org.test.ExtraDataNoRuntime "${BRANCH}" >&2; then ++ DEPLOY_DIR="$(flatpak_maybe_user info --show-location org.test.ExtraDataNoRuntime)" ++ ( find "${DEPLOY_DIR}/files/extra" -not -type d -ls || true ) | sed -e 's/^/# /' >&2 ++ ++ # There must not be any setuid or setgid files in the deploy dir ++ find "${DEPLOY_DIR}/files/extra" -type f -perm -4000 > setuid-files ++ assert_not_file_has_content setuid-files . ++ find "${DEPLOY_DIR}/files/extra" -type f -perm -2000 > setgid-files ++ assert_not_file_has_content setgid-files . ++ ++ # `flatpak uninstall` won't necessarily be able to recover by ++ # deleting the directory that was so deeply nested, because the ++ # directory is also so deeply nested that we run out of fd limit ++ # while removing it ++ rm -fr "${DEPLOY_DIR}/files/extra" ++ ++ flatpak_maybe_user uninstall -y org.test.ExtraDataNoRuntime >&2 ++ ++ ok "extra-data app with deeply nested setuid binary was disarmed" ++ else ++ app_dir="${FL_DIR}/app/org.test.ExtraDataNoRuntime" ++ find "${app_dir}" -not -type d -ls | sed -e 's/^/# /' >&2 ++ ++ # This filename pattern needs to be kept in sync with the ++ # choice of deploy directory mkdtempat template in ++ # flatpak_dir_deploy() ++ for d in "${app_dir}/${ARCH}/${BRANCH}"/.*-*/files/extra; do ++ assert_file_has_mode "$d" 700 ++ ++ # All files for which it was feasible had their permissions reset ++ if [ -e "$d/exe" ]; then ++ assert_file_has_mode "$d/exe" 755 ++ fi ++ if [ -e "$d/extra-data-test" ]; then ++ assert_file_has_mode "$d/extra-data-test" 644 ++ fi ++ done ++ ++ rm -fr "${app_dir}" ++ ++ ok "extra-data app with deeply nested setuid binary refused to install" ++ fi ++else ++ ok "# SKIP install+run extra data app with NoRuntime apply-extra-deeply-nested-setuid not found" ++fi ++ ++done_testing +diff --git a/tests/test-matrix/meson.build b/tests/test-matrix/meson.build +index 037500e..1c10b6c 100644 +--- a/tests/test-matrix/meson.build ++++ b/tests/test-matrix/meson.build +@@ -31,6 +31,10 @@ wrapped_tests += {'name' : 'test-subset@user.wrap', 'script' : 'test-subset.sh'} + wrapped_tests += {'name' : 'test-subset@system.wrap', 'script' : 'test-subset.sh'} + wrapped_tests += {'name' : 'test-extra-data@user.wrap', 'script' : 'test-extra-data.sh'} + wrapped_tests += {'name' : 'test-extra-data@system.wrap', 'script' : 'test-extra-data.sh'} ++wrapped_tests += {'name' : 'test-extra-data-defang@user.wrap', 'script' : 'test-extra-data-defang.sh'} ++wrapped_tests += {'name' : 'test-extra-data-defang@system.wrap', 'script' : 'test-extra-data-defang.sh'} ++wrapped_tests += {'name' : 'test-run-custom@user.wrap', 'script' : 'test-run-custom.sh'} ++wrapped_tests += {'name' : 'test-run-custom@system.wrap', 'script' : 'test-run-custom.sh'} + wrapped_tests += {'name' : 'test-basic.sh', 'script' : 'test-basic.sh'} + wrapped_tests += {'name' : 'test-completion.sh', 'script' : 'test-completion.sh'} + wrapped_tests += {'name' : 'test-config.sh', 'script' : 'test-config.sh'} +@@ -47,5 +51,3 @@ wrapped_tests += {'name' : 'test-unused.sh', 'script' : 'test-unused.sh'} + wrapped_tests += {'name' : 'test-prune.sh', 'script' : 'test-prune.sh'} + wrapped_tests += {'name' : 'test-seccomp.sh', 'script' : 'test-seccomp.sh'} + wrapped_tests += {'name' : 'test-repair.sh', 'script' : 'test-repair.sh'} +-wrapped_tests += {'name' : 'test-run-custom@user.wrap', 'script' : 'test-run-custom.sh'} +-wrapped_tests += {'name' : 'test-run-custom@system.wrap', 'script' : 'test-run-custom.sh'} +\ No newline at end of file +diff --git a/tests/update-test-matrix b/tests/update-test-matrix +index 4c07fd0..2e89c58 100755 +--- a/tests/update-test-matrix ++++ b/tests/update-test-matrix +@@ -35,6 +35,7 @@ TEST_MATRIX_SOURCE=( + 'tests/test-seccomp.sh' \ + 'tests/test-repair.sh' \ + 'tests/test-extra-data.sh{user+system}' \ ++ 'tests/test-extra-data-defang.sh{user+system}' \ + 'tests/test-run-custom.sh{user+system}' \ + ) + diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-if-canonicalizing-permissions-can-t-ope.patch flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-if-canonicalizing-permissions-can-t-ope.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-if-canonicalizing-permissions-can-t-ope.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-if-canonicalizing-permissions-can-t-ope.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,54 @@ +From: Simon McVittie +Date: Mon, 16 Nov 2026 18:41:53 +0000 +Subject: utils: Fail closed if canonicalizing permissions can't open + directory + +An attacker who controls the `apply_extra` unpacker or its input +could force this to fail by creating a directory hierarchy deeper than +flatpak-system-helper's `RLIMIT_NOFILE` limit. If we allow +`flatpak_canonicalize_permissions()` to report success in that situation, +then there could still be a setuid-root executable in the deeply-nested +directory after reporting success, which a local user or code executing +with the privileges of a local user could use to elevate privileges +to root. + +Resolves: CVE-2026-133842 +Resolves: https://github.com/flatpak/flatpak/security/advisories/GHSA-p4mw-6jfq-r82r +Signed-off-by: Simon McVittie +--- + common/flatpak-utils.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c +index b4b8e55..cacb4ab 100644 +--- a/common/flatpak-utils.c ++++ b/common/flatpak-utils.c +@@ -1311,7 +1311,7 @@ _flatpak_canonicalize_permissions (int parent_dfd, + res = FALSE; + } + +- if (glnx_dirfd_iterator_init_at (parent_dfd, rel_path, FALSE, &dfd_iter, NULL)) ++ if (glnx_dirfd_iterator_init_at (parent_dfd, rel_path, FALSE, &dfd_iter, error)) + { + while (TRUE) + { +@@ -1327,8 +1327,19 @@ _flatpak_canonicalize_permissions (int parent_dfd, + } + } + } ++ else ++ { ++ /* Can't open for iteration, fail closed */ ++ error = NULL; ++ res = FALSE; ++ } + ++ /* Only chmod the top-level directory back to 0755 if we did not ++ * encounter any errors among its descendants. If we did, then it ++ * might still contain setuid/setgid files, and it isn't safe to let ++ * other users access those. */ + if (toplevel && ++ res && + fchmodat (parent_dfd, rel_path, 0755, 0) != 0) + { + glnx_set_error_from_errno (error); diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-when-canonicalizing-permissions-if-read.patch flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-when-canonicalizing-permissions-if-read.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-when-canonicalizing-permissions-if-read.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133842/utils-Fail-closed-when-canonicalizing-permissions-if-read.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,43 @@ +From: Simon McVittie +Date: Mon, 16 Nov 2026 18:45:00 +0000 +Subject: utils: Fail closed when canonicalizing permissions if readdir() + fails + +This is hardening: I'm not aware of a way for an attacker to make this +happen intentionally. But, if it can happen, the it would be another +way for an attacker to cause `chmod()` on a potentially setuid file +to be skipped. + +Helps: CVE-2026-133842 +Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-p4mw-6jfq-r82r +Signed-off-by: Simon McVittie +--- + common/flatpak-utils.c | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c +index cacb4ab..3aa382f 100644 +--- a/common/flatpak-utils.c ++++ b/common/flatpak-utils.c +@@ -1317,8 +1317,19 @@ _flatpak_canonicalize_permissions (int parent_dfd, + { + struct dirent *dent; + +- if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, NULL, NULL) || dent == NULL) +- break; ++ if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, NULL, error)) ++ { ++ /* Can't continue iteration, fail closed */ ++ error = NULL; ++ res = FALSE; ++ break; ++ } ++ ++ if (dent == NULL) ++ { ++ /* End of iteration, not an error */ ++ break; ++ } + + if (!_flatpak_canonicalize_permissions (dfd_iter.fd, dent->d_name, FALSE, uid, gid, error)) + { diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133845/common-Add-an-object-tracking-unique-fds-in-a-D-Bus-messa.patch flatpak-1.16.6/debian/patches/CVE-2026-133845/common-Add-an-object-tracking-unique-fds-in-a-D-Bus-messa.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133845/common-Add-an-object-tracking-unique-fds-in-a-D-Bus-messa.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133845/common-Add-an-object-tracking-unique-fds-in-a-D-Bus-messa.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,341 @@ +From: Simon McVittie +Date: Tue, 17 Nov 2026 21:21:06 +0000 +Subject: common: Add an object tracking unique fds in a D-Bus message + +In a D-Bus service that operates at a security boundary and accepts +more than one file descriptor in a method call, it's technically +possible for a method call to have more than one `UNIX_FD` entry +(or "handle" in GVariant jargon) that uses the same index into the array +of out-of-band fds. If this happens, it's easy for it to lead to a +double-close or use-after-close that could result in unintended fds +being closed or leaked into a subprocess. + +FlatpakUniqueFDList prevents this by requiring all fds attached to +the message to be distinct, and only allowing at most one `UNIX_FD` +to refer to each one. It's implemented in a separate source file +so that it will be easy to reuse in other projects like x-d-p +if necessary. + +This also encapsulates the range-check that ensures that the caller +doesn't specify a handle outside the range of the fds array, to try +to avoid mistakes. + +Helps: CVE-2026-133845 +Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-5jrj-948r-2wx6 +Signed-off-by: Simon McVittie +--- + common/flatpak-dbus-utils-private.h | 26 ++++++++ + common/flatpak-dbus-utils.c | 121 ++++++++++++++++++++++++++++++++++ + tests/meson.build | 5 ++ + tests/test-dbus-utils.c | 125 ++++++++++++++++++++++++++++++++++++ + 4 files changed, 277 insertions(+) + create mode 100644 common/flatpak-dbus-utils-private.h + create mode 100644 common/flatpak-dbus-utils.c + create mode 100644 tests/test-dbus-utils.c + +diff --git a/common/flatpak-dbus-utils-private.h b/common/flatpak-dbus-utils-private.h +new file mode 100644 +index 0000000..bb08078 +--- /dev/null ++++ b/common/flatpak-dbus-utils-private.h +@@ -0,0 +1,26 @@ ++/* vi:set et sw=2 sts=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e-s: ++ * ++ * Utilities for D-Bus services ++ * ++ * Copyright 2026 Collabora Ltd. ++ * SPDX-License-Identifier: LGPL-2.1-or-later ++ */ ++ ++#pragma once ++ ++#include "libglnx.h" ++ ++#include ++#include ++ ++typedef struct _FlatpakUniqueFDList FlatpakUniqueFDList; ++ ++void flatpak_unique_fd_list_free (FlatpakUniqueFDList *self); ++G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakUniqueFDList, flatpak_unique_fd_list_free) ++ ++FlatpakUniqueFDList *flatpak_unique_fd_list_new (GUnixFDList *fd_list, ++ GError **error); ++ ++int flatpak_unique_fd_list_get (FlatpakUniqueFDList *self, ++ int handle, ++ GError **error); +diff --git a/common/flatpak-dbus-utils.c b/common/flatpak-dbus-utils.c +new file mode 100644 +index 0000000..2e14112 +--- /dev/null ++++ b/common/flatpak-dbus-utils.c +@@ -0,0 +1,121 @@ ++/* vi:set et sw=2 sts=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e-s: ++ * ++ * Utilities for D-Bus services ++ * ++ * Copyright 2026 Collabora Ltd. ++ * SPDX-License-Identifier: LGPL-2.1-or-later ++ */ ++ ++#include "config.h" ++#include "flatpak-dbus-utils-private.h" ++ ++/* ++ * FlatpakUniqueFDList: ++ * ++ * Wrapper for a #GUnixFDList which checks that each fd is used at most once. ++ */ ++struct _FlatpakUniqueFDList ++{ ++ GUnixFDList *fd_list; ++ int *fds; ++ int n; ++}; ++ ++void ++flatpak_unique_fd_list_free (FlatpakUniqueFDList *self) ++{ ++ g_clear_object (&self->fd_list); ++ g_free (self->fds); ++ g_free (self); ++} ++ ++ ++/* ++ * flatpak_unique_fd_list_new: ++ * @fd_list: File descriptors obtained from a D-Bus call, which ++ * must not be modified as long as the returned list exists ++ * @error: Raises a %G_DBUS_ERROR on failure ++ * ++ * Create a new list of unique fds based on @fd_list. ++ * ++ * Returns: The new list, or %NULL with %G_DBUS_ERROR_INVALID_ARGS ++ * if the fds in @fd_list were somehow not all unique. ++ */ ++FlatpakUniqueFDList * ++flatpak_unique_fd_list_new (GUnixFDList *fd_list, ++ GError **error) ++{ ++ g_autoptr(FlatpakUniqueFDList) self = g_new0 (FlatpakUniqueFDList, 1); ++ const int *fds; ++ ++ self->fd_list = g_object_ref (fd_list); ++ fds = g_unix_fd_list_peek_fds (fd_list, &self->n); ++ g_assert (self->n >= 0); ++ self->fds = g_new0 (int, self->n); ++ ++ for (int i = 0; i < self->n; i++) ++ { ++ for (int j = i + 1; j < self->n; j++) ++ { ++ /* This probably can't actually happen: fd-passing the same fd ++ * more than once results in two distinct fds at the destination, ++ * as if via dup(). */ ++ if (fds[i] == fds[j]) ++ { ++ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, ++ "Duplicate file descriptor for handle %d and %d", ++ i, j); ++ return NULL; ++ } ++ } ++ ++ self->fds[i] = fds[i]; ++ } ++ ++ return g_steal_pointer (&self); ++} ++ ++/* ++ * flatpak_unique_fd_list_get: ++ * @self: (nullable): The list of fds, or %NULL if there were none ++ * @handle: An index into the fds, in practice the value of a #GVariant ++ * of type %G_VARIANT_TYPE_HANDLE, which might be out-of-range ++ * @error: Raises a %G_DBUS_ERROR on failure ++ * ++ * If @handle is in range for @self and has not yet been used, ++ * return the corresponding fd. ++ * Otherwise report an error. ++ * ++ * The returned fd remains owned by the #GUnixFDList owned by @self, ++ * and therefore must not be closed by the caller, ++ * except perhaps in a subprocess that will not finalize @self. ++ * ++ * Returns: The fd, or -1 with %G_DBUS_ERROR_INVALID_ARGS ++ */ ++int ++flatpak_unique_fd_list_get (FlatpakUniqueFDList *self, ++ int handle, ++ GError **error) ++{ ++ int ret; ++ ++ if (self == NULL || handle < 0 || handle >= self->n) ++ { ++ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, ++ "No file descriptor for handle %d", ++ handle); ++ return -1; ++ } ++ ++ if (self->fds[handle] < 0) ++ { ++ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, ++ "File descriptor for handle %d already used", ++ handle); ++ return -1; ++ } ++ ++ ret = self->fds[handle]; ++ self->fds[handle] = -1; ++ return ret; ++} +diff --git a/tests/meson.build b/tests/meson.build +index 6f8b8c3..d5d6950 100644 +--- a/tests/meson.build ++++ b/tests/meson.build +@@ -114,6 +114,11 @@ c_tests = [ + 'timeout' : 150, + }], + ['test-context', {}], ++ ['test-dbus-utils', { ++ 'extra_sources' : [ ++ '../common/flatpak-dbus-utils.c', ++ ], ++ }], + ['test-exports', {}], + ['test-instance', { + 'extra_dependencies' : [ +diff --git a/tests/test-dbus-utils.c b/tests/test-dbus-utils.c +new file mode 100644 +index 0000000..b24bf70 +--- /dev/null ++++ b/tests/test-dbus-utils.c +@@ -0,0 +1,125 @@ ++/* vi:set et sw=2 sts=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e-s: ++ * ++ * Copyright © 2020-2026 Collabora Ltd. ++ * SPDX-License-Identifier: LGPL-2.1-or-later ++ */ ++ ++#include "config.h" ++ ++#include ++ ++#include ++ ++#include "flatpak-dbus-utils-private.h" ++ ++#if GLIB_CHECK_VERSION (2, 78, 0) ++# define OPEN_PIPE_CLOEXEC O_CLOEXEC ++#else ++# define OPEN_PIPE_CLOEXEC FD_CLOEXEC ++#endif ++ ++static void ++test_unique_fd_list (void) ++{ ++ g_autoptr(GError) error = NULL; ++ g_autoptr(GUnixFDList) fd_list = NULL; ++ g_autoptr(FlatpakUniqueFDList) unique = NULL; ++ int fds[2]; ++ int fd; ++ ++ g_unix_open_pipe (fds, OPEN_PIPE_CLOEXEC, &error); ++ g_assert_no_error (error); ++ ++ fd_list = g_unix_fd_list_new_from_array (fds, G_N_ELEMENTS (fds)); ++ g_assert_nonnull (fd_list); ++ ++ unique = flatpak_unique_fd_list_new (fd_list, &error); ++ g_assert_no_error (error); ++ g_assert_nonnull (unique); ++ ++ fd = flatpak_unique_fd_list_get (unique, -1, &error); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_cmpint (fd, <, 0); ++ g_clear_error (&error); ++ ++ fd = flatpak_unique_fd_list_get (unique, 47, &error); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_cmpint (fd, <, 0); ++ g_clear_error (&error); ++ ++ fd = flatpak_unique_fd_list_get (unique, 2, &error); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_cmpint (fd, <, 0); ++ g_clear_error (&error); ++ ++ fd = flatpak_unique_fd_list_get (unique, 0, &error); ++ g_assert_no_error (error); ++ g_assert_cmpint (fd, ==, fds[0]); ++ g_clear_error (&error); ++ ++ fd = flatpak_unique_fd_list_get (unique, 0, &error); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_cmpint (fd, <, 0); ++ g_clear_error (&error); ++ ++ fd = flatpak_unique_fd_list_get (unique, 1, &error); ++ g_assert_no_error (error); ++ g_assert_cmpint (fd, ==, fds[1]); ++ g_clear_error (&error); ++} ++ ++static void ++test_unique_fd_list_dup (void) ++{ ++ GLogLevelFlags old_always_fatal; ++ GLogLevelFlags old_fatal_mask; ++ ++ if (!g_test_undefined ()) ++ { ++ g_test_skip ("Not exercising programming errors"); ++ return; ++ } ++ ++ old_always_fatal = g_log_set_always_fatal (G_LOG_FATAL_MASK); ++ old_fatal_mask = g_log_set_fatal_mask ("GLib", G_LOG_FATAL_MASK); ++ ++ { ++ g_autoptr(GError) error = NULL; ++ g_autoptr(GUnixFDList) fd_list = NULL; ++ g_autoptr(FlatpakUniqueFDList) unique = NULL; ++ int fds[3]; ++ ++ g_unix_open_pipe (&fds[0], OPEN_PIPE_CLOEXEC, &error); ++ g_assert_no_error (error); ++ ++ /* This is a programming error. GUnixFDList will close all fds passed ++ * to it, therefore it's always incorrect for the list to have duplicates. */ ++ fds[2] = fds[0]; ++ ++ fd_list = g_unix_fd_list_new_from_array (fds, G_N_ELEMENTS (fds)); ++ g_assert_nonnull (fd_list); ++ ++ unique = flatpak_unique_fd_list_new (fd_list, &error); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_test_message ("Non-unique GUnixFDList -> %s", error->message); ++ g_assert_null (unique); ++ ++ /* Autofreeing fd_list here will cause a critical, which we ignore */ ++ } ++ ++ g_log_set_always_fatal (old_always_fatal); ++ g_log_set_fatal_mask ("GLib", old_fatal_mask); ++} ++ ++int ++main (int argc, char *argv[]) ++{ ++ setlocale (LC_ALL, ""); ++ ++ g_test_init (&argc, &argv, NULL); ++ ++ g_test_add_func ("/dbus-utils/unique-fd-list", test_unique_fd_list); ++ g_test_add_func ("/dbus-utils/unique-fd-list-dup", test_unique_fd_list_dup); ++ ++ return g_test_run (); ++} diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Exit-the-child-process-if-mapping-fds-fails.patch flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Exit-the-child-process-if-mapping-fds-fails.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Exit-the-child-process-if-mapping-fds-fails.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Exit-the-child-process-if-mapping-fds-fails.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,44 @@ +From: "re:fi.64" +Date: Mon, 16 Nov 2026 19:47:24 -0600 +Subject: portal: Exit the child process if mapping fds fails + +Any failure here is likely tied to some form of portal bug (either +fd mismanagement or allowing nonsensical invocations), in which case +continuing to e.g. drop CLOEXEC is not safe, as that would now be +targeting a different fd than desired. For example, this can lead to +leaking unintended file descriptors into the child process, providing +access to unintended resources outside the sandbox. Thus it's safer to +just exit immediately. + +[smcv: Expand commit message] +Resolves: CVE-2026-133845 +Resolves: https://github.com/flatpak/flatpak/security/advisories/GHSA-5jrj-948r-2wx6 +Signed-off-by: Simon McVittie +--- + portal/flatpak-portal.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/portal/flatpak-portal.c b/portal/flatpak-portal.c +index e2f59b7..af5b69c 100644 +--- a/portal/flatpak-portal.c ++++ b/portal/flatpak-portal.c +@@ -510,7 +510,8 @@ child_setup_func (gpointer user_data) + { + if (fd_map[i].from != fd_map[i].to) + { +- dup2 (fd_map[i].from, fd_map[i].to); ++ if (dup2 (fd_map[i].from, fd_map[i].to) == -1) ++ _exit (255); + close (fd_map[i].from); + } + } +@@ -520,7 +521,8 @@ child_setup_func (gpointer user_data) + { + if (fd_map[i].to != fd_map[i].final) + { +- dup2 (fd_map[i].to, fd_map[i].final); ++ if (dup2 (fd_map[i].to, fd_map[i].final) == -1) ++ _exit (255); + close (fd_map[i].to); + } + diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Rename-app_fd-usr_fd-variables-to-indicate-that-th.patch flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Rename-app_fd-usr_fd-variables-to-indicate-that-th.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Rename-app_fd-usr_fd-variables-to-indicate-that-th.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Rename-app_fd-usr_fd-variables-to-indicate-that-th.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,78 @@ +From: Simon McVittie +Date: Wed, 18 Nov 2026 16:21:13 +0000 +Subject: portal: Rename app_fd, + usr_fd variables to indicate that they're variants + +Naming them `*_fd` is already quite confusing when they are not file +descriptors, and will become more so when we want to introduce a +variable whose value is the actual file descriptor that these HANDLE +variants represent. + +Helps: CVE-2026-133845 +Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-5jrj-948r-2wx6 +Signed-off-by: Simon McVittie +--- + portal/flatpak-portal.c | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +diff --git a/portal/flatpak-portal.c b/portal/flatpak-portal.c +index af5b69c..bb9a9b5 100644 +--- a/portal/flatpak-portal.c ++++ b/portal/flatpak-portal.c +@@ -674,8 +674,8 @@ handle_spawn (PortalFlatpak *object, + g_autoptr(FlatpakInstance) instance = NULL; + g_autoptr(GVariant) sandbox_expose_fd = NULL; + g_autoptr(GVariant) sandbox_expose_fd_ro = NULL; +- g_autoptr(GVariant) app_fd = NULL; +- g_autoptr(GVariant) usr_fd = NULL; ++ g_autoptr(GVariant) app_fd_variant = NULL; ++ g_autoptr(GVariant) usr_fd_variant = NULL; + g_autoptr(GOutputStream) instance_id_out_stream = NULL; + guint sandbox_flags = 0; + gboolean sandboxed; +@@ -795,8 +795,8 @@ handle_spawn (PortalFlatpak *object, + sandbox_expose_fd = g_variant_lookup_value (arg_options, "sandbox-expose-fd", G_VARIANT_TYPE ("ah")); + sandbox_expose_fd_ro = g_variant_lookup_value (arg_options, "sandbox-expose-fd-ro", G_VARIANT_TYPE ("ah")); + g_variant_lookup (arg_options, "unset-env", "^as", &unset_env); +- app_fd = g_variant_lookup_value (arg_options, "app-fd", G_VARIANT_TYPE_HANDLE); +- usr_fd = g_variant_lookup_value (arg_options, "usr-fd", G_VARIANT_TYPE_HANDLE); ++ app_fd_variant = g_variant_lookup_value (arg_options, "app-fd", G_VARIANT_TYPE_HANDLE); ++ usr_fd_variant = g_variant_lookup_value (arg_options, "usr-fd", G_VARIANT_TYPE_HANDLE); + + if ((sandbox_flags & ~FLATPAK_SPAWN_SANDBOX_FLAGS_ALL) != 0) + { +@@ -1346,7 +1346,7 @@ handle_spawn (PortalFlatpak *object, + + empty_app = (arg_flags & FLATPAK_SPAWN_FLAGS_EMPTY_APP) != 0; + +- if (empty_app && app_fd != NULL) ++ if (empty_app && app_fd_variant != NULL) + { + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, + G_DBUS_ERROR_INVALID_ARGS, +@@ -1354,10 +1354,10 @@ handle_spawn (PortalFlatpak *object, + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + +- if (app_fd != NULL) ++ if (app_fd_variant != NULL) + { + int remapped_fd; +- gint32 handle = g_variant_get_handle (app_fd); ++ gint32 handle = g_variant_get_handle (app_fd_variant); + + if (handle >= fds_len || handle < 0) + { +@@ -1380,10 +1380,10 @@ handle_spawn (PortalFlatpak *object, + g_ptr_array_add (flatpak_argv, g_strdup ("--app-path=")); + } + +- if (usr_fd != NULL) ++ if (usr_fd_variant != NULL) + { + int remapped_fd; +- gint32 handle = g_variant_get_handle (usr_fd); ++ gint32 handle = g_variant_get_handle (usr_fd_variant); + + if (handle >= fds_len || handle < 0) + { diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Use-FlatpakUniqueFDList-to-prevent-multiple-uses-o.patch flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Use-FlatpakUniqueFDList-to-prevent-multiple-uses-o.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Use-FlatpakUniqueFDList-to-prevent-multiple-uses-o.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133845/portal-Use-FlatpakUniqueFDList-to-prevent-multiple-uses-o.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,241 @@ +From: Simon McVittie +Date: Tue, 17 Nov 2026 21:47:25 +0000 +Subject: portal: Use FlatpakUniqueFDList to prevent multiple uses of one fd + +Previously, if the Spawn() caller passed in a `fds` argument like + + { int32 3: handle 0, int32 4: handle 0 } + +then this would result in the 0'th fd in the `fd_list` (let's say 23) +appearing in the array of `FdMapEntry` more than once. In our +`child_setup`, the first use would use `dup2` to make fd 3 a copy of +fd 23, and then close fd 23. The second use would try to use `dup2` +again to make fd 4 a copy of fd 23, but fail because fd 23 is closed. + +Until recently, this failure was ignored and would result in fd 4 +from the flatpak-portal being leaked into the child process, +giving it unintended access to resources from outside its sandbox, +such as flatpak-portal's own D-Bus connection. Guard against this by +only allowing each fd to be referred to by at most one handle. + +Similarly, harden against misuse of the `sandbox-expose-fd`, +`sandbox-expose-fd-ro`, `app-fd` and `usr-fd` options by preventing +them from referring to a fd that was already claimed for some other +purpose. + +Resolves: CVE-2026-133845 +Resolves: https://github.com/flatpak/flatpak/security/advisories/GHSA-5jrj-948r-2wx6 +Signed-off-by: Simon McVittie +--- + portal/flatpak-portal.c | 86 ++++++++++++++++++++++++------------------------- + portal/meson.build | 1 + + 2 files changed, 44 insertions(+), 43 deletions(-) + +diff --git a/portal/flatpak-portal.c b/portal/flatpak-portal.c +index bb9a9b5..aa1d86f 100644 +--- a/portal/flatpak-portal.c ++++ b/portal/flatpak-portal.c +@@ -40,6 +40,7 @@ + #include + #include "flatpak-portal-dbus.h" + #include "flatpak-portal.h" ++#include "flatpak-dbus-utils-private.h" + #include "flatpak-dir-private.h" + #include "flatpak-utils-private.h" + #include "flatpak-transaction.h" +@@ -647,8 +648,7 @@ handle_spawn (PortalFlatpak *object, + PidData *pid_data; + InstanceIdReadData *instance_id_read_data = NULL; + gsize i, j, n_fds, n_envs; +- const gint *fds = NULL; +- gint fds_len = 0; ++ g_autoptr(FlatpakUniqueFDList) unique_fds = NULL; + g_autoptr(GArray) fd_map = NULL; + g_auto(GStrv) env = NULL; + gint32 max_fd; +@@ -697,7 +697,15 @@ handle_spawn (PortalFlatpak *object, + child_setup_data.env_fd = -1; + + if (fd_list != NULL) +- fds = g_unix_fd_list_peek_fds (fd_list, &fds_len); ++ { ++ unique_fds = flatpak_unique_fd_list_new (fd_list, &error); ++ ++ if (unique_fds == NULL) ++ { ++ g_dbus_method_invocation_return_gerror (invocation, error); ++ return G_DBUS_METHOD_INVOCATION_HANDLED; ++ } ++ } + + app_info = g_object_get_data (G_OBJECT (invocation), "app-info"); + g_assert (app_info != NULL); +@@ -838,7 +846,7 @@ handle_spawn (PortalFlatpak *object, + g_info ("Running spawn command %s", arg_argv[0]); + + n_fds = 0; +- if (fds != NULL) ++ if (unique_fds != NULL) + n_fds = g_variant_n_children (arg_fds); + + fd_map = g_array_sized_new (FALSE, FALSE, sizeof (FdMapEntry), n_fds); +@@ -851,18 +859,14 @@ handle_spawn (PortalFlatpak *object, + int handle_fd; + + g_variant_get_child (arg_fds, i, "{uh}", &dest_fd, &handle); ++ handle_fd = flatpak_unique_fd_list_get (unique_fds, handle, &error); + +- if (handle >= fds_len || handle < 0) ++ if (handle_fd < 0) + { +- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, +- G_DBUS_ERROR_INVALID_ARGS, +- "No file descriptor for handle %d", +- handle); ++ g_dbus_method_invocation_return_gerror (invocation, error); + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + +- handle_fd = fds[handle]; +- + fd_map_entry.to = dest_fd; + fd_map_entry.from = handle_fd; + fd_map_entry.final = fd_map_entry.to; +@@ -1267,26 +1271,26 @@ handle_spawn (PortalFlatpak *object, + for (i = 0; i < len; i++) + { + gint32 handle; ++ int expose_fd; + + g_variant_get_child (sandbox_expose_fd, i, "h", &handle); +- if (handle >= fds_len || handle < 0) ++ expose_fd = flatpak_unique_fd_list_get (unique_fds, handle, &error); ++ ++ if (expose_fd < 0) + { + g_debug ("Invalid sandbox-expose-fd handle %d", handle); +- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, +- G_DBUS_ERROR_INVALID_ARGS, +- "No file descriptor for handle %d", +- handle); ++ g_dbus_method_invocation_return_gerror (invocation, error); + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + +- if (validate_opath_fd (fds[handle], TRUE, &error)) ++ if (validate_opath_fd (expose_fd, TRUE, &error)) + { +- g_array_append_val (expose_fds, fds[handle]); ++ g_array_append_val (expose_fds, expose_fd); + } + else + { + g_info ("unable to validate sandbox-expose-fd %d, ignoring: %s", +- fds[handle], error->message); ++ expose_fd, error->message); + g_clear_error (&error); + } + } +@@ -1299,26 +1303,26 @@ handle_spawn (PortalFlatpak *object, + for (i = 0; i < len; i++) + { + gint32 handle; ++ int expose_fd; + + g_variant_get_child (sandbox_expose_fd_ro, i, "h", &handle); +- if (handle >= fds_len || handle < 0) ++ expose_fd = flatpak_unique_fd_list_get (unique_fds, handle, &error); ++ ++ if (expose_fd < 0) + { + g_debug ("Invalid sandbox-expose-ro-fd handle %d", handle); +- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, +- G_DBUS_ERROR_INVALID_ARGS, +- "No file descriptor for handle %d", +- handle); ++ g_dbus_method_invocation_return_gerror (invocation, error); + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + +- if (validate_opath_fd (fds[handle], FALSE, &error)) ++ if (validate_opath_fd (expose_fd, FALSE, &error)) + { +- g_array_append_val (expose_fds_ro, fds[handle]); ++ g_array_append_val (expose_fds_ro, expose_fd); + } + else + { + g_info ("unable to validate sandbox-expose-ro-fd %d, ignoring: %s", +- fds[handle], error->message); ++ expose_fd, error->message); + g_clear_error (&error); + } + } +@@ -1356,21 +1360,19 @@ handle_spawn (PortalFlatpak *object, + + if (app_fd_variant != NULL) + { ++ int app_fd; + int remapped_fd; + gint32 handle = g_variant_get_handle (app_fd_variant); + +- if (handle >= fds_len || handle < 0) ++ app_fd = flatpak_unique_fd_list_get (unique_fds, handle, &error); ++ ++ if (app_fd < 0) + { +- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, +- G_DBUS_ERROR_INVALID_ARGS, +- "No file descriptor for handle %d", +- handle); ++ g_dbus_method_invocation_return_gerror (invocation, error); + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + +- g_assert (fds != NULL); /* otherwise fds_len would be 0 */ +- +- remapped_fd = fd_map_remap_fd (fd_map, &max_fd, fds[handle]); ++ remapped_fd = fd_map_remap_fd (fd_map, &max_fd, app_fd); + + g_ptr_array_add (flatpak_argv, g_strdup_printf ("--app-fd=%d", + remapped_fd)); +@@ -1382,21 +1384,19 @@ handle_spawn (PortalFlatpak *object, + + if (usr_fd_variant != NULL) + { ++ int usr_fd; + int remapped_fd; + gint32 handle = g_variant_get_handle (usr_fd_variant); + +- if (handle >= fds_len || handle < 0) ++ usr_fd = flatpak_unique_fd_list_get (unique_fds, handle, &error); ++ ++ if (usr_fd < 0) + { +- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, +- G_DBUS_ERROR_INVALID_ARGS, +- "No file descriptor for handle %d", +- handle); ++ g_dbus_method_invocation_return_gerror (invocation, error); + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + +- g_assert (fds != NULL); /* otherwise fds_len would be 0 */ +- +- remapped_fd = fd_map_remap_fd (fd_map, &max_fd, fds[handle]); ++ remapped_fd = fd_map_remap_fd (fd_map, &max_fd, usr_fd); + + g_ptr_array_add (flatpak_argv, g_strdup_printf ("--usr-fd=%d", + remapped_fd)); +diff --git a/portal/meson.build b/portal/meson.build +index a3ebf71..8973643 100644 +--- a/portal/meson.build ++++ b/portal/meson.build +@@ -40,6 +40,7 @@ executable( + 'flatpak-portal.c', + 'flatpak-portal-app-info.c', + 'portal-impl.c', ++ '../common/flatpak-dbus-utils.c', + '../common/flatpak-portal-error.c', + ] + permission_gdbus + portal_gdbus, + ) diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133845/session-helper-Use-FlatpakUniqueFDList-here-too.patch flatpak-1.16.6/debian/patches/CVE-2026-133845/session-helper-Use-FlatpakUniqueFDList-here-too.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133845/session-helper-Use-FlatpakUniqueFDList-here-too.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133845/session-helper-Use-FlatpakUniqueFDList-here-too.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,106 @@ +From: Simon McVittie +Date: Wed, 18 Nov 2026 16:13:05 +0000 +Subject: session-helper: Use FlatpakUniqueFDList here, too + +This is not fixing a security vulnerability, because anyone who can talk +to the Development interface already has arbitrary code execution, +but let's keep this consistent with flatpak-portal to avoid accidents. + +Signed-off-by: Simon McVittie +--- + session-helper/flatpak-session-helper.c | 30 ++++++++++++++++++++++++------ + session-helper/meson.build | 5 ++++- + 2 files changed, 28 insertions(+), 7 deletions(-) + +diff --git a/session-helper/flatpak-session-helper.c b/session-helper/flatpak-session-helper.c +index 7cbb505..4331821 100644 +--- a/session-helper/flatpak-session-helper.c ++++ b/session-helper/flatpak-session-helper.c +@@ -29,6 +29,7 @@ + #include + #include + #include "flatpak-dbus-generated.h" ++#include "flatpak-dbus-utils-private.h" + #include "flatpak-session-helper.h" + #include "flatpak-utils-base-private.h" + +@@ -213,7 +214,7 @@ handle_host_command (FlatpakDevelopment *object, + GPid pid; + PidData *pid_data; + gsize i, j, n_fds, n_envs; +- const gint *fds; ++ g_autoptr(FlatpakUniqueFDList) unique_fds = NULL; + g_autofree FdMapEntry *fd_map = NULL; + g_auto(GStrv) env = NULL; + gint32 max_fd; +@@ -243,12 +244,19 @@ handle_host_command (FlatpakDevelopment *object, + g_info ("Running host command %s", arg_argv[0]); + + n_fds = 0; +- fds = NULL; ++ + if (fd_list != NULL) + { + n_fds = g_variant_n_children (arg_fds); +- fds = g_unix_fd_list_peek_fds (fd_list, NULL); ++ unique_fds = flatpak_unique_fd_list_new (fd_list, &error); ++ ++ if (unique_fds == NULL) ++ { ++ g_dbus_method_invocation_return_gerror (invocation, error); ++ return G_DBUS_METHOD_INVOCATION_HANDLED; ++ } + } ++ + fd_map = g_new0 (FdMapEntry, n_fds); + + child_setup_data.fd_map = fd_map; +@@ -258,19 +266,29 @@ handle_host_command (FlatpakDevelopment *object, + for (i = 0; i < n_fds; i++) + { + gint32 handle, fd; ++ int from_fd; + g_variant_get_child (arg_fds, i, "{uh}", &fd, &handle); ++ ++ from_fd = flatpak_unique_fd_list_get (unique_fds, handle, &error); ++ ++ if (from_fd < 0) ++ { ++ g_dbus_method_invocation_return_gerror (invocation, error); ++ return G_DBUS_METHOD_INVOCATION_HANDLED; ++ } ++ + fd_map[i].to = fd; +- fd_map[i].from = fds[i]; ++ fd_map[i].from = from_fd; + fd_map[i].final = fd_map[i].to; + + /* If stdin/out/err is a tty we try to set it as the controlling + tty for the app, this way we can use this to run in a terminal. */ + if ((fd == 0 || fd == 1 || fd == 2) && + !child_setup_data.set_tty && +- isatty (fds[i])) ++ isatty (from_fd)) + { + child_setup_data.set_tty = TRUE; +- child_setup_data.tty = fds[i]; ++ child_setup_data.tty = from_fd; + } + + max_fd = MAX (max_fd, fd_map[i].to); +diff --git a/session-helper/meson.build b/session-helper/meson.build +index 14fc47b..a7ca6e5 100644 +--- a/session-helper/meson.build ++++ b/session-helper/meson.build +@@ -11,7 +11,10 @@ executable( + ], + install : true, + install_dir : get_option('libexecdir'), +- sources : ['flatpak-session-helper.c'], ++ sources : [ ++ 'flatpak-session-helper.c', ++ '../common/flatpak-dbus-utils.c', ++ ], + ) + + configure_file( diff -Nru flatpak-1.16.6/debian/patches/CVE-2026-133845/tests-Assert-we-get-an-error-when-mapping-1-handle-to-the.patch flatpak-1.16.6/debian/patches/CVE-2026-133845/tests-Assert-we-get-an-error-when-mapping-1-handle-to-the.patch --- flatpak-1.16.6/debian/patches/CVE-2026-133845/tests-Assert-we-get-an-error-when-mapping-1-handle-to-the.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/CVE-2026-133845/tests-Assert-we-get-an-error-when-mapping-1-handle-to-the.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,136 @@ +From: "re:fi.64" +Date: Sun, 15 Nov 2026 18:57:39 -0600 +Subject: tests: Assert we get an error when mapping >1 handle to the same fd + +[smcv: Add test coverage for fds other than the fd map] +Helps: CVE-2026-133845 +Helps: https://github.com/flatpak/flatpak/security/advisories/GHSA-5jrj-948r-2wx6 +Co-authored-by: Simon McVittie +Signed-off-by: Simon McVittie +[smcv: backport to 1.18.x which didn't have test_spawn_env()] +--- + tests/test-portal.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 104 insertions(+) + +diff --git a/tests/test-portal.c b/tests/test-portal.c +index 0dfb752..25bfe10 100644 +--- a/tests/test-portal.c ++++ b/tests/test-portal.c +@@ -422,6 +422,109 @@ test_fd_passing (Fixture *f, + } + } + ++static void ++test_fd_handle_duplicate (Fixture *f, ++ gconstpointer context G_GNUC_UNUSED) ++{ ++ g_autoptr(GError) error = NULL; ++ g_autoptr(GUnixFDList) fds_in = g_unix_fd_list_new (); ++ g_autoptr(GUnixFDList) fds_out = NULL; ++ g_auto(GVariantBuilder) fd_map_builder = {}; ++ g_auto(GVariantBuilder) options_builder = {}; ++ guint pid; ++ gboolean ok; ++ const char * const argv[] = { "hello", NULL }; ++ glnx_autofd int null_fd = -1; ++ int handle; ++ ++ fixture_start_portal (f); ++ ++ null_fd = open ("/dev/null", O_RDONLY); ++ g_assert_no_errno (null_fd); ++ ++ handle = g_unix_fd_list_append (fds_in, null_fd, &error); ++ g_assert_no_error (error); ++ g_assert_cmpint (handle, >=, 0); ++ ++ g_variant_builder_init (&fd_map_builder, G_VARIANT_TYPE ("a{uh}")); ++ g_variant_builder_add (&fd_map_builder, "{uh}", 1, handle); ++ g_variant_builder_add (&fd_map_builder, "{uh}", 2, handle); ++ ok = portal_flatpak_call_spawn_sync (f->proxy, ++ "/", /* cwd */ ++ argv, /* argv */ ++ g_variant_builder_end (&fd_map_builder), ++ g_variant_new ("a{ss}", NULL), ++ FLATPAK_SPAWN_FLAGS_NONE, ++ g_variant_new ("a{sv}", NULL), ++ fds_in, ++ &pid, ++ &fds_out, ++ NULL, ++ &error); ++ g_test_message ("duplicates in fd map -> %s", ++ error ? error->message : "(no error!)"); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_false (ok); ++ g_assert_nonnull (strstr (error->message, "already used")); ++ g_assert_null (fds_out); ++ g_clear_error (&error); ++ ++ g_variant_builder_init (&options_builder, G_VARIANT_TYPE ("a{sv}")); ++ g_variant_builder_add (&options_builder, "{sv}", ++ "usr-fd", g_variant_new_handle (handle)); ++ g_variant_builder_add (&options_builder, "{sv}", ++ "sandbox-expose-fd", ++ g_variant_new_parsed ("[%h]", handle)); ++ ok = portal_flatpak_call_spawn_sync (f->proxy, ++ "/", /* cwd */ ++ argv, /* argv */ ++ g_variant_new ("a{uh}", NULL), ++ g_variant_new ("a{ss}", NULL), ++ FLATPAK_SPAWN_FLAGS_NONE, ++ g_variant_builder_end (&options_builder), ++ fds_in, ++ &pid, ++ &fds_out, ++ NULL, ++ &error); ++ g_test_message ("usr-fd duplicates sandbox-expose-fd -> %s", ++ error ? error->message : "(no error!)"); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_false (ok); ++ g_assert_nonnull (strstr (error->message, "already used")); ++ g_assert_null (fds_out); ++ g_clear_error (&error); ++ ++ g_variant_builder_init (&options_builder, G_VARIANT_TYPE ("a{sv}")); ++ g_variant_builder_add (&options_builder, "{sv}", ++ "app-fd", g_variant_new_handle (handle)); ++ g_variant_builder_add (&options_builder, "{sv}", ++ "sandbox-expose-fd-ro", ++ g_variant_new_parsed ("[%h]", handle)); ++ ok = portal_flatpak_call_spawn_sync (f->proxy, ++ "/", /* cwd */ ++ argv, /* argv */ ++ g_variant_new ("a{uh}", NULL), ++ g_variant_new ("a{ss}", NULL), ++ FLATPAK_SPAWN_FLAGS_NONE, ++ g_variant_builder_end (&options_builder), ++ fds_in, ++ &pid, ++ &fds_out, ++ NULL, ++ &error); ++ g_test_message ("app-fd duplicates sandbox-expose-fd-ro -> %s", ++ error ? error->message : "(no error!)"); ++ g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); ++ g_assert_false (ok); ++ g_assert_nonnull (strstr (error->message, "already used")); ++ g_assert_null (fds_out); ++ g_clear_error (&error); ++ ++ g_subprocess_send_signal (f->portal, SIGTERM); ++ g_subprocess_wait (f->portal, NULL, NULL); ++} ++ + static void + test_replace (Fixture *f, + gconstpointer context G_GNUC_UNUSED) +@@ -478,6 +581,7 @@ main (int argc, + g_test_add ("/help", Fixture, NULL, setup, test_help, teardown); + g_test_add ("/basic", Fixture, NULL, setup, test_basic, teardown); + g_test_add ("/fd-passing", Fixture, NULL, setup, test_fd_passing, teardown); ++ g_test_add ("/fd-handle-duplicate", Fixture, NULL, setup, test_fd_handle_duplicate, teardown); + g_test_add ("/replace", Fixture, NULL, setup, test_replace, teardown); + + return g_test_run (); diff -Nru flatpak-1.16.6/debian/patches/series flatpak-1.16.6/debian/patches/series --- flatpak-1.16.6/debian/patches/series 2026-09-28 13:13:01.000000000 +0000 +++ flatpak-1.16.6/debian/patches/series 2026-11-24 14:26:21.000000000 +0000 @@ -49,3 +49,14 @@ CVE-2026-97023-97024/dir-Use-deploy-helpers-in-apply_extra_data-and-flatpak_di.patch CVE-2026-97025/oci-Stop-persisting-bearer-token-to-child-repo-on-disk.patch CVE-2026-97026/common-Restrict-tmpdir-permissions-from-0777-to-0755.patch +tests/tests-add-test-run-custom.sh-to-test-matrix-source.patch +CVE-2026-133842/utils-Fail-closed-if-canonicalizing-permissions-can-t-ope.patch +CVE-2026-133842/utils-Fail-closed-when-canonicalizing-permissions-if-read.patch +CVE-2026-133842/tests-Test-deeply-nested-files-in-apply_extra-output.patch +CVE-2026-133842/tests-Assert-that-extra-data-can-t-normally-contain-setui.patch +CVE-2026-133845/portal-Exit-the-child-process-if-mapping-fds-fails.patch +CVE-2026-133845/portal-Rename-app_fd-usr_fd-variables-to-indicate-that-th.patch +CVE-2026-133845/common-Add-an-object-tracking-unique-fds-in-a-D-Bus-messa.patch +CVE-2026-133845/portal-Use-FlatpakUniqueFDList-to-prevent-multiple-uses-o.patch +CVE-2026-133845/tests-Assert-we-get-an-error-when-mapping-1-handle-to-the.patch +CVE-2026-133845/session-helper-Use-FlatpakUniqueFDList-here-too.patch diff -Nru flatpak-1.16.6/debian/patches/tests/tests-add-test-run-custom.sh-to-test-matrix-source.patch flatpak-1.16.6/debian/patches/tests/tests-add-test-run-custom.sh-to-test-matrix-source.patch --- flatpak-1.16.6/debian/patches/tests/tests-add-test-run-custom.sh-to-test-matrix-source.patch 1970-01-01 00:00:00.000000000 +0000 +++ flatpak-1.16.6/debian/patches/tests/tests-add-test-run-custom.sh-to-test-matrix-source.patch 2026-11-24 14:26:21.000000000 +0000 @@ -0,0 +1,25 @@ +From: razzeee +Date: Mon, 13 Apr 2026 17:19:48 +0200 +Subject: tests: add test-run-custom.sh to test matrix source + +test-run-custom.sh was only manually appended to test-matrix/meson.build +and would be lost on regeneration. Add it to update-test-matrix so it is +properly managed. + +(cherry picked from commit 655ddb42ec5124dfcf6e087005dc17ccc0d071c0) +--- + tests/update-test-matrix | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/tests/update-test-matrix b/tests/update-test-matrix +index 2e26a6f..4c07fd0 100755 +--- a/tests/update-test-matrix ++++ b/tests/update-test-matrix +@@ -35,6 +35,7 @@ TEST_MATRIX_SOURCE=( + 'tests/test-seccomp.sh' \ + 'tests/test-repair.sh' \ + 'tests/test-extra-data.sh{user+system}' \ ++ 'tests/test-run-custom.sh{user+system}' \ + ) + + "${tests_srcdir}/expand-test-matrix.sh" --meson "${TEST_MATRIX_SOURCE[*]}" > "${tests_srcdir}/test-matrix/meson.build"