mirror of
https://github.com/flatpak/flatpak.git
synced 2026-09-12 22:22:09 -04:00
exports: Add recursion depth limit to flatpak_exports_path_get_mode
A symlink loop on the host filesystem would cause infinite recursion and a stack overflow. Limit to 40 levels, matching the kernel's ELOOP limit and the existing check in _exports_path_expose.
This commit is contained in:
1 parent
e7bdeed3f6
commit
6950a22bf4
1 file changed
+16
-5
@@ -667,10 +667,10 @@ flatpak_exports_append_bwrap_args (FlatpakExports *exports,
|
||||
flatpak_bwrap_add_args (bwrap, "--ro-bind", "/usr/lib/os-release", "/run/host/os-release", NULL);
|
||||
}
|
||||
|
||||
/* Returns FLATPAK_FILESYSTEM_MODE_NONE if not visible */
|
||||
FlatpakFilesystemMode
|
||||
flatpak_exports_path_get_mode (FlatpakExports *exports,
|
||||
const char *path)
|
||||
static FlatpakFilesystemMode
|
||||
flatpak_exports_path_get_mode_full (FlatpakExports *exports,
|
||||
const char *path,
|
||||
int level)
|
||||
{
|
||||
guint n_keys;
|
||||
g_autofree const char **keys = (const char **) g_hash_table_get_keys_as_array (exports->hash, &n_keys);
|
||||
@@ -681,6 +681,9 @@ flatpak_exports_path_get_mode (FlatpakExports *exports,
|
||||
g_autoptr(GString) path_builder = g_string_new ("");
|
||||
struct stat st;
|
||||
|
||||
if (level > 40) /* 40 is the current kernel ELOOP check */
|
||||
return FLATPAK_FILESYSTEM_MODE_NONE;
|
||||
|
||||
qsort (keys, n_keys, sizeof (char *), flatpak_strcmp0_ptr);
|
||||
|
||||
/* Syntactic canonicalization only, no need to use host_fd */
|
||||
@@ -739,7 +742,7 @@ flatpak_exports_path_get_mode (FlatpakExports *exports,
|
||||
g_string_append (path2_builder, parts[j]);
|
||||
}
|
||||
|
||||
return flatpak_exports_path_get_mode (exports, path2_builder->str);
|
||||
return flatpak_exports_path_get_mode_full (exports, path2_builder->str, level + 1);
|
||||
}
|
||||
}
|
||||
else if (parts[i + 1] == NULL)
|
||||
@@ -752,6 +755,14 @@ flatpak_exports_path_get_mode (FlatpakExports *exports,
|
||||
return FLATPAK_FILESYSTEM_MODE_READ_WRITE;
|
||||
}
|
||||
|
||||
/* Returns FLATPAK_FILESYSTEM_MODE_NONE if not visible */
|
||||
FlatpakFilesystemMode
|
||||
flatpak_exports_path_get_mode (FlatpakExports *exports,
|
||||
const char *path)
|
||||
{
|
||||
return flatpak_exports_path_get_mode_full (exports, path, 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
flatpak_exports_path_is_visible (FlatpakExports *exports,
|
||||
const char *path)
|
||||
|
||||
Reference in new issue
Block a user