NPTL/TLS segment flipping code problem
Looking at this code (2.0.2), it appears to have a couple of problems I could not find mentioned on the mailing list archive:
(1) If base is zero in an expand-up segment, the conversion will yield an expand-down segment covering the whole 4Gb, thus providing a mechanism to obtain access to XEN space.
(2) If a malicious program accesses memory at a small negative offset from gs:0 and the access extends into the positive range, the access will gp-fault with either descriptor setting, thus leading to an endless loop of flipping between the two states.
(3) Since escaped opcodes (those starting with 0F) aren't handled, accessing mm/xmm data in __thread variables (along with other specialized operations on such variable the compiler might generate) is going to kill the program. Of course, it is similarly problematic that SIB addressing still isn't implemented, but that's at least stated so in the code.
(4) In the no-mod-r/m handling of the decoder, the byte case is handled
incorrectly: The address it deals with is still a 32-byte (or 16-byte, but 16-bit addressing isn't handled anyway) one. There simply must not be a 'case 1' there, and the insn_decode table should be changed accordingly.
(5, minor) The change from 2.0.1 to 2.0.2 (making the code a lot more correct) left an access to the no longer existing positive_access parameter of fixup_seg in (at least) one of the DPRINTK-s.
Jan
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Quoted 2 lines
Looking at this code (2.0.2), it appears to have a couple of problems I could not find mentioned on the mailing list archive:
Thanks, we'll look into these.
The whole TLS workaround is a huge pain in the butt, and has pretty horrible performance anyhow. The segment flipping approach doesn't buy us much as +ve and -ve accesses seem to be interleaved. It at least enables some simplifications to the instruction decoder (though as you point out, we need to extend it some).
We really need to look into producing a suitably patched glibc rpm. Likewise, we need to prevent gcc from generating -ve offsets for tls as the default.
Ian
Quoted 29 lines
(1) If base is zero in an expand-up segment, the conversion will yield an expand-down segment covering the whole 4Gb, thus providing a mechanism to obtain access to XEN space.
(2) If a malicious program accesses memory at a small negative offset from gs:0 and the access extends into the positive range, the access will gp-fault with either descriptor setting, thus leading to an endless loop of flipping between the two states.
(3) Since escaped opcodes (those starting with 0F) aren't handled, accessing mm/xmm data in
__threadvariables (along with other specialized operations on such variable the compiler might generate) is going to kill the program. Of course, it is similarly problematic that SIB addressing still isn't implemented, but that's at least stated so in the code.(4) In the no-mod-r/m handling of the decoder, the byte case is handled
incorrectly: The address it deals with is still a 32-byte (or 16-byte, but 16-bit addressing isn't handled anyway) one. There simply must not be a 'case 1' there, and theinsn_decodetable should be changed accordingly.(5, minor) The change from 2.0.1 to 2.0.2 (making the code a lot more correct) left an access to the no longer existing
positive_accessparameter offixup_segin (at least) one of the DPRINTK-s.Jan
Quoted 8 lines
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xen-devel
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Hi!
Ian Pratt wrote:
[..]
Quoted 3 lines
We really need to look into producing a suitably patched glibc rpm. Likewise, we need to prevent gcc from generating -ve offsets for tls as the default.
You can workaround that in userspace with:
LD_ASSUME_KERNEL=2.4.9
Set it in /etc/environment or in your kernel command line. The later depends on your setup: IMMV.
Regards,
Nuno Silva
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
I don't think that would get us all the way. It would stop ld.so linking to TLS glibc after booting, but:
1. GCC can now emit -ve offset accesses directly in application binaries. So the problem may not be entirely solvable at link-time.
2. Still need to deal with linking of 'init' process, which is run before you get a chance to set LD_ASSUME_KERNEL.
Maybe there's a workaround for 2 less invasive than deleting /lib/tls, but I don't know what it is.
-- Keir
Quoted 22 lines
Hi!
Ian Pratt wrote:
[..]
Quoted 3 lines
We really need to look into producing a suitably patched glibc rpm. Likewise, we need to prevent gcc from generating -ve offsets for tls as the default.
You can workaround that in userspace with:
LD_ASSUME_KERNEL=2.4.9Set it in
/etc/environmentor in your kernel command line. The later depends on your setup: IMMV.Regards,
Nuno Silva
Quoted 8 lines
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xen-devel
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Quoted 6 lines
Looking at this code (2.0.2), it appears to have a couple of problems I could not find mentioned on the mailing list archive:
(1) If base is zero in an expand-up segment, the conversion will yield an expand-down segment covering the whole 4Gb, thus providing a mechanism to obtain access to XEN space.
No it won't. When we flip to expands-down we set the limit to
(-(base & PAGE_MASK) >> 12) - 1
== (-(0 & PAGE_MASK) >> 12) - 1
== 0 - 1
== 0xfffff
This is a *zero-length* grows-down segment, exactly as we require for safety. [Yes, you can have a zero-length grows-down segment, even though it is impossible to have a zero-length grows-up segment -- I tested on real silicon.]
Quoted 4 lines
(2) If a malicious program accesses memory at a small negative offset from gs:0 and the access extends into the positive range, the access will gp-fault with either descriptor setting, thus leading to an endless loop of flipping between the two states.
Harmless. The guest OS will still execute (e.g., to service timer interrupts) and will be able to preempt the malicious program when it has received its timeslice. So the program cannot take over the machine -- it can only receive the same amount of CPU as a user-space infinite CPU loop.
Quoted 6 lines
(3) Since escaped opcodes (those starting with 0F) aren't handled, accessing mm/xmm data in
__threadvariables (along with other specialized operations on such variable the compiler might generate) is going to kill the program. Of course, it is similarly problematic that SIB addressing still isn't implemented, but that's at least stated so in the code.
Yes there are restrictions in what it supports. But we have a DPRINTK for those cases so we can fix them up as/if they occur.
Quoted 5 lines
(4) In the no-mod-r/m handling of the decoder, the byte case is handled
incorrectly: The address it deals with is still a 32-byte (or 16-byte, but 16-bit addressing isn't handled anyway) one. There simply must not be a 'case 1' there, and theinsn_decodetable should be changed accordingly.
You mean the following fragment?
if ( !(decode & HAS_MODRM) )
{
switch ( decode & 7 )
{
case 1:
offset = (long)(*(char *)pb);
goto skip_modrm;It is correct -- sign extends the 8-bit offset to a signed long as we require. The instruction only contains a single-byte offset -- it isn't stored as 16 or 32 bits.
Quoted 3 lines
(5, minor) The change from 2.0.1 to 2.0.2 (making the code a lot more correct) left an access to the no longer existing
positive_accessparameter offixup_segin (at least) one of the DPRINTK-s.
Now fixed in the new 2.0.3 release. The FC3 issue that some poeple (including Rik) were seeing is also now fixed.
-- Keir
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt