diff --git a/ChangeLog b/ChangeLog index 8a6c668..ea010a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2015-07-01 Igor Zamyatin + + * sysdeps/i386/dl-trampoline.S (_dl_runtime_profile): Save + and restore Intel MPX return bound registers + * sysdeps/x86_64/dl-trampoline.h: Add PRESERVE_BND_REGS_PREFIX to + call, jump and ret instructions to not loose bounds. + * sysdeps/x86/bits/link.h (La_i86_retval): Add lrv_bnd0 and + lrv_bnd1. + 2015-06-30 Torvald Riegel * nptl/DESIGN-systemtap-probes.txt: Remove lll_lock_wait, diff --git a/sysdeps/i386/dl-trampoline.S b/sysdeps/i386/dl-trampoline.S index f11972c..1c8e3d7 100644 --- a/sysdeps/i386/dl-trampoline.S +++ b/sysdeps/i386/dl-trampoline.S @@ -18,6 +18,12 @@ #include +#ifdef HAVE_MPX_SUPPORT +# define PRESERVE_BND_REGS_PREFIX bnd +#else +# define PRESERVE_BND_REGS_PREFIX .byte 0xf2 +#endif + .text .globl _dl_runtime_resolve .type _dl_runtime_resolve, @function @@ -161,24 +167,39 @@ _dl_runtime_profile: +4 free %esp free */ - subl $20, %esp - cfi_adjust_cfa_offset (20) - movl %eax, (%esp) - movl %edx, 4(%esp) - fstpt 8(%esp) - fstpt 20(%esp) + subl $36, %esp + cfi_adjust_cfa_offset (36) +#ifdef HAVE_MPX_SUPPORT + bndmov %bnd0, (%esp) + bndmov %bnd1, 8(%esp) +#else + .byte 0x66,0x0f,0x1b,0x04,0x24 + .byte 0x66,0x0f,0x1b,0x4c,0x24,0x08 +#endif + movl %eax, 16(%esp) + movl %edx, 20(%esp) + fstpt 24(%esp) + fstpt 36(%esp) pushl %esp cfi_adjust_cfa_offset (4) - leal 36(%esp), %ecx - movl 56(%esp), %eax - movl 60(%esp), %edx + leal 52(%esp), %ecx + movl 72(%esp), %eax + movl 76(%esp), %edx call _dl_call_pltexit - movl (%esp), %eax - movl 4(%esp), %edx - fldt 20(%esp) - fldt 8(%esp) - addl $60, %esp - cfi_adjust_cfa_offset (-60) +#ifdef HAVE_MPX_SUPPORT + bndmov (%esp), %bnd0 + bndmov 8(%esp), %bnd1 +#else + .byte 0x66,0x0f,0x1a,0x04,0x24 + .byte 0x66,0x0f,0x1a,0x4c,0x24,0x08 +#endif + movl 16(%esp), %eax + movl 20(%esp), %edx + fldt 36(%esp) + fldt 24(%esp) + addl $76, %esp + cfi_adjust_cfa_offset (-76) + PRESERVE_BND_REGS_PREFIX ret cfi_endproc .size _dl_runtime_profile, .-_dl_runtime_profile diff --git a/sysdeps/x86/bits/link.h b/sysdeps/x86/bits/link.h index 3f559c9..0bf9b9a 100644 --- a/sysdeps/x86/bits/link.h +++ b/sysdeps/x86/bits/link.h @@ -38,6 +38,8 @@ typedef struct La_i86_retval uint32_t lrv_edx; long double lrv_st0; long double lrv_st1; + uint64_t lrv_bnd0; + uint64_t lrv_bnd1; } La_i86_retval; diff --git a/sysdeps/x86_64/dl-trampoline.h b/sysdeps/x86_64/dl-trampoline.h index 0e5a6fb..d542428 100644 --- a/sysdeps/x86_64/dl-trampoline.h +++ b/sysdeps/x86_64/dl-trampoline.h @@ -63,20 +63,6 @@ movaps (LR_XMM_OFFSET + XMM_SIZE*6)(%rsp), %xmm6 movaps (LR_XMM_OFFSET + XMM_SIZE*7)(%rsp), %xmm7 -#ifndef __ILP32__ -# ifdef HAVE_MPX_SUPPORT - bndmov (LR_BND_OFFSET)(%rsp), %bnd0 # Restore bound - bndmov (LR_BND_OFFSET + BND_SIZE)(%rsp), %bnd1 # registers. - bndmov (LR_BND_OFFSET + BND_SIZE*2)(%rsp), %bnd2 - bndmov (LR_BND_OFFSET + BND_SIZE*3)(%rsp), %bnd3 -# else - .byte 0x66,0x0f,0x1a,0x84,0x24;.long (LR_BND_OFFSET) - .byte 0x66,0x0f,0x1a,0x8c,0x24;.long (LR_BND_OFFSET + BND_SIZE) - .byte 0x66,0x0f,0x1a,0x94,0x24;.long (LR_BND_OFFSET + BND_SIZE*2) - .byte 0x66,0x0f,0x1a,0x9c,0x24;.long (LR_BND_OFFSET + BND_SIZE*3) -# endif -#endif - #ifdef RESTORE_AVX /* Check if any xmm0-xmm7 registers are changed by audit module. */ @@ -154,8 +140,24 @@ 1: #endif + +#ifndef __ILP32__ +# ifdef HAVE_MPX_SUPPORT + bndmov (LR_BND_OFFSET)(%rsp), %bnd0 # Restore bound + bndmov (LR_BND_OFFSET + BND_SIZE)(%rsp), %bnd1 # registers. + bndmov (LR_BND_OFFSET + BND_SIZE*2)(%rsp), %bnd2 + bndmov (LR_BND_OFFSET + BND_SIZE*3)(%rsp), %bnd3 +# else + .byte 0x66,0x0f,0x1a,0x84,0x24;.long (LR_BND_OFFSET) + .byte 0x66,0x0f,0x1a,0x8c,0x24;.long (LR_BND_OFFSET + BND_SIZE) + .byte 0x66,0x0f,0x1a,0x94,0x24;.long (LR_BND_OFFSET + BND_SIZE*2) + .byte 0x66,0x0f,0x1a,0x9c,0x24;.long (LR_BND_OFFSET + BND_SIZE*3) +# endif +#endif + mov 16(%rbx), %R10_LP # Anything in framesize? test %R10_LP, %R10_LP + PRESERVE_BND_REGS_PREFIX jns 3f /* There's nothing in the frame size, so there @@ -174,6 +176,7 @@ addq $48, %rsp # Adjust the stack to the return value # (eats the reloc index and link_map) cfi_adjust_cfa_offset(-48) + PRESERVE_BND_REGS_PREFIX jmp *%r11 # Jump to function address. 3: @@ -200,6 +203,7 @@ movq 32(%rdi), %rsi movq 40(%rdi), %rdi + PRESERVE_BND_REGS_PREFIX call *%r11 mov 24(%rbx), %rsp # Drop the copied stack content @@ -280,11 +284,11 @@ #ifndef __ILP32__ # ifdef HAVE_MPX_SUPPORT - bndmov LRV_BND0_OFFSET(%rcx), %bnd0 # Restore bound registers. - bndmov LRV_BND1_OFFSET(%rcx), %bnd1 + bndmov LRV_BND0_OFFSET(%rsp), %bnd0 # Restore bound registers. + bndmov LRV_BND1_OFFSET(%rsp), %bnd1 # else - .byte 0x66,0x0f,0x1a,0x81;.long (LRV_BND0_OFFSET) - .byte 0x66,0x0f,0x1a,0x89;.long (LRV_BND1_OFFSET) + .byte 0x66,0x0f,0x1a,0x84,0x24;.long (LRV_BND0_OFFSET) + .byte 0x66,0x0f,0x1a,0x8c,0x24;.long (LRV_BND1_OFFSET) # endif #endif @@ -299,6 +303,7 @@ addq $48, %rsp # Adjust the stack to the return value # (eats the reloc index and link_map) cfi_adjust_cfa_offset(-48) + PRESERVE_BND_REGS_PREFIX retq #ifdef MORE_CODE