Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jun 2022 19:41:34 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d37548e01059 - stable/13 - linux(4): Properly restore the thread signal mask after signal delivery on i386
Message-ID:  <202206171941.25HJfYCk030640@gitrepo.freebsd.org>

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

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

commit d37548e01059f7cff3b88bebe894b7519b7fd1e6
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-05-30 17:03:49 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:35:40 +0000

    linux(4): Properly restore the thread signal mask after signal delivery on i386
    
    Replace sigframe sf_extramask by native sigset_t and use it to
    store/restore the thread signal mask without conversion to/from
    Linux signal mask.
    
    Pointy hat to:          dchagin
    MFC after:              2 weeks
    
    (cherry picked from commit 4a6c2d075da0c5105269e6edcbe57bf6aaa0a0ae)
---
 sys/amd64/linux32/linux32_sysvec.c | 11 ++---------
 sys/i386/linux/linux_sysvec.c      | 10 ++--------
 sys/x86/linux/linux_x86_sigframe.h |  2 +-
 3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index 2b0d2d267fbe..4b6464bd7b81 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -373,7 +373,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 	bzero(&frame, sizeof(frame));
 
 	frame.sf_sig = sig;
-
+	frame.sf_sigmask = *mask;
 	bsd_to_linux_sigset(mask, &lmask);
 
 	/* Build the signal context to be used by sigreturn. */
@@ -399,8 +399,6 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 	frame.sf_sc.sc_cr2    = (u_int32_t)(uintptr_t)ksi->ksi_addr;
 	frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(code);
 
-	frame.sf_extramask[0] = lmask.__mask;
-
 	if (copyout(&frame, fp, sizeof(frame)) != 0) {
 		/*
 		 * Process has trashed its stack; give it an illegal
@@ -442,8 +440,6 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
 {
 	struct l_sigframe frame;
 	struct trapframe *regs;
-	sigset_t bmask;
-	l_sigset_t lmask;
 	int eflags;
 	ksiginfo_t ksi;
 
@@ -477,10 +473,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
 		return(EINVAL);
 	}
 
-	lmask.__mask = frame.sf_sc.sc_mask;
-	lmask.__mask = frame.sf_extramask[0];
-	linux_to_bsd_sigset(&lmask, &bmask);
-	kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
+	kern_sigprocmask(td, SIG_SETMASK, &frame.sf_sigmask, NULL, 0);
 
 	/* Restore signal context. */
 	regs->tf_rdi    = frame.sf_sc.sc_edi;
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index b11a3ae136bf..14be8f7aa36b 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -474,7 +474,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 	bzero(&frame, sizeof(frame));
 
 	frame.sf_sig = sig;
-
+	frame.sf_sigmask = *mask;
 	bsd_to_linux_sigset(mask, &lmask);
 
 	/* Build the signal context to be used by sigreturn. */
@@ -500,8 +500,6 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 	frame.sf_sc.sc_cr2    = (register_t)ksi->ksi_addr;
 	frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(ksi->ksi_trapno);
 
-	frame.sf_extramask[0] = lmask.__mask;
-
 	if (copyout(&frame, fp, sizeof(frame)) != 0) {
 		/*
 		 * Process has trashed its stack; give it an illegal
@@ -540,8 +538,6 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
 {
 	struct l_sigframe frame;
 	struct trapframe *regs;
-	l_sigset_t lmask;
-	sigset_t bmask;
 	int eflags;
 	ksiginfo_t ksi;
 
@@ -577,9 +573,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
 		return (EINVAL);
 	}
 
-	lmask.__mask = frame.sf_sc.sc_mask;
-	linux_to_bsd_sigset(&lmask, &bmask);
-	kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
+	kern_sigprocmask(td, SIG_SETMASK, &frame.sf_sigmask, NULL, 0);
 
 	/* Restore signal context. */
 	/* %gs was restored by the trampoline. */
diff --git a/sys/x86/linux/linux_x86_sigframe.h b/sys/x86/linux/linux_x86_sigframe.h
index 56ff346ea5b7..75d9a104a345 100644
--- a/sys/x86/linux/linux_x86_sigframe.h
+++ b/sys/x86/linux/linux_x86_sigframe.h
@@ -116,7 +116,7 @@ struct l_sigframe {
 	l_int			sf_sig;
 	struct l_sigcontext	sf_sc;
 	struct l_fpstate	sf_fpstate;
-	l_uint			sf_extramask[1];
+	sigset_t		sf_sigmask;
 };
 
 struct l_rt_sigframe {



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