Skip to content

Commit 24e3580

Browse files
Jan BeulichIngo Molnar
authored andcommitted
x86: Don't leak 64-bit kernel register values to 32-bit processes
While 32-bit processes can't directly access R8...R15, they can gain access to these registers by temporarily switching themselves into 64-bit mode. Therefore, registers not preserved anyway by called C functions (i.e. R8...R11) must be cleared prior to returning to user mode. Signed-off-by: Jan Beulich <jbeulich@novell.com> Cc: <stable@kernel.org> LKML-Reference: <4AC34D73020000780001744A@vpn.id2.novell.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 4701472 commit 24e3580

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

‎arch/x86/ia32/ia32entry.S‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#define __AUDIT_ARCH_LE 0x40000000
2222

2323
#ifndef CONFIG_AUDITSYSCALL
24-
#define sysexit_audit int_ret_from_sys_call
25-
#define sysretl_audit int_ret_from_sys_call
24+
#define sysexit_audit ia32_ret_from_sys_call
25+
#define sysretl_audit ia32_ret_from_sys_call
2626
#endif
2727

2828
#define IA32_NR_syscalls ((ia32_syscall_end - ia32_sys_call_table)/8)
@@ -39,12 +39,12 @@
3939
.endm
4040

4141
/* clobbers %eax */
42-
.macro CLEAR_RREGS _r9=rax
42+
.macro CLEAR_RREGS offset=0, _r9=rax
4343
xorl %eax,%eax
44-
movq %rax,R11(%rsp)
45-
movq %rax,R10(%rsp)
46-
movq %\_r9,R9(%rsp)
47-
movq %rax,R8(%rsp)
44+
movq %rax,\offset+R11(%rsp)
45+
movq %rax,\offset+R10(%rsp)
46+
movq %\_r9,\offset+R9(%rsp)
47+
movq %rax,\offset+R8(%rsp)
4848
.endm
4949

5050
/*
@@ -172,6 +172,10 @@ sysexit_from_sys_call:
172172
movl RIP-R11(%rsp),%edx /* User %eip */
173173
CFI_REGISTER rip,rdx
174174
RESTORE_ARGS 1,24,1,1,1,1
175+
xorq %r8,%r8
176+
xorq %r9,%r9
177+
xorq %r10,%r10
178+
xorq %r11,%r11
175179
popfq
176180
CFI_ADJUST_CFA_OFFSET -8
177181
/*CFI_RESTORE rflags*/
@@ -202,7 +206,7 @@ sysexit_from_sys_call:
202206

203207
.macro auditsys_exit exit,ebpsave=RBP
204208
testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
205-
jnz int_ret_from_sys_call
209+
jnz ia32_ret_from_sys_call
206210
TRACE_IRQS_ON
207211
sti
208212
movl %eax,%esi /* second arg, syscall return value */
@@ -218,8 +222,9 @@ sysexit_from_sys_call:
218222
cli
219223
TRACE_IRQS_OFF
220224
testl %edi,TI_flags(%r10)
221-
jnz int_with_check
222-
jmp \exit
225+
jz \exit
226+
CLEAR_RREGS -ARGOFFSET
227+
jmp int_with_check
223228
.endm
224229

225230
sysenter_auditsys:
@@ -329,6 +334,9 @@ sysretl_from_sys_call:
329334
CFI_REGISTER rip,rcx
330335
movl EFLAGS-ARGOFFSET(%rsp),%r11d
331336
/*CFI_REGISTER rflags,r11*/
337+
xorq %r10,%r10
338+
xorq %r9,%r9
339+
xorq %r8,%r8
332340
TRACE_IRQS_ON
333341
movl RSP-ARGOFFSET(%rsp),%esp
334342
CFI_RESTORE rsp
@@ -353,7 +361,7 @@ cstar_tracesys:
353361
#endif
354362
xchgl %r9d,%ebp
355363
SAVE_REST
356-
CLEAR_RREGS r9
364+
CLEAR_RREGS 0, r9
357365
movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
358366
movq %rsp,%rdi /* &pt_regs -> arg1 */
359367
call syscall_trace_enter
@@ -425,6 +433,8 @@ ia32_do_call:
425433
call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
426434
ia32_sysret:
427435
movq %rax,RAX-ARGOFFSET(%rsp)
436+
ia32_ret_from_sys_call:
437+
CLEAR_RREGS -ARGOFFSET
428438
jmp int_ret_from_sys_call
429439

430440
ia32_tracesys:
@@ -442,8 +452,8 @@ END(ia32_syscall)
442452

443453
ia32_badsys:
444454
movq $0,ORIG_RAX-ARGOFFSET(%rsp)
445-
movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
446-
jmp int_ret_from_sys_call
455+
movq $-ENOSYS,%rax
456+
jmp ia32_sysret
447457

448458
quiet_ni_syscall:
449459
movq $-ENOSYS,%rax

0 commit comments

Comments
 (0)