Skip to contentSkip to conversation

x86-64: ptrace ia32 BP fix

PATCH Roland McGrath 1 participant 1 message Jul 5, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 6 lines · Roland McGrath
Quoted 5 lines
arch/x86_64/ia32/ia32entry.S +0 -0
@@ -102,6 +102,7 @@ sysenter_do_call:	
 	.byte	0xf, 0x35
 
Quoted 6 lines

arch/x86_64/ia32/ia32entry.S sysenter_do_call: · line 106

Quoted 3 lines
arch/x86_64/ia32/ia32entry.S +1 -0
 sysenter_tracesys:
+	movl	%r9d,%ebp
 	SAVE_REST

This is wrong because it will clobber ebp before it is saved. It is only saved in SAVE_REST.

It is right because it stores %ebp before it is saved in the argument block that ptrace can access. That is the point of it. %r9d has the value loaded from (%rbp) just prior to this code, which is what %ebp should reflect to match the i386 behavior.

Quoted 10 lines
Quoted 10 lines
arch/x86_64/ia32/ia32entry.S +0 -3
 	CLEAR_RREGS
 	movq	$-ENOSYS,RAX(%rsp)	/* really needed? */
@@ -109,13 +110,7 @@ sysenter_tracesys:
 	call	syscall_trace_enter
 	LOAD_ARGS ARGOFFSET  /* reload args from stack in case ptrace changed it */
 	RESTORE_REST
-	movl	%ebp, %ebp
-	/* no need to do an access_ok check here because rbp has been
-	   32bit zero extended */ 
Quoted 8 lines

arch/x86_64/ia32/ia32entry.S sysenter_tracesys: · line 113

Quoted 5 lines
arch/x86_64/ia32/ia32entry.S +1 -4
-1:	movl	(%rbp),%r9d
-	.section __ex_table,"a"
-	.quad 1b,ia32_badarg
-	.previous
+	movl	%ebp,%r9d

And this also cannot be correct because RESTORE_REST has overwritten %rbp already.

This is also correct because RESTORE_REST has stored into %rbp the value in the argument block, which ptrace may have modified. This movl ensures that this changed value is what the system call's argument will be.

The patch is tested and works. Just try strace on a 32-bit program that calls mmap2 and look at the 6th argument value. It shows a stack address without this patch. With this patch, it shows the argument value the same as strace on a native i386 kernel does.

Thanks,
Roland