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)
Sat, Nov 1, 6:28 AM
Unknown Object (File)
Mon, Oct 27, 7:36 AM
Unknown Object (File)
Sat, Oct 25, 3:22 AM
Unknown Object (File)
Sun, Oct 19, 12:32 AM
Unknown Object (File)
Fri, Oct 17, 10:49 PM
Unknown Object (File)
Wed, Oct 15, 4:05 AM
Unknown Object (File)
Tue, Oct 14, 6:42 PM
Unknown Object (File)
Tue, Oct 14, 6:42 PM

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 Passed
Unit
No Test Coverage
Build Status
Buildable 26231
Build 24723: arc lint + arc unit

Event Timeline

sys/amd64/linux/linux_sysvec.c
360

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
358

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