Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Sep 2021 14:08:46 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a15507a1d5f1 - stable/13 - Restrict spsr updated in the arm64 set_regs*
Message-ID:  <202109271408.18RE8klu082561@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=a15507a1d5f1f5837cc7b41f2259543a7d429a61

commit a15507a1d5f1f5837cc7b41f2259543a7d429a61
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2021-09-13 15:24:34 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2021-09-27 09:55:27 +0000

    Restrict spsr updated in the arm64 set_regs*
    
    When using ptrace(2) on arm64 to set registers in a 32-bit program we
    need to take care to only set some of the fields. Follow the existing
    arm64 path and only let the user set the flags fields. This is also the
    case in the arm kernel so fixes a change in behaviour between the two.
    
    While here update set_regs to only set spsr and elr once.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit b029ef7fe618c6fa0482958422cc362905c15376)
---
 sys/arm64/arm64/machdep.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 1fbe3fbebb6f..eedde49e5de9 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -254,9 +254,7 @@ set_regs(struct thread *td, struct reg *regs)
 	frame = td->td_frame;
 	frame->tf_sp = regs->sp;
 	frame->tf_lr = regs->lr;
-	frame->tf_elr = regs->elr;
 	frame->tf_spsr &= ~PSR_FLAGS;
-	frame->tf_spsr |= regs->spsr & PSR_FLAGS;
 
 	memcpy(frame->tf_x, regs->x, sizeof(frame->tf_x));
 
@@ -268,9 +266,13 @@ set_regs(struct thread *td, struct reg *regs)
 		 * it put it.
 		 */
 		frame->tf_elr = regs->x[15];
-		frame->tf_spsr = regs->x[16] & PSR_FLAGS;
-	}
+		frame->tf_spsr |= regs->x[16] & PSR_FLAGS;
+	} else
 #endif
+	{
+		frame->tf_elr = regs->elr;
+		frame->tf_spsr |= regs->spsr & PSR_FLAGS;
+	}
 	return (0);
 }
 
@@ -490,7 +492,8 @@ set_regs32(struct thread *td, struct reg32 *regs)
 	tf->tf_x[13] = regs->r_sp;
 	tf->tf_x[14] = regs->r_lr;
 	tf->tf_elr = regs->r_pc;
-	tf->tf_spsr = regs->r_cpsr;
+	tf->tf_spsr &= ~PSR_FLAGS;
+	tf->tf_spsr |= regs->r_cpsr & PSR_FLAGS;
 
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109271408.18RE8klu082561>