Page MenuHomeFreeBSD

Make ldconfig put */lib/compat* at the end of the search list
Needs ReviewPublic

Authored by se on Jan 14 2022, 10:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 6, 10:31 PM
Unknown Object (File)
Mon, Nov 3, 10:36 AM
Unknown Object (File)
Oct 24 2025, 3:48 AM
Unknown Object (File)
Sep 8 2025, 8:01 AM
Unknown Object (File)
Sep 4 2025, 5:19 PM
Unknown Object (File)
Sep 4 2025, 12:59 PM
Unknown Object (File)
Aug 15 2025, 6:51 AM
Unknown Object (File)
Aug 11 2025, 12:15 PM
Subscribers
None

Details

Reviewers
imp
kib
bapt
Summary

If ldconfig -m adds a new directory to the search path, it is put at the end of the list.
This makes libraries in that directory inaccessible, if an older library of that name has been preserved in a lib/compat directory.
The result can be mismatched libraries, especially after a port upgrade that did not bump library numbers.
And that happened to me repeatedly and prevented server ports from starting, the samba server in this particular case.

But this can also be a severe security issue, if after a port upgrade the vulnerable library in a compat directory is preferred over the fixed one!

The patch put up for review puts paths that contain "/lib/compat" at the end of the search list.
Libraries can still be found in compat directories, but same name libraries in non-compat directories will be preferred.

This is a significant change from long established behavior, but I think there are good reasons to pessimize libraries in compat directories during lookup, especially because of security concerns, if vulnerable libraries are still used after an upgrade!

Test Plan

Compare output of "ldconfig -r" with and without the patch.

Expected result:

  • The number of shared libraries listed is unchanged.
  • The path list on the 2nd line has the same elements, only in a different order.
  • All elements not containing "/lib/compat" precede those containing that string.
  • The relative order of elements not containing "/lib/compat" is unchanged within that subset.
  • The relative order of elements containing "/lib/compat" is unchanged within that subset.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

se requested review of this revision.Jan 14 2022, 10:16 AM
se created this revision.

I object against ldconfig(8) changes. If you want a way to force merged directories to go at the head of the list, add an option to ldconfig(8) to do that.

The practical problem is that the 'best' order is both machine- and person- depended. For instance, I have both gcc10 and gcc11 installed on my dev workstation, and what I want is to have gcc11 lib/ to be before gcc10, so that newer libstdc++.so.6 is always selected. Right now the order is determined by the order of local/etc/rc.d directory sorting.

Solving the building order for the ports ldconfig additions should be rc.d/ldconfig + ports solution.