Skip to content
Snippets Groups Projects

pressure-vessel: Remap preloadable modules better

Merged Simon McVittie requested to merge wip/t29490 into master
1 file
+ 28
45
Compare changes
  • Side-by-side
  • Inline
+ 28
45
@@ -719,7 +719,12 @@ static PreloadModule opt_preload_modules[] =
{ "LD_AUDIT", NULL },
{ "LD_PRELOAD", NULL },
};
static PreloadModule adjusted_preload_modules[G_N_ELEMENTS (opt_preload_modules)];
static const char * const adverb_preload_options[G_N_ELEMENTS (opt_preload_modules)] =
{
/* Must be in the same order as opt_preload_modules */
"--ld-audit",
"--ld-preload",
};
/*
* check_main_program:
@@ -1325,6 +1330,7 @@ main (int argc,
g_autoptr(FILE) original_stdout = NULL;
g_autoptr(GArray) pass_fds_through_adverb = g_array_new (FALSE, FALSE, sizeof (int));
const char *steam_app_id;
g_autoptr(GPtrArray) adverb_preload_argv = NULL;
setlocale (LC_ALL, "");
@@ -2085,6 +2091,8 @@ main (int argc,
FLATPAK_FILESYSTEM_MODE_READ_WRITE,
"/tmp");
adverb_preload_argv = g_ptr_array_new_with_free_func (g_free);
/* We need the LD_PRELOADs from Steam visible at the paths that were
* used for them, which might be their physical rather than logical
* locations. Steam doesn't generally use LD_AUDIT, but the Steam app
@@ -2093,13 +2101,12 @@ main (int argc,
{
const char *variable = opt_preload_modules[i].variable;
const GPtrArray *values = opt_preload_modules[i].values;
const char *option = adverb_preload_options[i];
gsize len;
gsize j;
g_debug ("Adjusting %s...", variable);
adjusted_preload_modules[i].variable = variable;
if (values == NULL)
len = 0;
else
@@ -2142,9 +2149,10 @@ main (int argc,
adjusted_path = g_build_filename ("/run/parent", preload, NULL);
g_debug ("%s -> %s", preload, adjusted_path);
pv_preload_lists_append (adjusted_preload_modules,
G_N_ELEMENTS (adjusted_preload_modules),
variable, adjusted_path);
g_ptr_array_add (adverb_preload_argv,
g_strdup_printf ("%s=%s",
option,
adjusted_path));
if (g_str_has_suffix (preload, "/libshared-library-guard.so"))
{
@@ -2165,9 +2173,10 @@ main (int argc,
else
{
g_debug ("%s -> unmodified", preload);
pv_preload_lists_append (adjusted_preload_modules,
G_N_ELEMENTS (adjusted_preload_modules),
variable, preload);
g_ptr_array_add (adverb_preload_argv,
g_strdup_printf ("%s=%s",
option,
preload));
}
/* No FlatpakExports here: any file not in /usr or /app that
@@ -2189,9 +2198,10 @@ main (int argc,
/* When using a runtime we can't write to /usr/ or /libQUAL/,
* so redirect this preloaded module to the corresponding
* location in /run/host. */
pv_preload_lists_append (adjusted_preload_modules,
G_N_ELEMENTS (adjusted_preload_modules),
variable, adjusted_path);
g_ptr_array_add (adverb_preload_argv,
g_strdup_printf ("%s=%s",
option,
adjusted_path));
}
else
{
@@ -2212,9 +2222,10 @@ main (int argc,
preload);
}
pv_preload_lists_append (adjusted_preload_modules,
G_N_ELEMENTS (adjusted_preload_modules),
variable, preload);
g_ptr_array_add (adverb_preload_argv,
g_strdup_printf ("%s=%s",
option,
preload));
}
}
else
@@ -2624,36 +2635,7 @@ main (int argc,
break;
}
for (i = 0; i < G_N_ELEMENTS (adjusted_preload_modules); i++)
{
const gchar *variable = adjusted_preload_modules[i].variable;
const GPtrArray *values = adjusted_preload_modules[i].values;
const gchar *option = NULL;
gsize j;
if (g_strcmp0 (variable, "LD_AUDIT") == 0)
{
option = "--ld-audit";
}
else if (g_strcmp0 (variable, "LD_PRELOAD") == 0)
{
option = "--ld-preload";
}
else
{
/* Programming error: this logic needs to be updated
* to handle this new preload module */
g_critical ("Unhandled preload module %s", variable);
continue;
}
if (values == NULL)
continue;
for (j = 0; j < values->len; j++)
flatpak_bwrap_add_arg_printf (adverb_argv, "%s=%s", option,
(gchar *)g_ptr_array_index (values, j));
}
flatpak_bwrap_append_args (adverb_argv, adverb_preload_argv);
if (opt_verbose)
flatpak_bwrap_add_arg (adverb_argv, "--verbose");
@@ -2796,6 +2778,7 @@ out:
pv_preload_modules_free (opt_preload_modules, G_N_ELEMENTS (opt_preload_modules));
g_clear_pointer (&adverb_preload_argv, g_ptr_array_unref);
g_clear_pointer (&opt_env_if_host, g_strfreev);
g_clear_pointer (&opt_freedesktop_app_id, g_free);
g_clear_pointer (&opt_steam_app_id, g_free);
Loading