Bug 275031 - rc.d/ldconfig missing hard-coded /lib/casper from rtld-elf STANDARD_LIBRARY_PATH
Summary: rc.d/ldconfig missing hard-coded /lib/casper from rtld-elf STANDARD_LIBRARY_PATH
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 13.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-11 19:59 UTC by John W. O'Brien
Modified: 2023-12-27 11:41 UTC (History)
5 users (show)

See Also:


Attachments
stable/12: Prepend /lib/casper to rc.d/ldconfig's baseline (469 bytes, text/plain)
2023-11-11 19:59 UTC, John W. O'Brien
no flags Details
stable/13: Prepend /lib/casper to rc.d/ldconfig's baseline (469 bytes, patch)
2023-11-11 20:01 UTC, John W. O'Brien
no flags Details | Diff
stable/12: Initialize ldconfig baseline paths from rtld standard library paths (770 bytes, patch)
2023-11-12 22:04 UTC, John W. O'Brien
no flags Details | Diff
stable/13: Initialize ldconfig baseline paths from rtld standard library paths (770 bytes, patch)
2023-11-12 22:05 UTC, John W. O'Brien
no flags Details | Diff
rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths (1.39 KB, patch)
2023-11-13 15:33 UTC, John W. O'Brien
john: maintainer-approval? (kib)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John W. O'Brien 2023-11-11 19:59:19 UTC
Created attachment 246246 [details]
stable/12: Prepend /lib/casper to rc.d/ldconfig's baseline

Synopsis
========

ldconfig manages the file at _PATH_ELF_HINTS and always includes a baseline set of directories independent of its rc vars such as ldconfig_paths and ldconfig_local_dirs. After consulting the hints, rtld falls back to a hard-coded list of library directories. The ldconfig hard-coded path is a subset of the rtld hard-coded path whereas they should be identical.


Context
=======

% ldd /usr/local/sbin/tcpdump | grep libcap_dns
        libcap_dns.so.2 => /lib/casper/libcap_dns.so.2 (0x21349571a000)
% /usr/local/sbin/tcpdump --version
tcpdump version 4.99.4
libpcap version 1.10.4
OpenSSL 1.1.1w  11 Sep 2023
%


Expected behavior
=================

% sudo pkg check -B tcpdump
Checking tcpdump: 100%
%


Observed behavior
=================

% sudo pkg check -B tcpdump
Checking tcpdump:   0%
(tcpdump-4.99.4_1) /usr/local/sbin/tcpdump - required shared library libcap_dns.so.2 not found
Checking tcpdump: 100%
%


Analysis
========

The "pkg check -B" command has no hard-coded default path and relies on the elf-hints maintained by ldconfig. The ldconfig baseline (_LDC) is set to "/lib /usr/lib" in libexec/rc/rc.d/ldconfig on the (still supported) stable/12 and stable/13 branches. The rtld baseline (STANDARD_LIBRARY_PATH) is set to  "/lib/casper:/lib:/usr/lib" in libexec/rtld-elf/paths.h on the stable/12 branch and in libexec/rtld-elf/rtld_paths.h on the stable/13 branch. Considering rtld to be authoritative, ldconfig's baseline needs correction.

The main and stable/14 branches are not affected because the casper shared libs have been moved to /lib, so the rtld and ldconfig baselines agree.


See also
========

https://lists.freebsd.org/archives/freebsd-ports/2023-November/004889.html


Testing
=======

% echo /lib/casper |
     sudo tee /usr/local/libdata/ldconfig/casper > /dev/null
% sudo service ldconfig restart
ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/local/lib 
/usr/local/lib/compat/pkg /lib/casper /usr/local/lib/compat/pkg 
/usr/local/lib/perl5/5.36/mach/CORE /usr/local/llvm15/lib
32-bit compatibility ldconfig path: /usr/lib32
% sudo pkg check -B tcpdump
Checking tcpdump: 100%
Comment 1 John W. O'Brien 2023-11-11 20:01:17 UTC
Created attachment 246247 [details]
stable/13: Prepend /lib/casper to rc.d/ldconfig's baseline

The patches for stable/12 and stable/13 are nearly identical. Both are included for completeness.
Comment 2 Konstantin Belousov freebsd_committer freebsd_triage 2023-11-11 20:37:39 UTC
I have no opinion about (dying) stable/12.

For main and all living stable branches (stable/14, and stable/13) the better
approach is to initialize _LDC from the 'Default lib path' line in the
/libexec/ld-elf.so.1 -v output.

Similarly, ldconfig32_paths should take system paths from the
/libexec/ld-elf32.so.1 -v output.

This way it would be fixed once and for all future tweaks.
Comment 3 John W. O'Brien 2023-11-11 21:30:01 UTC
(In reply to Konstantin Belousov from comment #2)

> For main and all living stable branches (stable/14, and
> stable/13) the better approach is to initialize _LDC from
> the 'Default lib path' line in the /libexec/ld-elf.so.1 -v
> output.

Like this?

_LDC=`/libexec/ld-elf.so.1 -v | sed -n -e 's/:/ /' -e 's/^Default lib path //p'`

> Similarly, ldconfig32_paths should take system paths from
> the /libexec/ld-elf32.so.1 -v output.

Should that happen when /etc/defaults/rc.conf is first generated, or every time it is processed?
Comment 4 Tatsuki Makino 2023-11-11 22:48:43 UTC
(In reply to Konstantin Belousov from comment #2)
> I have no opinion about (dying) stable/12.

I used 12.4-STABLE when I did my research on this :)


A quick workaround is the following

echo 'ldconfig_paths="/lib/casper ${ldconfig_paths:-}"' >> /etc/rc.conf

If anything, I would prefer to consider this hard-coded on ports/ports-mgmt/pkg side...
Comment 5 Konstantin Belousov freebsd_committer freebsd_triage 2023-11-12 00:29:54 UTC
(In reply to John W. O'Brien from comment #3)
I do not understand what it has to do with rc.conf.

Also, I would write the calculation somewhat differently:
_LDC=$(/libexec/ld-elf.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' ')
to only edit the relevant line.
Comment 6 John W. O'Brien 2023-11-12 20:01:23 UTC
(In reply to Konstantin Belousov from comment #5)

> I do not understand what it has to do with rc.conf.

It was I who did not understand when you mentioned ldconfig32_paths. I see now that the section of rc.d/ldconfig that handles 32-bit compatibility re-initializes _LDC="", and that is where the system paths should be set.


> Also, I would write the calculation somewhat differently:
> _LDC=$(/libexec/ld-elf.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' ')
> to only edit the relevant line.

I will incorporate that into revised patches.
Comment 7 John W. O'Brien 2023-11-12 22:04:30 UTC
Created attachment 246263 [details]
stable/12: Initialize ldconfig baseline paths from rtld standard library paths
Comment 8 John W. O'Brien 2023-11-12 22:05:14 UTC
Created attachment 246264 [details]
stable/13: Initialize ldconfig baseline paths from rtld standard library paths
Comment 9 Konstantin Belousov freebsd_committer freebsd_triage 2023-11-12 22:15:50 UTC
(In reply to John W. O'Brien from comment #8)
Do you have account on reviews.freebsd.org?  Please put your stable/13' patch
there.
Comment 10 John W. O'Brien 2023-11-12 22:36:26 UTC
(In reply to Konstantin Belousov from comment #9)
Certainly.

In light of this, more general approach, I realize this change should be applied to main and subsequently back-ported to stable/14, stable/13, and (if still relevant) stable/12. I will prepare the Phabricator revision accordingly.
Comment 11 John W. O'Brien 2023-11-12 22:58:28 UTC
See review D42557.
Comment 12 Tatsuki Makino 2023-11-13 01:29:34 UTC
(In reply to Konstantin Belousov from comment #5)

This is for (life expectancy less than 2 months) stable/12 or earlier :)


I see that you are now modifying the default values to get them from the command...

Is there a problem with leaving /usr/src/libexec/rc/rc.conf side empty and only using the command if it is empty?

But, I don't see what the point is in specifying it on the rc.conf side, though :)
Comment 13 Tatsuki Makino 2023-11-13 02:57:31 UTC
(In reply to Tatsuki Makino from comment #12)

Sorry, comment #12 is a terrible misdirection.
The value in /etc/default/rc.conf was only appended.

It was to match the default values hard-coded in /usr/src/libexec/rc/rc.d/ldconfig with the default values hard-coded in /usr/src/libexec/rtld-elf/*path*.h.

How about pioneering an option on libexec/rtld-elf side that allows output per value?
Something about the pipes seems too redundant.
Comment 14 John W. O'Brien 2023-11-13 15:33:13 UTC
Created attachment 246272 [details]
rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths
Comment 15 commit-hook freebsd_committer freebsd_triage 2023-11-13 23:40:02 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=99132daf6f70cb0cc969c555d3612547fa3cf1db

commit 99132daf6f70cb0cc969c555d3612547fa3cf1db
Author:     John W. O'Brien <john@saltant.com>
AuthorDate: 2023-11-12 22:45:27 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-11-13 23:39:17 +0000

    rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths

    Ensure that ldconfig-managed elf and elf32 hints always include
    the standard library paths that are known independently to rtld.

    PR:                     275031
    Reviewed by:            kib
    MFC after:              2 weeks
    Sponsored by:           Saltant Solutions LLC
    Differential Revision:  https://reviews.freebsd.org/D42557

 libexec/rc/rc.d/ldconfig | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 16 Tatsuki Makino 2023-11-16 04:48:43 UTC
(In reply to commit-hook from comment #15)

It seems that using the results of ld-elf*.so.1 run as is may result in setting up a directory that does not exist.

Shortcut to its reporting
https://lists.freebsd.org/archives/freebsd-ports/2023-November/004910.html
Comment 17 Konstantin Belousov freebsd_committer freebsd_triage 2023-11-16 05:48:00 UTC
(In reply to Tatsuki Makino from comment #16)
This is innocent.  Anyway, I put the fix at https://reviews.freebsd.org/D42626
Comment 18 Tatsuki Makino 2023-11-16 06:23:48 UTC
(In reply to Konstantin Belousov from comment #17)

I think that should be a check added to the 64-bit side as well.
Here, all data is picked up automatically, and deficiencies are avoided automatically.
Then, only the rtld side would have to check to see if the directory is actually there, won't it?
Comment 19 commit-hook freebsd_committer freebsd_triage 2023-11-28 11:41:43 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5dba91f557f0fb295977a07b2837b0351723b9c8

commit 5dba91f557f0fb295977a07b2837b0351723b9c8
Author:     John W. O'Brien <john@saltant.com>
AuthorDate: 2023-11-12 22:45:27 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-11-28 11:39:39 +0000

    rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths

    PR:                     275031

    (cherry picked from commit 99132daf6f70cb0cc969c555d3612547fa3cf1db)

 libexec/rc/rc.d/ldconfig | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 20 commit-hook freebsd_committer freebsd_triage 2023-11-28 11:43:47 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=481273492bbbab5ee1978a24e55b13c1f39bc560

commit 481273492bbbab5ee1978a24e55b13c1f39bc560
Author:     John W. O'Brien <john@saltant.com>
AuthorDate: 2023-11-12 22:45:27 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-11-28 11:42:22 +0000

    rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths

    PR:                     275031

    (cherry picked from commit 99132daf6f70cb0cc969c555d3612547fa3cf1db)

 libexec/rc/rc.d/ldconfig | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 21 Mark Linimon freebsd_committer freebsd_triage 2023-12-27 11:41:16 UTC
^Triage: assign to committer that resolved.  Already mfced to 13.