Skip to content

Fix duplicate libfprint_private code / global state

Popax21 requested to merge Popax21/libfprint:tod into tod

Currently, both libfprint-2.so (the library linked into e.g. fprintd) and libfprint-2-tod.so (the library being linked into TOD modules) statically link libfprint_private. This however causes the private code + global variables to be present twice, which results in undefined behavior and assertion failures (e.g. type getters like fpi_device_action_get_type end up registering the same type twice, which can end in libfprint locking up)

image

My proposed fix is to not link libfprint_private into the libfprint target at all, but instead replace all references to it with a dependency on libfprint_tod, which does still link in libfprint_private. However, special care has to be taken of symbol visibility: even though libfprint_tod exposes almost all symbols globally, libnbis has to explicitly be linked in twice, as its functions aren't exposed (this is OK, as it doesn't have any global state which could cause issues). Additionally, two functions (enroll_data_free and match_data_free) have to be marked as global by adding them to libfprint-tod.ver.in, as they're referenced by public parts of libfprint's code, even though they aren't part of the private API.

As for specific build system changes, this patch makes libfprint_tod explicitly be a shared_library to prevent Meson from linking it in statically, and also links in libfprint_private using link_whole, to prevent symbols from being lost or optimized away. Additionally, libfprint_tod now doesn't compile with libfprint_private's source files. Other than this, all references to libfprint_private have been replaced with either libfprint_tod or libfprint_private_prov (which is either libfprint_private or libfprint_tod depending on the tod build option)

I'm open to changing the approach taken in my patch if the maintainers would like me to do so.

Edited by Popax21

Merge request reports

Loading