Page MenuHomeFreeBSD

amd64: do not restore fsbase/gsbase for 32bit processes
ClosedPublic

Authored by kib on Jun 16 2026, 9:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jul 16, 1:54 AM
Unknown Object (File)
Wed, Jul 15, 7:26 AM
Unknown Object (File)
Wed, Jul 15, 7:26 AM
Unknown Object (File)
Thu, Jul 9, 1:17 AM
Unknown Object (File)
Tue, Jul 7, 2:58 AM
Unknown Object (File)
Sun, Jul 5, 12:41 AM
Unknown Object (File)
Fri, Jul 3, 1:06 PM
Unknown Object (File)
Fri, Jul 3, 5:24 AM

Details

Summary
There is no WRFSBASE and WRGSBASE 32bit variants at all. As such, the
fsbase and gsbase must always be equal to the bases in the corresponding
segment descriptor, same as on real i386.

If a 32bit program reloads either %fs or %gs using setcontext(9) or
sigreturn(9), restoring bases from the syscall entry time is wrong.
In all other cases, hardware already does the right action when the
segment register is loaded, and the bases for the ufssel/ugssel in GDT
are updated on the context switch.

Diff Detail

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

Event Timeline

kib requested review of this revision.Jun 16 2026, 9:52 PM
This revision is now accepted and ready to land.Jun 16 2026, 10:21 PM

Hi. Thanks for the patch, it solves my problem with some 32-bit binaries crashing on processors without FSGSBASE support.

Fix gsbase restore.

Simply loading %gs correctly loads MSR_GSBASE but not the MSR_KGSBASE for which we do SWAPGS right before IRETQ. We need to do the equivalent of "xchg MSR_GSBASE, MSR_KGSBASE" after the 'mov %ax,%gs" to get the right registers values for doreti.

This revision now requires review to proceed.Jun 17 2026, 3:43 PM

Hi. Thanks for the patch, it solves my problem with some 32-bit binaries crashing on processors without FSGSBASE support.

Did _anything_ worked at all with the previous version of the patch? Please try this variant.

In D57611#1321114, @kib wrote:

Did _anything_ worked at all with the previous version of the patch?

At least one of the previously crashed binaries started working without problems.

In D57611#1321114, @kib wrote:

Please try this variant.

With the new patch, all the problematic binaries I know of work fine.

P.S. Test environment: CPU without FSGSBASE, FreeBSD 15.1 amd64 in bhyve, FreeBSD 5.5 i386 in chroot.

Move 32bit gdbase block out of the hot path.

This revision was not accepted when it landed; it landed in state Needs Review.Jun 21 2026, 12:17 PM
This revision was automatically updated to reflect the committed changes.