Blame SOURCES/flatpak-1.0.2-CVE-2019-5736.patch

66b0f8
From 86d9d711bdaada5677166a99b96b769df2c5e7b6 Mon Sep 17 00:00:00 2001
66b0f8
From: Alexander Larsson <alexl@redhat.com>
66b0f8
Date: Sun, 10 Feb 2019 18:23:44 +0100
66b0f8
Subject: [PATCH] Don't expose /proc when running apply_extra
66b0f8
66b0f8
As shown by CVE-2019-5736, it is sometimes possible for the sandbox
66b0f8
app to access outside files using /proc/self/exe. This is not
66b0f8
typically an issue for flatpak as the sandbox runs as the user which
66b0f8
has no permissions to e.g. modify the host files.
66b0f8
66b0f8
However, when installing apps using extra-data into the system repo
66b0f8
we *do* actually run a sandbox as root. So, in this case we disable mounting
66b0f8
/proc in the sandbox, which will neuter attacks like this.
66b0f8
---
66b0f8
 common/flatpak-common-types-private.h | 1 +
66b0f8
 common/flatpak-dir.c                  | 2 +-
66b0f8
 common/flatpak-run.c                  | 6 +++++-
66b0f8
 3 files changed, 7 insertions(+), 2 deletions(-)
66b0f8
66b0f8
diff --git a/common/flatpak-common-types-private.h b/common/flatpak-common-types-private.h
66b0f8
index 8c40d2e8..1e94bd1c 100644
66b0f8
--- a/common/flatpak-common-types-private.h
66b0f8
+++ b/common/flatpak-common-types-private.h
66b0f8
@@ -44,6 +44,7 @@ typedef enum {
66b0f8
   FLATPAK_RUN_FLAG_SANDBOX            = (1 << 14),
66b0f8
   FLATPAK_RUN_FLAG_NO_DOCUMENTS_PORTAL = (1 << 15),
66b0f8
   FLATPAK_RUN_FLAG_BLUETOOTH          = (1 << 16),
66b0f8
+  FLATPAK_RUN_FLAG_NO_PROC            = (1 << 19),
66b0f8
 } FlatpakRunFlags;
66b0f8
 
66b0f8
 typedef struct FlatpakDir          FlatpakDir;
66b0f8
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
66b0f8
index eb69225d..be370d49 100644
66b0f8
--- a/common/flatpak-dir.c
66b0f8
+++ b/common/flatpak-dir.c
66b0f8
@@ -6509,7 +6509,7 @@ apply_extra_data (FlatpakDir   *self,
66b0f8
                           NULL);
66b0f8
 
66b0f8
   if (!flatpak_run_setup_base_argv (bwrap, runtime_files, NULL, runtime_ref_parts[2],
66b0f8
-                                    FLATPAK_RUN_FLAG_NO_SESSION_HELPER,
66b0f8
+                                    FLATPAK_RUN_FLAG_NO_SESSION_HELPER | FLATPAK_RUN_FLAG_NO_PROC,
66b0f8
                                     error))
66b0f8
     return FALSE;
66b0f8
 
66b0f8
diff --git a/common/flatpak-run.c b/common/flatpak-run.c
66b0f8
index 6ab466af..b4f2c475 100644
66b0f8
--- a/common/flatpak-run.c
66b0f8
+++ b/common/flatpak-run.c
66b0f8
@@ -2347,9 +2347,13 @@ flatpak_run_setup_base_argv (FlatpakBwrap   *bwrap,
66b0f8
     "# Disable user pkcs11 config, because the host modules don't work in the runtime\n"
66b0f8
     "user-config: none\n";
66b0f8
 
66b0f8
+  if ((flags & FLATPAK_RUN_FLAG_NO_PROC) == 0)
66b0f8
+    flatpak_bwrap_add_args (bwrap,
66b0f8
+                            "--proc", "/proc",
66b0f8
+                            NULL);
66b0f8
+
66b0f8
   flatpak_bwrap_add_args (bwrap,
66b0f8
                           "--unshare-pid",
66b0f8
-                          "--proc", "/proc",
66b0f8
                           "--dir", "/tmp",
66b0f8
                           "--dir", "/var/tmp",
66b0f8
                           "--dir", "/run/host",
66b0f8
-- 
66b0f8
2.20.1
66b0f8