From f1a69ab3eae0e399491598237587ae2be7980078 Mon Sep 17 00:00:00 2001 From: elad Date: Tue, 19 Dec 2006 09:58:34 +0000 Subject: [PATCH] Some changes to get rid of another KAUTH_GENERIC_ISSUSER usage: - Make procfs_control() in procfs_ctl.c static, - Add an argument to the above, 'pfs', for the pfsnode, - Add another request type to KAUTH_PROCESS_CANPROCFS named KAUTH_REQ_PROCESS_CANPROCFS_CTL (and update documentation), - Use the above combination in a call to kauth_authorize_process(). --- share/man/man9/kauth.9 | 6 ++++-- sys/miscfs/procfs/procfs_ctl.c | 24 ++++++++++++------------ sys/sys/kauth.h | 5 +++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/share/man/man9/kauth.9 b/share/man/man9/kauth.9 index 1ad65efe5e9d..cf7855235a41 100644 --- a/share/man/man9/kauth.9 +++ b/share/man/man9/kauth.9 @@ -1,4 +1,4 @@ -.\" $NetBSD: kauth.9,v 1.38 2006/12/14 11:45:08 elad Exp $ +.\" $NetBSD: kauth.9,v 1.39 2006/12/19 09:58:34 elad Exp $ .\" .\" Copyright (c) 2005, 2006 Elad Efrat .\" All rights reserved. @@ -28,7 +28,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 14, 2006 +.Dd December 19, 2006 .Dt KAUTH 9 .Os .Sh NAME @@ -279,11 +279,13 @@ is the for the target element in the target process, and .Ar arg2 is the access type, which can be either +.Dq KAUTH_REQ_PROCESS_CANPROCFS_CTL , .Dq KAUTH_REQ_PROCESS_CANPROCFS_READ , .Dq KAUTH_REQ_PROCESS_CANPROCFS_RW , or .Dq KAUTH_REQ_PROCESS_CANPROCFS_WRITE , indicating +.Em control , .Em read , .Em read-write , or diff --git a/sys/miscfs/procfs/procfs_ctl.c b/sys/miscfs/procfs/procfs_ctl.c index 3e30e0badfd1..5cd13b68b8d6 100644 --- a/sys/miscfs/procfs/procfs_ctl.c +++ b/sys/miscfs/procfs/procfs_ctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_ctl.c,v 1.37 2006/11/22 15:48:11 elad Exp $ */ +/* $NetBSD: procfs_ctl.c,v 1.38 2006/12/19 09:58:35 elad Exp $ */ /* * Copyright (c) 1993 @@ -72,7 +72,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: procfs_ctl.c,v 1.37 2006/11/22 15:48:11 elad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_ctl.c,v 1.38 2006/12/19 09:58:35 elad Exp $"); #include #include @@ -126,13 +126,15 @@ static const vfs_namemap_t signames[] = { { NULL, 0 }, }; -int procfs_control(struct lwp *, struct lwp *, int, int); +static int procfs_control(struct lwp *, struct lwp *, int, int, + struct pfsnode *); int -procfs_control(curl, l, op, sig) +procfs_control(curl, l, op, sig, pfs) struct lwp *curl; struct lwp *l; int op, sig; + struct pfsnode *pfs; { struct proc *curp = curl->l_proc; struct proc *p = l->l_proc; @@ -164,13 +166,11 @@ procfs_control(curl, l, op, sig) return (EBUSY); /* - * (3) it's not owned by you, or is set-id on exec - * (unless you're root), or... + * (3) the security model prevents it. */ - if ((kauth_cred_getuid(p->p_cred) != kauth_cred_getuid(curl->l_cred) || - ISSET(p->p_flag, P_SUGID)) && - (error = kauth_authorize_generic(curl->l_cred, KAUTH_GENERIC_ISSUSER, - &curl->l_acflag)) != 0) + if ((error = kauth_authorize_process(curl->l_cred, + KAUTH_PROCESS_CANPROCFS, p, pfs, + KAUTH_ARG(KAUTH_REQ_PROCESS_CANPROCFS_CTL), NULL)) != 0) return (error); break; @@ -349,14 +349,14 @@ procfs_doctl( nm = vfs_findname(ctlnames, msg, xlen); if (nm) { - error = procfs_control(curl, l, nm->nm_val, 0); + error = procfs_control(curl, l, nm->nm_val, 0, pfs); } else { nm = vfs_findname(signames, msg, xlen); if (nm) { if (ISSET(p->p_flag, P_TRACED) && p->p_pptr == p) error = procfs_control(curl, l, PROCFS_CTL_RUN, - nm->nm_val); + nm->nm_val, pfs); else { psignal(p, nm->nm_val); error = 0; diff --git a/sys/sys/kauth.h b/sys/sys/kauth.h index aca51e5d9956..c5685ac91f68 100644 --- a/sys/sys/kauth.h +++ b/sys/sys/kauth.h @@ -1,4 +1,4 @@ -/* $NetBSD: kauth.h,v 1.26 2006/12/14 18:27:59 elad Exp $ */ +/* $NetBSD: kauth.h,v 1.27 2006/12/19 09:58:35 elad Exp $ */ /*- * Copyright (c) 2005, 2006 Elad Efrat @@ -132,7 +132,8 @@ enum { * Process scope - sub-actions. */ enum kauth_process_req { - KAUTH_REQ_PROCESS_CANPROCFS_READ=1, + KAUTH_REQ_PROCESS_CANPROCFS_CTL=1, + KAUTH_REQ_PROCESS_CANPROCFS_READ, KAUTH_REQ_PROCESS_CANPROCFS_RW, KAUTH_REQ_PROCESS_CANPROCFS_WRITE, KAUTH_REQ_PROCESS_RESOURCE_NICE,