Page MenuHomeFreeBSD

rtld: add direct-exec option -o
ClosedPublic

Authored by kib on Sun, Apr 28, 6:55 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 30, 4:41 PM
Unknown Object (File)
Tue, Apr 30, 2:29 PM
Unknown Object (File)
Tue, Apr 30, 2:11 PM
Unknown Object (File)
Tue, Apr 30, 2:11 PM
Unknown Object (File)
Tue, Apr 30, 2:11 PM
Unknown Object (File)
Tue, Apr 30, 8:33 AM
Unknown Object (File)
Tue, Apr 30, 7:57 AM
Unknown Object (File)
Sun, Apr 28, 3:10 PM
Subscribers

Details

Summary
allowing to set any known LD_ parameter for the current rtld invocation,
but without polluting the activated' binary environment.  In other
words, the set parameter is not exported into the environment.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Sun, Apr 28, 6:55 AM

Is there some simple regression test we can add to verify that 1) -o overrides the environment, and 2) actually works? My first idea for a simple test is to use LD_PRELOAD=./libfoo.so /libexec/ld-elf.so.1 -o PRELOAD=./libpythagoras.so cat and then check that libpythagoras.so (some dummy library used in rtld tests) is loaded using procstat -v. Maybe there's a simpler test?

libexec/rtld-elf/rtld.1
396
401
402
406
407
407

So if LD_BIND_NOW=1 is set in the env and one passes -o BIND_NOW=0, we'll get the latter's semantics but LD_BIND_NOW=1 will be set in the environment? That seems potentially quite confusing (not for BIND_NOW specifically, but in general).

I do not object to the idea, I'm just wondering if it's sensible for rtld to print a warning in this scenario.

libexec/rtld-elf/rtld.c
6178

I don't really see the point of calculating strlen(l->n) if we're going to use strncmp() anyway. I see that rtld_init_env_vars_for_prefix() does this as well, but the reason is also not obvious to me.

kib marked 7 inline comments as done.Sun, Apr 28, 8:01 PM
kib added inline comments.
libexec/rtld-elf/rtld.1
407

Note that LD_BIND_NOW=0 is fully equal to LD_BIND_NOW=1 from the rtld PoV. This should be even more confusing, but this is the historical behavior.

If you need to isolate direct exec from env settings, there is the '-u' option already.

libexec/rtld-elf/rtld.c
6178

strncmp is used because n is not nul-terminated for our purposes (it is terminated by '='). This is the rare reasonable use of strncmp.

kib marked 2 inline comments as done.

Grammar updates.

markj added inline comments.
libexec/rtld-elf/rtld.1
398
libexec/rtld-elf/rtld.c
6178

The use of strncmp() makes sense to me, it's the check v - n == (ptrdiff_t)strlen(l->n) that seems redundant.

This revision is now accepted and ready to land.Tue, Apr 30, 12:01 AM
kib marked 2 inline comments as done.Tue, Apr 30, 12:15 AM
kib added inline comments.
libexec/rtld-elf/rtld.c
6178

Suppose that l->n == "ABCD", and n == "AB=1". Without strlen() comparison, the strncmp() check alone would succeed.

This revision was automatically updated to reflect the committed changes.
kib marked an inline comment as done.