Proc locking.

This commit is contained in:
jhb 2001-01-23 21:33:55 +00:00
parent 9a868ba306
commit 2baf61c869
5 changed files with 63 additions and 17 deletions

View File

@ -101,6 +101,8 @@ exec_svr4_imgact(imgp)
/* text + data can't exceed file size */
if (a_out->a_data + a_out->a_text > imgp->attr->va_size)
return (EFAULT);
/* For p_rlimit below. */
mtx_assert(&Giant, MA_OWNED);
/*
* text/data/bss must not exceed limits
*/

View File

@ -249,6 +249,7 @@ fd_revoke(p, fd)
struct vnode *vp;
struct mount *mp;
struct vattr vattr;
struct ucred *uc;
int error, *retval;
retval = p->p_retval;
@ -265,12 +266,20 @@ fd_revoke(p, fd)
goto out;
}
if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0)
PROC_LOCK(p);
uc = p->p_ucred;
crhold(uc);
PROC_UNLOCK(p);
if ((error = VOP_GETATTR(vp, &vattr, uc, p)) != 0) {
crfree(uc);
goto out;
}
if (p->p_ucred->cr_uid != vattr.va_uid &&
(error = suser(p)) != 0)
if (uc->cr_uid != vattr.va_uid && (error = suser(p)) != 0) {
crfree(uc);
goto out;
}
crfree(uc);
if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
goto out;
@ -294,6 +303,7 @@ fd_truncate(p, fd, flp)
off_t start, length;
struct vnode *vp;
struct vattr vattr;
struct ucred *uc;
int error, *retval;
struct ftruncate_args ft;
@ -309,7 +319,13 @@ fd_truncate(p, fd, flp)
if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO)
return ESPIPE;
if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0)
PROC_LOCK(p);
uc = p->p_ucred;
crhold(uc);
PROC_UNLOCK(p);
error = VOP_GETATTR(vp, &vattr, uc, p);
crfree(uc);
if (error != 0)
return error;
length = vattr.va_size;
@ -366,17 +382,23 @@ svr4_sys_open(p, uap)
retval = p->p_retval[0];
PROC_LOCK(p);
if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
!(p->p_flag & P_CONTROLT)) {
#if defined(NOTYET)
struct filedesc *fdp = p->p_fd;
struct file *fp = fdp->fd_ofiles[retval];
PROC_UNLOCK(p);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, p);
#endif
} else
PROC_UNLOCK(p);
#else
}
PROC_UNLOCK(p);
#endif
return error;
}
@ -414,20 +436,19 @@ svr4_sys_creat64(p, uap)
}
int
svr4_sys_llseek(p, v)
svr4_sys_llseek(p, uap)
register struct proc *p;
struct svr4_sys_llseek_args *v;
struct svr4_sys_llseek_args *uap;
{
struct svr4_sys_llseek_args *uap = v;
struct lseek_args ap;
SCARG(&ap, fd) = SCARG(uap, fd);
#if BYTE_ORDER == BIG_ENDIAN
SCARG(&ap, offset) = (((long long) SCARG(uap, offset1)) << 32) |
SCARG(&ap, offset) = (((u_int64_t) SCARG(uap, offset1)) << 32) |
SCARG(uap, offset2);
#else
SCARG(&ap, offset) = (((long long) SCARG(uap, offset2)) << 32) |
SCARG(&ap, offset) = (((u_int64_t) SCARG(uap, offset2)) << 32) |
SCARG(uap, offset1);
#endif
SCARG(&ap, whence) = SCARG(uap, whence);

View File

@ -138,6 +138,8 @@ svr4_sys_getrlimit(p, uap)
if (rl == -1)
return EINVAL;
/* For p_rlimit. */
mtx_assert(&Giant, MA_OWNED);
blim = p->p_rlimit[rl];
/*
@ -184,6 +186,8 @@ svr4_sys_setrlimit(p, uap)
if (rl == -1)
return EINVAL;
/* For p_rlimit. */
mtx_assert(&Giant, MA_OWNED);
limp = &p->p_rlimit[rl];
if ((error = copyin(SCARG(uap, rlp), &slim, sizeof(slim))) != 0)
@ -232,6 +236,8 @@ svr4_sys_getrlimit64(p, uap)
if (rl == -1)
return EINVAL;
/* For p_rlimit. */
mtx_assert(&Giant, MA_OWNED);
blim = p->p_rlimit[rl];
/*
@ -278,6 +284,8 @@ svr4_sys_setrlimit64(p, uap)
if (rl == -1)
return EINVAL;
/* For p_rlimit. */
mtx_assert(&Giant, MA_OWNED);
limp = &p->p_rlimit[rl];
if ((error = copyin(SCARG(uap, rlp), &slim, sizeof(slim))) != 0)

View File

@ -480,7 +480,9 @@ svr4_sys_signal(p, uap)
sigset_t *set;
set = stackgap_alloc(&sg, sizeof(sigset_t));
PROC_LOCK(p);
*set = p->p_sigmask;
PROC_UNLOCK(p);
SIGDELSET(*set, signum);
SCARG(&sa, sigmask) = set;
return sigsuspend(p, &sa);
@ -504,7 +506,9 @@ svr4_sys_sigprocmask(p, uap)
retval = p->p_retval;
if (SCARG(uap, oset) != NULL) {
/* Fix the return value first if needed */
PROC_LOCK(p);
bsd_to_svr4_sigset(&p->p_sigmask, &sss);
PROC_UNLOCK(p);
if ((error = copyout(&sss, SCARG(uap, oset), sizeof(sss))) != 0)
return error;
}
@ -518,8 +522,7 @@ svr4_sys_sigprocmask(p, uap)
svr4_to_bsd_sigset(&sss, &bss);
(void) splhigh();
PROC_LOCK(p);
switch (SCARG(uap, how)) {
case SVR4_SIG_BLOCK:
SIGSETOR(p->p_sigmask, bss);
@ -539,8 +542,7 @@ svr4_sys_sigprocmask(p, uap)
error = EINVAL;
break;
}
(void) spl0();
PROC_UNLOCK(p);
return error;
}
@ -560,8 +562,10 @@ svr4_sys_sigpending(p, uap)
case 1: /* sigpending */
if (SCARG(uap, mask) == NULL)
return 0;
PROC_LOCK(p);
bss = p->p_siglist;
SIGSETAND(bss, p->p_sigmask);
PROC_UNLOCK(p);
bsd_to_svr4_sigset(&bss, &sss);
break;
@ -628,9 +632,11 @@ svr4_sys_context(p, uap)
switch (uap->func) {
case 0:
PROC_LOCK(p);
DPRINTF(("getcontext(%p)\n", uap->uc));
svr4_getcontext(p, &uc, &p->p_sigmask,
sigonstack(cpu_getstack(p)));
PROC_UNLOCK(p);
return copyout(&uc, uap->uc, sizeof(uc));
case 1:

View File

@ -212,10 +212,12 @@ svr4_fixup(register_t **stack_base, struct image_params *imgp)
AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
AUXARGS_ENTRY(pos, AT_BASE, args->base);
PROC_LOCK(imgp->proc);
AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_cred->p_ruid);
AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_cred->p_svuid);
AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_cred->p_rgid);
AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_cred->p_svgid);
PROC_UNLOCK(imgp->proc);
AUXARGS_ENTRY(pos, AT_NULL, 0);
free(imgp->auxargs, M_TEMP);
@ -249,6 +251,7 @@ svr4_emul_find(p, sgp, prefix, path, pbuf, cflag)
struct nameidata ndroot;
struct vattr vat;
struct vattr vatroot;
struct ucred *uc;
int error;
char *ptr, *buf, *cp;
size_t sz, len;
@ -329,14 +332,20 @@ svr4_emul_find(p, sgp, prefix, path, pbuf, cflag)
}
NDFREE(&ndroot, NDF_ONLY_PNBUF);
if ((error = VOP_GETATTR(nd.ni_vp, &vat, p->p_ucred, p)) != 0) {
PROC_LOCK(p);
uc = p->p_ucred;
crhold(uc);
PROC_UNLOCK(p);
if ((error = VOP_GETATTR(nd.ni_vp, &vat, uc, p)) != 0) {
crfree(uc);
goto done;
}
if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, p->p_ucred, p))
!= 0) {
if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, uc, p)) != 0) {
crfree(uc);
goto done;
}
crfree(uc);
if (vat.va_fsid == vatroot.va_fsid &&
vat.va_fileid == vatroot.va_fileid) {