diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2020-06-15 13:18:34 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2020-06-15 13:18:34 +0000 |
commit | aec50f272cb073305fcec4e9633a45e99a271abe (patch) | |
tree | 3723a0376fc3af3d0e0ffa6d85fabb6d435f303e | |
parent | b5a8904220350abfde4290ff9959a991506fbdab (diff) |
Raise SPL when modifying ps_klist to prevent a race with interrupts.
The list can be accessed from interrupt context if a signal is sent
from an interrupt handler.
OK anton@ cheloha@ mpi@
-rw-r--r-- | sys/kern/kern_event.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_sig.c | 8 |
2 files changed, 15 insertions, 3 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index bb1340da842..ac793bd2045 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_event.c,v 1.137 2020/06/14 07:22:55 visa Exp $ */ +/* $OpenBSD: kern_event.c,v 1.138 2020/06/15 13:18:33 visa Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> @@ -246,6 +246,7 @@ int filt_procattach(struct knote *kn) { struct process *pr; + int s; if ((curproc->p_p->ps_flags & PS_PLEDGE) && (curproc->p_p->ps_pledge & PLEDGE_PROC) == 0) @@ -274,7 +275,9 @@ filt_procattach(struct knote *kn) kn->kn_flags &= ~EV_FLAG1; } + s = splhigh(); klist_insert(&pr->ps_klist, kn); + splx(s); return (0); } @@ -291,11 +294,14 @@ void filt_procdetach(struct knote *kn) { struct process *pr = kn->kn_ptr.p_process; + int s; if (kn->kn_status & KN_DETACHED) return; + s = splhigh(); klist_remove(&pr->ps_klist, kn); + splx(s); } int @@ -324,10 +330,10 @@ filt_proc(struct knote *kn, long hint) s = splhigh(); kn->kn_status |= KN_DETACHED; - splx(s); kn->kn_flags |= (EV_EOF | EV_ONESHOT); kn->kn_data = W_EXITCODE(pr->ps_xexit, pr->ps_xsig); klist_remove(&pr->ps_klist, kn); + splx(s); return (1); } diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 76ebe1cc68d..757507fedd3 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.257 2020/06/14 07:22:55 visa Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.258 2020/06/15 13:18:33 visa Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -1803,6 +1803,7 @@ int filt_sigattach(struct knote *kn) { struct process *pr = curproc->p_p; + int s; if (kn->kn_id >= NSIG) return EINVAL; @@ -1810,7 +1811,9 @@ filt_sigattach(struct knote *kn) kn->kn_ptr.p_process = pr; kn->kn_flags |= EV_CLEAR; /* automatically set */ + s = splhigh(); klist_insert(&pr->ps_klist, kn); + splx(s); return (0); } @@ -1819,8 +1822,11 @@ void filt_sigdetach(struct knote *kn) { struct process *pr = kn->kn_ptr.p_process; + int s; + s = splhigh(); klist_remove(&pr->ps_klist, kn); + splx(s); } /* |