| author | |
| committer | |
| log | c666ebb1f8aac440a4d0d554e9f8aa836bf58060 |
| tree | ddbed1598f7fa9f0737c4a33a72c560b585577b7 |
| parent | da018f972619377e8c044c5c27ebf231be262bb3 |
| signature |
Whatever was in the frame pointer register prior to clone() will no longer be
valid in the child process, so zero it to protect FP-based unwinders. This is
just an extension of what was already done for i386 and x86_64. Only applied
to architectures where the _start() code also zeroes the frame pointer.13 files changed, 40 insertions(+), 35 deletions(-)
lib/libc/musl/src/thread/aarch64/clone.s+2-1| ... | ... | @@ -24,7 +24,8 @@ __clone: |
| 24 | 24 | 	// parent |
| 25 | 25 | 	ret |
| 26 | 26 | 	// child |
| 27 | 1:	ldp x1,x0,[sp],#16 | |
| 27 | 1:	mov fp, 0 | |
| 28 | 	ldp x1,x0,[sp],#16 | |
| 28 | 29 | 	blr x1 |
| 29 | 30 | 	mov x8,#93 // SYS_exit |
| 30 | 31 | 	svc #0 |
lib/libc/musl/src/thread/arm/clone.s+2-1| ... | ... | @@ -19,7 +19,8 @@ __clone: |
| 19 | 19 | 	ldmfd sp!,{r4,r5,r6,r7} |
| 20 | 20 | 	bx lr |
| 21 | 21 | |
| 22 | 1:	mov r0,r6 | |
| 22 | 1:	mov fp,#0 | |
| 23 | 	mov r0,r6 | |
| 23 | 24 | 	bl 3f |
| 24 | 25 | 2:	mov r7,#1 |
| 25 | 26 | 	svc 0 |
lib/libc/musl/src/thread/i386/clone.s+8-9| ... | ... | @@ -30,9 +30,15 @@ __clone: |
| 30 | 30 | 	mov 8(%ebp),%ebp |
| 31 | 31 | 	int $128 |
| 32 | 32 | 	test %eax,%eax |
| 33 | 	jnz 1f | |
| 33 | 	jz 1f | |
| 34 | 	add $16,%esp | |
| 35 | 	pop %edi | |
| 36 | 	pop %esi | |
| 37 | 	pop %ebx | |
| 38 | 	pop %ebp | |
| 39 | 	ret | |
| 34 | 40 | |
| 35 | 	mov %ebp,%eax | |
| 41 | 1:	mov %ebp,%eax | |
| 36 | 42 | 	xor %ebp,%ebp |
| 37 | 43 | 	call *%eax |
| 38 | 44 | 	mov %eax,%ebx |
| ... | ... | @@ -40,10 +46,3 @@ __clone: |
| 40 | 46 | 	inc %eax |
| 41 | 47 | 	int $128 |
| 42 | 48 | 	hlt |
| 43 | ||
| 44 | 1:	add $16,%esp | |
| 45 | 	pop %edi | |
| 46 | 	pop %esi | |
| 47 | 	pop %ebx | |
| 48 | 	pop %ebp | |
| 49 | 	ret |
lib/libc/musl/src/thread/loongarch64/clone.s+1| ... | ... | @@ -22,6 +22,7 @@ __clone: |
| 22 | 22 | 	beqz $a0, 1f # whether child process |
| 23 | 23 | 	jirl $zero, $ra, 0 # parent process return |
| 24 | 24 | 1: |
| 25 | 	move $fp, $zero | |
| 25 | 26 | 	ld.d $t8, $sp, 0 # function pointer |
| 26 | 27 | 	ld.d $a0, $sp, 8 # argument pointer |
| 27 | 28 | 	jirl $ra, $t8, 0 # call the user's function |
lib/libc/musl/src/thread/m68k/clone.s+2-1| ... | ... | @@ -18,7 +18,8 @@ __clone: |
| 18 | 18 | 	beq 1f |
| 19 | 19 | 	movem.l (%sp)+,%d2-%d5 |
| 20 | 20 | 	rts |
| 21 | 1:	move.l %a1,-(%sp) | |
| 21 | 1:	suba.l %%fp,%%fp | |
| 22 | 	move.l %a1,-(%sp) | |
| 22 | 23 | 	jsr (%a0) |
| 23 | 24 | 	move.l #1,%d0 |
| 24 | 25 | 	trap #0 |
lib/libc/musl/src/thread/microblaze/clone.s+2-1| ... | ... | @@ -22,7 +22,8 @@ __clone: |
| 22 | 22 | 	rtsd r15, 8 |
| 23 | 23 | 	nop |
| 24 | 24 | |
| 25 | 1:	lwi r3, r1, 0 | |
| 25 | 1:	add r19, r0, r0 | |
| 26 | 	lwi r3, r1, 0 | |
| 26 | 27 | 	lwi r5, r1, 4 |
| 27 | 28 | 	brald r15, r3 |
| 28 | 29 | 	nop |
lib/libc/musl/src/thread/mips/clone.s+2-1| ... | ... | @@ -27,7 +27,8 @@ __clone: |
| 27 | 27 | 	addu $sp, $sp, 16 |
| 28 | 28 | 	jr $ra |
| 29 | 29 | 	nop |
| 30 | 1:	lw $25, 0($sp) | |
| 30 | 1:	move $fp, $0 | |
| 31 | 	lw $25, 0($sp) | |
| 31 | 32 | 	lw $4, 4($sp) |
| 32 | 33 | 	jalr $25 |
| 33 | 34 | 	nop |
lib/libc/musl/src/thread/mips64/clone.s+2-1| ... | ... | @@ -25,7 +25,8 @@ __clone: |
| 25 | 25 | 	nop |
| 26 | 26 | 	jr	$ra |
| 27 | 27 | 	nop |
| 28 | 1:	ld	$25, 0($sp)	# function pointer | |
| 28 | 1:	move	$fp, $0 | |
| 29 | 	ld	$25, 0($sp)	# function pointer | |
| 29 | 30 | 	ld	$4, 8($sp)	# argument pointer |
| 30 | 31 | 	jalr	$25		# call the user's function |
| 31 | 32 | 	nop |
lib/libc/musl/src/thread/mipsn32/clone.s+2-1| ... | ... | @@ -25,7 +25,8 @@ __clone: |
| 25 | 25 | 	nop |
| 26 | 26 | 	jr	$ra |
| 27 | 27 | 	nop |
| 28 | 1:	lw	$25, 0($sp)	# function pointer | |
| 28 | 1:	move	$fp, $0 | |
| 29 | 	lw	$25, 0($sp)	# function pointer | |
| 29 | 30 | 	lw	$4, 4($sp)	# argument pointer |
| 30 | 31 | 	jalr	$25		# call the user's function |
| 31 | 32 | 	nop |
lib/libc/musl/src/thread/or1k/clone.s+2-1| ... | ... | @@ -23,7 +23,8 @@ __clone: |
| 23 | 23 | 	l.jr	r9 |
| 24 | 24 | 	 l.nop |
| 25 | 25 | |
| 26 | 1:	l.lwz	r11, 0(r1) | |
| 26 | 1:	l.ori	r2, r0, 0 | |
| 27 | 	l.lwz	r11, 0(r1) | |
| 27 | 28 | 	l.jalr	r11 |
| 28 | 29 | 	 l.lwz	r3, 4(r1) |
| 29 | 30 |
lib/libc/musl/src/thread/powerpc/clone.s+9-12| ... | ... | @@ -48,9 +48,16 @@ neg 3, 3 #negate the result (errno) |
| 48 | 48 | # compare sc result with 0 |
| 49 | 49 | cmpwi cr7, 3, 0 |
| 50 | 50 | |
| 51 | # if not 0, jump to end | |
| 52 | bne cr7, 2f | |
| 51 | # if not 0, restore stack and return | |
| 52 | beq cr7, 2f | |
| 53 | 53 | |
| 54 | lwz 30, 0(1) | |
| 55 | lwz 31, 4(1) | |
| 56 | addi 1, 1, 16 | |
| 57 | ||
| 58 | blr | |
| 59 | ||
| 60 | 2: | |
| 54 | 61 | #else: we're the child |
| 55 | 62 | #call funcptr: move arg (d) into r3 |
| 56 | 63 | mr 3, 31 |
| ... | ... | @@ -61,13 +68,3 @@ bctrl |
| 61 | 68 | # mov SYS_exit into r0 (the exit param is already in r3) |
| 62 | 69 | li 0, 1 |
| 63 | 70 | sc |
| 64 | ||
| 65 | 2: | |
| 66 | ||
| 67 | # restore stack | |
| 68 | lwz 30, 0(1) | |
| 69 | lwz 31, 4(1) | |
| 70 | addi 1, 1, 16 | |
| 71 | ||
| 72 | blr | |
| 73 |
lib/libc/musl/src/thread/x32/clone.s+3-3| ... | ... | @@ -15,12 +15,12 @@ __clone: |
| 15 | 15 | 	mov %rcx,(%rsi) |
| 16 | 16 | 	syscall |
| 17 | 17 | 	test %eax,%eax |
| 18 | 	jnz 1f | |
| 19 | 	xor %ebp,%ebp | |
| 18 | 	jz 1f | |
| 19 | 	ret | |
| 20 | 1:	xor %ebp,%ebp | |
| 20 | 21 | 	pop %rdi |
| 21 | 22 | 	call *%r9 |
| 22 | 23 | 	mov %eax,%edi |
| 23 | 24 | 	movl $0x4000003c,%eax /* SYS_exit */ |
| 24 | 25 | 	syscall |
| 25 | 26 | 	hlt |
| 26 | 1:	ret |
lib/libc/musl/src/thread/x86_64/clone.s+3-3| ... | ... | @@ -16,8 +16,9 @@ __clone: |
| 16 | 16 | 	mov %rcx,(%rsi) |
| 17 | 17 | 	syscall |
| 18 | 18 | 	test %eax,%eax |
| 19 | 	jnz 1f | |
| 20 | 	xor %ebp,%ebp | |
| 19 | 	jz 1f | |
| 20 | 	ret | |
| 21 | 1:	xor %ebp,%ebp | |
| 21 | 22 | 	pop %rdi |
| 22 | 23 | 	call *%r9 |
| 23 | 24 | 	mov %eax,%edi |
| ... | ... | @@ -25,4 +26,3 @@ __clone: |
| 25 | 26 | 	mov $60,%al |
| 26 | 27 | 	syscall |
| 27 | 28 | 	hlt |
| 28 | 1:	ret |