1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

Unlock ptsignal by using the ps_mtx instead of KERNEL_LOCK to ensure

the process is not modified during signal delivery.
This also unlocks psignal and prsignal since those are simple wrappers
around ptsignal.

OK mpi@
This commit is contained in:
claudio 2024-11-05 09:14:19 +00:00
parent 09b2714454
commit 2de7505c8a
3 changed files with 24 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_sig.c,v 1.346 2024/11/05 06:03:19 jsg Exp $ */
/* $OpenBSD: kern_sig.c,v 1.347 2024/11/05 09:14:19 claudio Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@ -124,6 +124,8 @@ void postsig_done(struct proc *, int, sigset_t, int);
void postsig(struct proc *, int, struct sigctx *);
int cansignal(struct proc *, struct process *, int);
void ptsignal_locked(struct proc *, int, enum signal_type);
struct pool sigacts_pool; /* memory pool for sigacts structures */
void sigio_del(struct sigiolst *);
@ -877,9 +879,7 @@ trapsignal(struct proc *p, int signum, u_long trapno, int code,
sigexit(p, signum);
/* NOTREACHED */
}
KERNEL_LOCK();
ptsignal(p, signum, STHREAD);
KERNEL_UNLOCK();
}
}
@ -905,11 +905,14 @@ psignal(struct proc *p, int signum)
void
prsignal(struct process *pr, int signum)
{
mtx_enter(&pr->ps_mtx);
/* Ignore signal if the target process is exiting */
if (pr->ps_flags & PS_EXITING) {
mtx_leave(&pr->ps_mtx);
return;
}
ptsignal(TAILQ_FIRST(&pr->ps_threads), signum, SPROCESS);
ptsignal_locked(TAILQ_FIRST(&pr->ps_threads), signum, SPROCESS);
mtx_leave(&pr->ps_mtx);
}
/*
@ -919,6 +922,16 @@ prsignal(struct process *pr, int signum)
*/
void
ptsignal(struct proc *p, int signum, enum signal_type type)
{
struct process *pr = p->p_p;
mtx_enter(&pr->ps_mtx);
ptsignal_locked(p, signum, type);
mtx_leave(&pr->ps_mtx);
}
void
ptsignal_locked(struct proc *p, int signum, enum signal_type type)
{
int prop;
sig_t action, altaction = SIG_DFL;
@ -928,7 +941,7 @@ ptsignal(struct proc *p, int signum, enum signal_type type)
struct proc *q;
int wakeparent = 0;
KERNEL_ASSERT_LOCKED();
MUTEX_ASSERT_LOCKED(&pr->ps_mtx);
#ifdef DIAGNOSTIC
if ((u_int)signum >= NSIG || signum == 0)
@ -998,7 +1011,7 @@ ptsignal(struct proc *p, int signum, enum signal_type type)
}
if (type != SPROPAGATED)
knote(&pr->ps_klist, NOTE_SIGNAL | signum);
knote_locked(&pr->ps_klist, NOTE_SIGNAL | signum);
prop = sigprop[signum];
@ -1017,10 +1030,8 @@ ptsignal(struct proc *p, int signum, enum signal_type type)
* and if it is set to SIG_IGN,
* action will be SIG_DFL here.)
*/
mtx_enter(&pr->ps_mtx);
sigignore = pr->ps_sigacts->ps_sigignore;
sigcatch = pr->ps_sigacts->ps_sigcatch;
mtx_leave(&pr->ps_mtx);
if (sigignore & mask)
return;
@ -1061,7 +1072,7 @@ ptsignal(struct proc *p, int signum, enum signal_type type)
if (prop & (SA_CONT | SA_STOP) && type != SPROPAGATED)
TAILQ_FOREACH(q, &pr->ps_threads, p_thr_link)
if (q != p)
ptsignal(q, signum, SPROPAGATED);
ptsignal_locked(q, signum, SPROPAGATED);
SCHED_LOCK();
@ -2020,15 +2031,11 @@ userret(struct proc *p)
/* send SIGPROF or SIGVTALRM if their timers interrupted this thread */
if (p->p_flag & P_PROFPEND) {
atomic_clearbits_int(&p->p_flag, P_PROFPEND);
KERNEL_LOCK();
psignal(p, SIGPROF);
KERNEL_UNLOCK();
}
if (p->p_flag & P_ALRMPEND) {
atomic_clearbits_int(&p->p_flag, P_ALRMPEND);
KERNEL_LOCK();
psignal(p, SIGVTALRM);
KERNEL_UNLOCK();
}
if (SIGPENDING(p) != 0) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sys_generic.c,v 1.158 2024/08/12 19:32:05 anton Exp $ */
/* $OpenBSD: sys_generic.c,v 1.159 2024/11/05 09:14:19 claudio Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@ -382,11 +382,8 @@ dofilewritev(struct proc *p, int fd, struct uio *uio, int flags,
if (uio->uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
if (error == EPIPE) {
KERNEL_LOCK();
if (error == EPIPE)
ptsignal(p, SIGPIPE, STHREAD);
KERNEL_UNLOCK();
}
}
cnt -= uio->uio_resid;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uipc_syscalls.c,v 1.219 2024/04/25 17:32:53 bluhm Exp $ */
/* $OpenBSD: uipc_syscalls.c,v 1.220 2024/11/05 09:14:19 claudio Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
@ -788,11 +788,8 @@ sendit(struct proc *p, int s, struct msghdr *mp, int flags, register_t *retsize)
if (auio.uio_resid != len && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
if (error == EPIPE && (flags & MSG_NOSIGNAL) == 0) {
KERNEL_LOCK();
if (error == EPIPE && (flags & MSG_NOSIGNAL) == 0)
ptsignal(p, SIGPIPE, STHREAD);
KERNEL_UNLOCK();
}
}
if (error == 0) {
*retsize = len - auio.uio_resid;