git: cd304fdbe95b - stable/13 - i386: do not allow userspace to set tf_trapno on sigreturn(2)

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 31 Aug 2022 01:32:13 UTC
The branch stable/13 has been updated by kib:

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

commit cd304fdbe95b844f4dff5cd40d213f6923c8767b
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-08-19 01:26:37 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-08-31 01:20:27 +0000

    i386: do not allow userspace to set tf_trapno on sigreturn(2)
    
    PR:     265889
    
    (cherry picked from commit dc4a2d1d0e838579f21d9d1fef8655f902f06ab2)
---
 sys/i386/i386/exec_machdep.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/i386/i386/exec_machdep.c b/sys/i386/i386/exec_machdep.c
index 2223dd2a1efa..a3fc0178d322 100644
--- a/sys/i386/i386/exec_machdep.c
+++ b/sys/i386/i386/exec_machdep.c
@@ -636,6 +636,7 @@ osigreturn(struct thread *td, struct osigreturn_args *uap)
 	regs->tf_esp = scp->sc_sp;
 	regs->tf_eip = scp->sc_pc;
 	regs->tf_eflags = eflags;
+	regs->tf_trapno = T_RESERVED;
 
 #if defined(COMPAT_43)
 	if (scp->sc_onstack & 1)
@@ -735,6 +736,7 @@ freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
 
 		bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs));
 	}
+	regs->tf_trapno = T_RESERVED;
 
 #if defined(COMPAT_43)
 	if (ucp->uc_mcontext.mc_onstack & 1)
@@ -869,6 +871,7 @@ sys_sigreturn(struct thread *td, struct sigreturn_args *uap)
 			return (ret);
 		bcopy(&ucp->uc_mcontext.mc_fs, regs, sizeof(*regs));
 	}
+	regs->tf_trapno = T_RESERVED;
 
 #if defined(COMPAT_43)
 	if (ucp->uc_mcontext.mc_onstack & 1)