fpi-device: Get the emulation mode only through compile-time defined libs

In test mode, dynamically load libraries in well known locations that can
allow to override the libfprint behavior.

It would still be possible to potentially inject code by replicating the
distro build directory and adding a library there, but if one is able to
access there, they would already be able to access any path.

Plus the env variable check is still there, so again they would need to
be able to change the fprintd environment
This commit is contained in:
Marco Trevisan (Treviño)
2026-06-19 15:55:13 +02:00
parent 3933e5d468
commit f800bbd485
7 changed files with 59 additions and 11 deletions
+11 -6
View File
@@ -80,11 +80,18 @@ test_emulation_lib = shared_library('fprint-test-emulation',
install: installed_tests,
install_dir: installed_tests_execdir,
)
test_emulation_lib_name = fs.name(test_emulation_lib.full_path())
# Preload the test-emulation library so that the weak NULL implementation
# in libfprint is overridden with one that honours FP_DEVICE_EMULATION.
envs.prepend('LD_PRELOAD', test_emulation_lib.full_path())
# Paths where the test-emulation helper may be loaded via dlopen
test_emulation = configuration_data()
test_emulation.set_quoted('FPI_EMULATION_ENV_VAR',
'FP_DEVICE_EMULATION')
test_emulation.set_quoted('FPI_EMULATION_HELPER_BUILDDIR',
meson.project_build_root() / 'tests')
test_emulation.set_quoted('FPI_EMULATION_HELPER_INSTALLDIR',
libexecdir / 'installed-tests' / versioned_libname)
test_emulation.set_quoted('FPI_EMULATION_HELPER_MODULE',
fs.name(test_emulation_lib.full_path()))
configure_file(output: 'fpi-test-emulation.h', configuration: test_emulation)
env_parser_cmd = '''
import os;
@@ -98,7 +105,6 @@ envs_str = run_command(python3, '-c', env_parser_cmd,
envs_str = ' '.join([
envs_str,
'LD_PRELOAD=' + (installed_tests_execdir / test_emulation_lib_name),
'G_TEST_SRCDIR=' + installed_tests_testdir,
'G_TEST_BUILDDIR=' + installed_tests_execdir,
])
@@ -225,7 +231,6 @@ if get_option('introspection')
'driver_test': driver_test,
'driver_env': ' '.join([
driver_envs_str,
'LD_PRELOAD=' + (installed_tests_execdir / test_emulation_lib_name),
'LD_LIBRARY_PATH=' + installed_tests_libdir,
# FIXME: Adding this requires gnome-desktop-testing!12
# 'GI_TYPELIB_PATH=' + installed_tests_libdir / 'girepository-1.0',
+2 -1
View File
@@ -17,6 +17,7 @@
*/
#include "fpi-device.h"
#include "fpi-test-emulation.h"
gboolean
(fpi_device_emulation_mode_enabled) (FpDevice *device)
@@ -25,7 +26,7 @@ gboolean
if (g_once_init_enter (&emulation_mode))
g_once_init_leave (&emulation_mode,
g_strcmp0 (g_getenv ("FP_DEVICE_EMULATION"), "1") == 0 ?
g_strcmp0 (g_getenv (FPI_EMULATION_ENV_VAR), "1") == 0 ?
TRUE : G_MAXSIZE);
return emulation_mode == TRUE;