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.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Comment Actions
Hi. Thanks for the patch, it solves my problem with some 32-bit binaries crashing on processors without FSGSBASE support.
Comment Actions
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.
Comment Actions
Did _anything_ worked at all with the previous version of the patch? Please try this variant.
Comment Actions
At least one of the previously crashed binaries started working without problems.
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.