Page MenuHomeFreeBSD

Fix execution of linux binaries with glibc>=2.24
ClosedPublic

Authored by trasz on Jun 18 2019, 7:56 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 19, 12:05 AM
Unknown Object (File)
Mon, Nov 18, 10:02 AM
Unknown Object (File)
Mon, Nov 18, 12:14 AM
Unknown Object (File)
Tue, Nov 12, 8:30 PM
Unknown Object (File)
Sun, Nov 10, 8:37 PM
Unknown Object (File)
Sat, Nov 2, 9:57 AM
Unknown Object (File)
Mon, Oct 28, 4:44 AM
Unknown Object (File)
Oct 16 2024, 3:27 AM

Details

Summary

Fix running linux binaries linked against newer glibc. Without
it they segfault on startup in a hard to reproduce way - try running
"/bin/echo 1 1 1 1 1 1" with varying amounts of "1"s; first do
"sysctl compat.linux.osrelease='5.0.0'".

The reason for this is not known; it's more of a hack than a proper fix.
There's a new compat.linux.align_stack sysctl to disable it, just in case.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/amd64/linux/linux_sysvec.c
349 ↗(On Diff #58773)

FWIW, 8 instead of 24 works too.

Do you have more details about working/non-working versions? I.e., what glibc version works?

Also is it the case that /bin/echo 1 1 1 1 1... consistently fails with some number of 1s and runs successfully with other cases? Like 1 1 1 works, 1 1 1 1 fails, 1 1 1 1 1 works?

Do you have more details about working/non-working versions? I.e., what glibc version works?

Not really, I'm afraid - the one from CentOS 7 (latest one) works, the one from Ubuntu doesn't.

Also is it the case that /bin/echo 1 1 1 1 1... consistently fails with some number of 1s and runs successfully with other cases? Like 1 1 1 works, 1 1 1 1 fails, 1 1 1 1 1 works?

Exactly. Basically: the vectp must not end in 0x0.

trasz edited the summary of this revision. (Show Details)

Prettify, add sysctl.

I suspect I know what's going on. If vectp % 16 == 8 then when long argc is stuck in front of it per the ABI requirements, the stack is aligned to 16 bytes. I suspect a change was made to require 16-byte alignment as recommend by Intel. A possibly relevant thread (I've only skimmed it) https://lore.kernel.org/patchwork/patch/749568/

Based on @brooks' comment let's drop the sysctl.

What do you think of a formulation like ((vectp + 8) & ~0xF) - 8

Apply comments from brooks and emaste.

sys/amd64/linux/linux_sysvec.c
347 ↗(On Diff #61576)

This should probably say something like:

...glibc depends on a 16-byte stack alignment. One "long argc" will be prepended later.

fwiw the argc is prepended in linux_fixup_elf

This revision is now accepted and ready to land.Sep 3 2019, 2:01 PM