From 19eb87d22a5314e238867d1e30894cc9dadf3ec4 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Wed, 7 Mar 2001 03:37:06 +0000 Subject: [PATCH] Grab the process lock while calling psignal and before calling psignal. --- sys/alpha/alpha/machdep.c | 4 +-- sys/alpha/osf1/osf1_signal.c | 2 +- sys/amd64/amd64/fpu.c | 2 ++ sys/amd64/amd64/machdep.c | 8 ++++-- sys/amd64/isa/npx.c | 2 ++ sys/compat/linprocfs/linprocfs_vnops.c | 6 ++--- sys/compat/svr4/svr4_stream.c | 5 +++- sys/dev/syscons/scmouse.c | 4 +++ sys/dev/syscons/syscons.c | 4 +++ sys/dev/usb/uhid.c | 2 ++ sys/dev/usb/usb.c | 7 ++++-- sys/fs/msdosfs/msdosfs_vnops.c | 2 ++ sys/fs/nwfs/nwfs_io.c | 2 ++ sys/gnu/ext2fs/ext2_readwrite.c | 2 ++ sys/gnu/fs/ext2fs/ext2_readwrite.c | 2 ++ sys/i386/i386/machdep.c | 8 ++++-- sys/i386/isa/npx.c | 2 ++ sys/i386/isa/pcvt/pcvt_ext.c | 25 ++++++++++++++---- sys/i386/isa/spigot.c | 5 +++- sys/i386/linux/linux_sysvec.c | 6 +++-- sys/i386/svr4/svr4_machdep.c | 1 + sys/ia64/ia64/machdep.c | 2 +- sys/kern/sys_generic.c | 10 ++++++-- sys/kern/tty.c | 10 ++++++-- sys/kern/uipc_syscalls.c | 5 +++- sys/kern/vfs_aio.c | 35 +++++++++++++++++++------- sys/msdosfs/msdosfs_vnops.c | 2 ++ sys/nfs/nfs_bio.c | 6 ++++- sys/nfsclient/nfs_bio.c | 6 ++++- sys/nwfs/nwfs_io.c | 2 ++ sys/pc98/i386/machdep.c | 8 ++++-- sys/pc98/pc98/machdep.c | 8 ++++-- sys/pc98/pc98/npx.c | 2 ++ sys/pc98/pc98/syscons.c | 4 +++ sys/pci/meteor.c | 15 ++++++++--- sys/ufs/ufs/ufs_readwrite.c | 2 ++ 36 files changed, 173 insertions(+), 45 deletions(-) diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c index 7238cd1f3a08..ad8d116b9819 100644 --- a/sys/alpha/alpha/machdep.c +++ b/sys/alpha/alpha/machdep.c @@ -1278,8 +1278,8 @@ osendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -1418,8 +1418,8 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } diff --git a/sys/alpha/osf1/osf1_signal.c b/sys/alpha/osf1/osf1_signal.c index 7b533817d863..f84bd4ae4896 100644 --- a/sys/alpha/osf1/osf1_signal.c +++ b/sys/alpha/osf1/osf1_signal.c @@ -619,8 +619,8 @@ osf1_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index 0dab6ae6f66d..87d274b0ec1d 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -781,7 +781,9 @@ npx_intr(dummy) * * Treat them like a true async interrupt. */ + PROC_LOCK(curproc); psignal(curproc, SIGFPE); + PROC_UNLOCK(curproc); } mtx_unlock(&Giant); } diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 0118473017d2..5d9f8bd12833 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -510,8 +510,8 @@ osendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -592,7 +592,9 @@ osendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)fp; @@ -671,8 +673,8 @@ sendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -740,7 +742,9 @@ sendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)sfp; diff --git a/sys/amd64/isa/npx.c b/sys/amd64/isa/npx.c index 0dab6ae6f66d..87d274b0ec1d 100644 --- a/sys/amd64/isa/npx.c +++ b/sys/amd64/isa/npx.c @@ -781,7 +781,9 @@ npx_intr(dummy) * * Treat them like a true async interrupt. */ + PROC_LOCK(curproc); psignal(curproc, SIGFPE); + PROC_UNLOCK(curproc); } mtx_unlock(&Giant); } diff --git a/sys/compat/linprocfs/linprocfs_vnops.c b/sys/compat/linprocfs/linprocfs_vnops.c index 55e3f52b5158..722544a2cd8d 100644 --- a/sys/compat/linprocfs/linprocfs_vnops.c +++ b/sys/compat/linprocfs/linprocfs_vnops.c @@ -300,13 +300,13 @@ linprocfs_ioctl(ap) PROC_UNLOCK(procp); return EINVAL; /* Can only start a stopped process */ } - PROC_UNLOCK(procp); if ((signo = *(int*)ap->a_data) != 0) { - if (signo >= NSIG || signo <= 0) + if (signo >= NSIG || signo <= 0) { + PROC_UNLOCK(procp); return EINVAL; + } psignal(procp, signo); } - PROC_LOCK(procp); procp->p_step = 0; PROC_UNLOCK(procp); wakeup(&procp->p_step); diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c index 87e8482287aa..843a26b31737 100644 --- a/sys/compat/svr4/svr4_stream.c +++ b/sys/compat/svr4/svr4_stream.c @@ -216,8 +216,11 @@ svr4_sendit(p, s, mp, flags) if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + if (error == EPIPE) { + PROC_LOCK(p); psignal(p, SIGPIPE); + PROC_UNLOCK(p); + } } if (error == 0) p->p_retval[0] = len - auio.uio_resid; diff --git a/sys/dev/syscons/scmouse.c b/sys/dev/syscons/scmouse.c index 7bac404d5ed8..30a983edb219 100644 --- a/sys/dev/syscons/scmouse.c +++ b/sys/dev/syscons/scmouse.c @@ -765,7 +765,9 @@ sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, cur_scp->mouse_proc = NULL; cur_scp->mouse_pid = 0; } else { + PROC_LOCK(cur_scp->mouse_proc); psignal(cur_scp->mouse_proc, cur_scp->mouse_signal); + PROC_UNLOCK(cur_scp->mouse_proc); break; } } @@ -818,7 +820,9 @@ sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, cur_scp->mouse_proc = NULL; cur_scp->mouse_pid = 0; } else { + PROC_LOCK(cur_scp->mouse_proc); psignal(cur_scp->mouse_proc, cur_scp->mouse_signal); + PROC_UNLOCK(cur_scp->mouse_proc); break; } } diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index 452c8e0b9d68..631daa490c24 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -2300,7 +2300,9 @@ signal_vt_rel(scr_stat *scp) if (scp->smode.mode != VT_PROCESS) return FALSE; scp->status |= SWITCH_WAIT_REL; + PROC_LOCK(scp->proc); psignal(scp->proc, scp->smode.relsig); + PROC_UNLOCK(scp->proc); DPRINTF(5, ("sending relsig to %d\n", scp->pid)); return TRUE; } @@ -2313,7 +2315,9 @@ signal_vt_acq(scr_stat *scp) if (scp->sc->unit == sc_console_unit) cons_unavail = TRUE; scp->status |= SWITCH_WAIT_ACQ; + PROC_LOCK(scp->proc); psignal(scp->proc, scp->smode.acqsig); + PROC_UNLOCK(scp->proc); DPRINTF(5, ("sending acqsig to %d\n", scp->pid)); return TRUE; } diff --git a/sys/dev/usb/uhid.c b/sys/dev/usb/uhid.c index 1cdd455ff937..f413c3bc48b5 100644 --- a/sys/dev/usb/uhid.c +++ b/sys/dev/usb/uhid.c @@ -366,7 +366,9 @@ uhid_intr(xfer, addr, status) selwakeup(&sc->sc_rsel); if (sc->sc_async != NULL) { DPRINTFN(3, ("uhid_intr: sending SIGIO %p\n", sc->sc_async)); + PROC_LOCK(sc->sc_async); psignal(sc->sc_async, SIGIO); + PROC_UNLOCK(sc->sc_async); } } diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index f917d1f18504..5382ec0f2849 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -51,13 +51,13 @@ #if defined(__NetBSD__) || defined(__OpenBSD__) #include #include -#include #elif defined(__FreeBSD__) #include #include #include #include #endif +#include #include #include #if __FreeBSD_version >= 500014 @@ -683,8 +683,11 @@ usbd_add_event(type, dev) SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next); wakeup(&usb_events); selwakeup(&usb_selevent); - if (usb_async_proc != NULL) + if (usb_async_proc != NULL) { + PROC_LOCK(usb_async_proc); psignal(usb_async_proc, SIGIO); + PROC_UNLOCK(usb_async_proc); + } splx(s); } diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index fb7b83dba9cf..8ed27a073801 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -654,7 +654,9 @@ msdosfs_write(ap) if (p && ((uoff_t)uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); return (EFBIG); } diff --git a/sys/fs/nwfs/nwfs_io.c b/sys/fs/nwfs/nwfs_io.c index 116b0d9c78fe..f6344e03b311 100644 --- a/sys/fs/nwfs/nwfs_io.c +++ b/sys/fs/nwfs/nwfs_io.c @@ -237,7 +237,9 @@ nwfs_writevnode(vp, uiop, cred, ioflag) } if (uiop->uio_resid == 0) return 0; if (p && uiop->uio_offset + uiop->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); return (EFBIG); } error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred); diff --git a/sys/gnu/ext2fs/ext2_readwrite.c b/sys/gnu/ext2fs/ext2_readwrite.c index 64065c3d9a3c..62bc27aa11a2 100644 --- a/sys/gnu/ext2fs/ext2_readwrite.c +++ b/sys/gnu/ext2fs/ext2_readwrite.c @@ -222,7 +222,9 @@ WRITE(ap) if (vp->v_type == VREG && p && uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); return (EFBIG); } diff --git a/sys/gnu/fs/ext2fs/ext2_readwrite.c b/sys/gnu/fs/ext2fs/ext2_readwrite.c index 64065c3d9a3c..62bc27aa11a2 100644 --- a/sys/gnu/fs/ext2fs/ext2_readwrite.c +++ b/sys/gnu/fs/ext2fs/ext2_readwrite.c @@ -222,7 +222,9 @@ WRITE(ap) if (vp->v_type == VREG && p && uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); return (EFBIG); } diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 0118473017d2..5d9f8bd12833 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -510,8 +510,8 @@ osendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -592,7 +592,9 @@ osendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)fp; @@ -671,8 +673,8 @@ sendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -740,7 +742,9 @@ sendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)sfp; diff --git a/sys/i386/isa/npx.c b/sys/i386/isa/npx.c index 0dab6ae6f66d..87d274b0ec1d 100644 --- a/sys/i386/isa/npx.c +++ b/sys/i386/isa/npx.c @@ -781,7 +781,9 @@ npx_intr(dummy) * * Treat them like a true async interrupt. */ + PROC_LOCK(curproc); psignal(curproc, SIGFPE); + PROC_UNLOCK(curproc); } mtx_unlock(&Giant); } diff --git a/sys/i386/isa/pcvt/pcvt_ext.c b/sys/i386/isa/pcvt/pcvt_ext.c index 50ded4e79cbf..3f0e95452154 100644 --- a/sys/i386/isa/pcvt/pcvt_ext.c +++ b/sys/i386/isa/pcvt/pcvt_ext.c @@ -2294,11 +2294,17 @@ vgapage(int new_screen) /* Try resignaling uncooperative X-window servers */ if (vsp->smode.mode == VT_PROCESS) { if (vsp->vt_status & VT_WAIT_REL) { - if(vsp->smode.relsig) + if(vsp->smode.relsig) { + PROC_LOCK(vsp->proc); psignal(vsp->proc, vsp->smode.relsig); + PROC_UNLOCK(vsp->proc); + } } else if (vsp->vt_status & VT_WAIT_ACK) { - if(vsp->smode.acqsig) + if(vsp->smode.acqsig) { + PROC_LOCK(vsp->proc); psignal(vsp->proc, vsp->smode.acqsig); + PROC_UNLOCK(vsp->proc); + } } } return EAGAIN; @@ -2310,8 +2316,11 @@ vgapage(int new_screen) { /* we cannot switch immediately here */ vsp->vt_status |= VT_WAIT_REL; - if(vsp->smode.relsig) + if(vsp->smode.relsig) { + PROC_LOCK(vsp->proc); psignal(vsp->proc, vsp->smode.relsig); + PROC_UNLOCK(vsp->proc); + } } else { @@ -2341,8 +2350,11 @@ vgapage(int new_screen) { /* if _new_ vt is under process control... */ vsp->vt_status |= VT_WAIT_ACK; - if(vsp->smode.acqsig) + if(vsp->smode.acqsig) { + PROC_LOCK(vsp->proc); psignal(vsp->proc, vsp->smode.acqsig); + PROC_UNLOCK(vsp->proc); + } } else { @@ -2502,9 +2514,12 @@ usl_vt_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) */ vsp->vt_status |= VT_WAIT_ACK; - if(vsp->smode.acqsig) + if(vsp->smode.acqsig) { + PROC_LOCK(vsp->proc); psignal(vsp->proc, vsp->smode.acqsig); + PROC_UNLOCK(vsp->proc); + } } else { diff --git a/sys/i386/isa/spigot.c b/sys/i386/isa/spigot.c index 4c638d55d938..96272df2dc51 100644 --- a/sys/i386/isa/spigot.c +++ b/sys/i386/isa/spigot.c @@ -266,8 +266,11 @@ spigintr(int unit) { struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[unit]; - if(ss->p && ss->signal_num) + if(ss->p && ss->signal_num) { + PROC_LOCK(ss->p); psignal(ss->p, ss->signal_num); + PROC_UNLOCK(ss->p); + } } static int diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index dc20e07b2733..8050392b4353 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -246,13 +246,13 @@ linux_rt_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); #ifdef DEBUG if (ldebug(sigreturn)) printf(LMSG("rt_sendsig: bad stack %p, oonstack=%x"), fp, oonstack); #endif psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -320,6 +320,7 @@ linux_rt_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) * Process has trashed its stack; give it an illegal * instruction to halt it in its tracks. */ + PROC_LOCK(p); sigexit(p, SIGILL); /* NOTREACHED */ } @@ -404,8 +405,8 @@ linux_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -454,6 +455,7 @@ linux_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) * Process has trashed its stack; give it an illegal * instruction to halt it in its tracks. */ + PROC_LOCK(p); sigexit(p, SIGILL); /* NOTREACHED */ } diff --git a/sys/i386/svr4/svr4_machdep.c b/sys/i386/svr4/svr4_machdep.c index 00bb45ac8ccc..1541835afcd4 100644 --- a/sys/i386/svr4/svr4_machdep.c +++ b/sys/i386/svr4/svr4_machdep.c @@ -467,6 +467,7 @@ svr4_sendsig(catcher, sig, mask, code) * Process has trashed its stack; give it an illegal * instruction to halt it in its tracks. */ + PROC_LOCK(p); sigexit(p, SIGILL); /* NOTREACHED */ } diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c index 0b8ccae25e56..08452ca5574d 100644 --- a/sys/ia64/ia64/machdep.c +++ b/sys/ia64/ia64/machdep.c @@ -843,8 +843,8 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index b5a9c416e9f5..a779711d549a 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -411,8 +411,11 @@ dofilewrite(p, fp, fd, buf, nbyte, offset, flags) if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + if (error == EPIPE) { + PROC_LOCK(p); psignal(p, SIGPIPE); + PROC_UNLOCK(p); + } } cnt -= auio.uio_resid; #ifdef KTRACE @@ -504,8 +507,11 @@ writev(p, uap) if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + if (error == EPIPE) { + PROC_LOCK(p); psignal(p, SIGPIPE); + PROC_UNLOCK(p); + } } cnt -= auio.uio_resid; #ifdef KTRACE diff --git a/sys/kern/tty.c b/sys/kern/tty.c index a7ba12dec90e..d57135d90942 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1467,8 +1467,14 @@ ttymodem(tp, flag) !ISSET(tp->t_cflag, CLOCAL)) { SET(tp->t_state, TS_ZOMBIE); CLR(tp->t_state, TS_CONNECTED); - if (tp->t_session && tp->t_session->s_leader) - psignal(tp->t_session->s_leader, SIGHUP); + if (tp->t_session && tp->t_session->s_leader) { + struct proc *p; + + p = tp->t_session->s_leader; + PROC_LOCK(p); + psignal(p, SIGHUP); + PROC_UNLOCK(p); + } ttyflush(tp, FREAD | FWRITE); return (0); } diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 6aed0237ed1e..c46b7eafba50 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -593,8 +593,11 @@ sendit(p, s, mp, flags) if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + if (error == EPIPE) { + PROC_LOCK(p); psignal(p, SIGPIPE); + PROC_UNLOCK(p); + } } if (error == 0) p->p_retval[0] = len - auio.uio_resid; diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index f9d93a5d14f1..c8c2da89de92 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -609,8 +609,11 @@ aio_process(struct aiocblist *aiocbe) if ((error) && (auio.uio_resid != cnt)) { if (error == ERESTART || error == EINTR || error == EWOULDBLOCK) error = 0; - if ((error == EPIPE) && (cb->aio_lio_opcode == LIO_WRITE)) + if ((error == EPIPE) && (cb->aio_lio_opcode == LIO_WRITE)) { + PROC_LOCK(userp); psignal(userp, SIGPIPE); + PROC_UNLOCK(userp); + } } cnt -= auio.uio_resid; @@ -800,10 +803,11 @@ aio_daemon(void *uproc) lj->lioj_queue_count) && (lj->lioj_buffer_finished_count == lj->lioj_buffer_count)) { - psignal(userp, - lj->lioj_signal.sigev_signo); - lj->lioj_flags |= - LIOJ_SIGNAL_POSTED; + PROC_LOCK(userp); + psignal(userp, + lj->lioj_signal.sigev_signo); + PROC_UNLOCK(userp); + lj->lioj_flags |= LIOJ_SIGNAL_POSTED; } } splx(s); @@ -834,7 +838,9 @@ aio_daemon(void *uproc) } if (cb->aio_sigevent.sigev_notify == SIGEV_SIGNAL) { + PROC_LOCK(userp); psignal(userp, cb->aio_sigevent.sigev_signo); + PROC_UNLOCK(userp); } } @@ -1695,8 +1701,11 @@ aio_cancel(struct proc *p, struct aio_cancel_args *uap) cancelled++; /* XXX cancelled, knote? */ if (cbe->uaiocb.aio_sigevent.sigev_notify == - SIGEV_SIGNAL) + SIGEV_SIGNAL) { + PROC_LOCK(cbe->userproc); psignal(cbe->userproc, cbe->uaiocb.aio_sigevent.sigev_signo); + PROC_UNLOCK(cbe->userproc); + } if (uap->aiocbp) break; } @@ -1734,8 +1743,11 @@ aio_cancel(struct proc *p, struct aio_cancel_args *uap) cbe->uaiocb._aiocb_private.error = ECANCELED; /* XXX cancelled, knote? */ if (cbe->uaiocb.aio_sigevent.sigev_notify == - SIGEV_SIGNAL) + SIGEV_SIGNAL) { + PROC_LOCK(cbe->userproc); psignal(cbe->userproc, cbe->uaiocb.aio_sigevent.sigev_signo); + PROC_UNLOCK(cbe->userproc); + } } else { notcancelled++; } @@ -2050,13 +2062,18 @@ process_signal(void *aioj) struct aiocb *cb = &aiocbe->uaiocb; if ((lj) && (lj->lioj_signal.sigev_notify == SIGEV_SIGNAL) && - (lj->lioj_queue_count == lj->lioj_queue_finished_count)) { + (lj->lioj_queue_count == lj->lioj_queue_finished_count)) { + PROC_LOCK(lj->lioj_ki->kaio_p); psignal(lj->lioj_ki->kaio_p, lj->lioj_signal.sigev_signo); + PROC_UNLOCK(lj->lioj_ki->kaio_p); lj->lioj_flags |= LIOJ_SIGNAL_POSTED; } - if (cb->aio_sigevent.sigev_notify == SIGEV_SIGNAL) + if (cb->aio_sigevent.sigev_notify == SIGEV_SIGNAL) { + PROC_LOCK(aiocbe->userproc); psignal(aiocbe->userproc, cb->aio_sigevent.sigev_signo); + PROC_UNLOCK(aiocbe->userproc); + } } /* diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c index fb7b83dba9cf..8ed27a073801 100644 --- a/sys/msdosfs/msdosfs_vnops.c +++ b/sys/msdosfs/msdosfs_vnops.c @@ -654,7 +654,9 @@ msdosfs_write(ap) if (p && ((uoff_t)uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); return (EFBIG); } diff --git a/sys/nfs/nfs_bio.c b/sys/nfs/nfs_bio.c index 09585bff6c00..0c30ca3fd7f4 100644 --- a/sys/nfs/nfs_bio.c +++ b/sys/nfs/nfs_bio.c @@ -823,7 +823,9 @@ nfs_write(ap) */ if (p && uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); if (haverslock) nfs_rsunlock(np, p); return (EFBIG); @@ -1440,8 +1442,10 @@ nfs_doio(bp, cr, p) (!(nmp->nm_flag & NFSMNT_NQNFS) && np->n_mtime != np->n_vattr.va_mtime.tv_sec))) { uprintf("Process killed due to text file modification\n"); + PROC_LOCK(p); psignal(p, SIGKILL); - PHOLD(p); + _PHOLD(p); + PROC_UNLOCK(p); } break; case VLNK: diff --git a/sys/nfsclient/nfs_bio.c b/sys/nfsclient/nfs_bio.c index 09585bff6c00..0c30ca3fd7f4 100644 --- a/sys/nfsclient/nfs_bio.c +++ b/sys/nfsclient/nfs_bio.c @@ -823,7 +823,9 @@ nfs_write(ap) */ if (p && uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); if (haverslock) nfs_rsunlock(np, p); return (EFBIG); @@ -1440,8 +1442,10 @@ nfs_doio(bp, cr, p) (!(nmp->nm_flag & NFSMNT_NQNFS) && np->n_mtime != np->n_vattr.va_mtime.tv_sec))) { uprintf("Process killed due to text file modification\n"); + PROC_LOCK(p); psignal(p, SIGKILL); - PHOLD(p); + _PHOLD(p); + PROC_UNLOCK(p); } break; case VLNK: diff --git a/sys/nwfs/nwfs_io.c b/sys/nwfs/nwfs_io.c index 116b0d9c78fe..f6344e03b311 100644 --- a/sys/nwfs/nwfs_io.c +++ b/sys/nwfs/nwfs_io.c @@ -237,7 +237,9 @@ nwfs_writevnode(vp, uiop, cred, ioflag) } if (uiop->uio_resid == 0) return 0; if (p && uiop->uio_offset + uiop->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); return (EFBIG); } error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred); diff --git a/sys/pc98/i386/machdep.c b/sys/pc98/i386/machdep.c index ab2e2539745f..ffbfd04e3e0d 100644 --- a/sys/pc98/i386/machdep.c +++ b/sys/pc98/i386/machdep.c @@ -523,8 +523,8 @@ osendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -605,7 +605,9 @@ osendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)fp; @@ -684,8 +686,8 @@ sendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -753,7 +755,9 @@ sendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)sfp; diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c index ab2e2539745f..ffbfd04e3e0d 100644 --- a/sys/pc98/pc98/machdep.c +++ b/sys/pc98/pc98/machdep.c @@ -523,8 +523,8 @@ osendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -605,7 +605,9 @@ osendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)fp; @@ -684,8 +686,8 @@ sendsig(catcher, sig, mask, code) SIGDELSET(p->p_sigignore, SIGILL); SIGDELSET(p->p_sigcatch, SIGILL); SIGDELSET(p->p_sigmask, SIGILL); - PROC_UNLOCK(p); psignal(p, SIGILL); + PROC_UNLOCK(p); return; } @@ -753,7 +755,9 @@ sendsig(catcher, sig, mask, code) * Something is wrong with the stack pointer. * ...Kill the process. */ + PROC_LOCK(p); sigexit(p, SIGILL); + /* NOTREACHED */ } regs->tf_esp = (int)sfp; diff --git a/sys/pc98/pc98/npx.c b/sys/pc98/pc98/npx.c index 75176b30dc09..e31e308b4474 100644 --- a/sys/pc98/pc98/npx.c +++ b/sys/pc98/pc98/npx.c @@ -835,7 +835,9 @@ npx_intr(dummy) * * Treat them like a true async interrupt. */ + PROC_LOCK(p); psignal(curproc, SIGFPE); + PROC_UNLOCK(p); } mtx_unlock(&Giant); } diff --git a/sys/pc98/pc98/syscons.c b/sys/pc98/pc98/syscons.c index adb0e7cf3670..b157f4a62852 100644 --- a/sys/pc98/pc98/syscons.c +++ b/sys/pc98/pc98/syscons.c @@ -2314,7 +2314,9 @@ signal_vt_rel(scr_stat *scp) if (scp->smode.mode != VT_PROCESS) return FALSE; scp->status |= SWITCH_WAIT_REL; + PROC_LOCK(scp->proc); psignal(scp->proc, scp->smode.relsig); + PROC_UNLOCK(scp->proc); DPRINTF(5, ("sending relsig to %d\n", scp->pid)); return TRUE; } @@ -2327,7 +2329,9 @@ signal_vt_acq(scr_stat *scp) if (scp->sc->unit == sc_console_unit) cons_unavail = TRUE; scp->status |= SWITCH_WAIT_ACQ; + PROC_LOCK(scp->proc); psignal(scp->proc, scp->smode.acqsig); + PROC_UNLOCK(scp->proc); DPRINTF(5, ("sending acqsig to %d\n", scp->pid)); return TRUE; } diff --git a/sys/pci/meteor.c b/sys/pci/meteor.c index d9fe31a0b5c7..088ca7c79f71 100644 --- a/sys/pci/meteor.c +++ b/sys/pci/meteor.c @@ -649,8 +649,11 @@ meteor_intr(void *arg) * If the user requested to be notified via signal, * let them know the field is complete. */ - if(mtr->proc && (mtr->signal & METEOR_SIG_MODE_MASK)) + if(mtr->proc && (mtr->signal & METEOR_SIG_MODE_MASK)) { + PROC_LOCK(mtr->proc); psignal(mtr->proc, mtr->signal&(~METEOR_SIG_MODE_MASK)); + PROC_UNLOCK(mtr->proc); + } } if (status & 0x2) { /* odd field */ mtr->odd_fields_captured++; @@ -663,8 +666,11 @@ meteor_intr(void *arg) * If the user requested to be notified via signal, * let them know the field is complete. */ - if(mtr->proc && (mtr->signal & METEOR_SIG_MODE_MASK)) + if(mtr->proc && (mtr->signal & METEOR_SIG_MODE_MASK)) { + PROC_LOCK(mtr->proc); psignal(mtr->proc, mtr->signal&(~METEOR_SIG_MODE_MASK)); + PROC_UNLOCK(mtr->proc); + } } /* @@ -696,8 +702,11 @@ meteor_intr(void *arg) * If the user requested to be notified via signal, * let them know the frame is complete. */ - if(mtr->proc && !(mtr->signal & METEOR_SIG_MODE_MASK)) + if(mtr->proc && !(mtr->signal & METEOR_SIG_MODE_MASK)) { + PROC_LOCK(mtr->proc); psignal(mtr->proc, mtr->signal&(~METEOR_SIG_MODE_MASK)); + PROC_UNLOCK(mtr->proc); + } /* * Reset the want flags if in continuous or * synchronous capture mode. diff --git a/sys/ufs/ufs/ufs_readwrite.c b/sys/ufs/ufs/ufs_readwrite.c index 62ec9e309b40..27e1d69ab4da 100644 --- a/sys/ufs/ufs/ufs_readwrite.c +++ b/sys/ufs/ufs/ufs_readwrite.c @@ -440,7 +440,9 @@ WRITE(ap) if (vp->v_type == VREG && p && uio->uio_offset + uio->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) { + PROC_LOCK(p); psignal(p, SIGXFSZ); + PROC_UNLOCK(p); if (object) vm_object_vndeallocate(object); return (EFBIG);