Don't break if exporting paths or symlinks to files in the runtime

For instance like in https://github.com/flatpak/flatpak/issues/494
if there is a /linuxrc -> /bin/busybox symlink, and /bin/busybox
is not in the runtime then we will fail creating it as a mountpoint
for the bind mount.

Fixes https://github.com/flatpak/flatpak/issues/494
This commit is contained in:
Alexander Larsson committed 2017-01-19 10:43:17 +01:00
1 parent 605c7ee87b
commit 592bea2b2e
3 files changed
+46 -13

No files matched your search

+38 -13
View File
@@ -93,6 +93,12 @@ const char *dont_mount_in_root[] = {
"tmp", "etc", "app", "run", "proc", "sys", "dev", "var", NULL
};
/* We don't want to export paths pointing into these, because they are readonly
(so we can't create mountpoints there) and don't match whats on the host anyway */
const char *dont_export_in[] = {
"/lib/", "/lib32/", "/lib64/", "/bin/", "/sbin/", "/usr/", "/etc/", "/app/", NULL
};
typedef enum {
FLATPAK_CONTEXT_DEVICE_DRI = 1 << 0,
FLATPAK_CONTEXT_DEVICE_ALL = 1 << 1,
@@ -2286,15 +2292,35 @@ add_hide_path (GHashTable *hash_table,
GINT_TO_POINTER ( MAX (old_mode, FAKE_MODE_HIDDEN)));
}
static void
static gboolean
add_expose_path (GHashTable *hash_table,
FlatpakFilesystemMode mode,
const char *path)
{
g_autofree char *canonical = flatpak_canonicalize_filename (path);
struct stat st;
int i;
if (!g_path_is_absolute (path))
{
g_warning ("Exposing relative path %s", path);
return FALSE;
}
for (i = 0; dont_export_in[i] != NULL; i++)
{
/* Don't expose files in non-mounted dirs like /app or /usr, as
they are not the same as on the host, and we generally can't
create the parents for them anyway */
if (g_str_has_prefix (canonical, dont_export_in[i]))
{
g_debug ("skipping export for path %s", canonical);
return FALSE;
}
}
if (lstat (path, &st) != 0)
return;
return FALSE;
if (S_ISDIR (st.st_mode) ||
S_ISREG (st.st_mode) ||
@@ -2308,22 +2334,21 @@ add_expose_path (GHashTable *hash_table,
if (S_ISLNK (st.st_mode))
{
g_autofree char *resolved = flatpak_resolve_link (path, NULL);
/* Don't keep symlinks into /app or /usr, as they are not the
same as on the host, and we generally can't create the parents
for them anyway */
if (resolved &&
!g_str_has_prefix (resolved, "/app/") &&
!g_str_has_prefix (resolved, "/usr/"))
{
add_expose_path (hash_table, mode, resolved);
mode = FAKE_MODE_SYMLINK;
}
if (resolved && add_expose_path (hash_table, mode, resolved))
mode = FAKE_MODE_SYMLINK;
else
mode = 0;
}
if (mode > 0)
g_hash_table_insert (hash_table, g_strdup (path), GINT_TO_POINTER ( MAX (old_mode, mode)));
{
g_hash_table_insert (hash_table, g_strdup (path), GINT_TO_POINTER ( MAX (old_mode, mode)));
return TRUE;
}
}
return FALSE;
}
void
+7
View File
@@ -2185,6 +2185,13 @@ flatpak_resolve_link (const char *path,
return g_build_path (dirname, link, NULL);
}
char *
flatpak_canonicalize_filename (const char *path)
{
g_autoptr(GFile) file = g_file_new_for_path (path);
return g_file_get_path (file);
}
gboolean flatpak_file_rename (GFile *from,
GFile *to,
GCancellable *cancellable,
+1
View File
@@ -383,6 +383,7 @@ char * flatpak_readlink (const char *path,
GError **error);
char * flatpak_resolve_link (const char *path,
GError **error);
char * flatpak_canonicalize_filename (const char *path);
gboolean flatpak_file_rename (GFile *from,
GFile *to,