From 999e9cef64de4d4088717f5afabdf9538f55660f Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 14 May 2004 16:35:24 +0000 Subject: Simplify the code by: 1. Checking for a negative uio_offset at the beginning. This really does not affect us in most cases because we check that later too. 2. Checking for attempts to write to init sooner and in all cases. --- sys/miscfs/procfs/procfs_subr.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/sys/miscfs/procfs/procfs_subr.c b/sys/miscfs/procfs/procfs_subr.c index 9a874d5b9e8..49dd6c1a817 100644 --- a/sys/miscfs/procfs/procfs_subr.c +++ b/sys/miscfs/procfs/procfs_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_subr.c,v 1.58 2003/09/27 13:29:02 darcy Exp $ */ +/* $NetBSD: procfs_subr.c,v 1.59 2004/05/14 16:35:24 christos Exp $ */ /* * Copyright (c) 1993 @@ -73,7 +73,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.58 2003/09/27 13:29:02 darcy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.59 2004/05/14 16:35:24 christos Exp $"); #include #include @@ -299,9 +299,17 @@ procfs_rw(v) struct lwp *l; struct proc *p; + if (uio->uio_offset < 0) + return EINVAL; p = PFIND(pfs->pfs_pid); if (p == 0) - return (EINVAL); + return ESRCH; + /* + * Do not allow init to be modified while in secure mode; it + * could be duped into changing the security level. + */ + if (uio->uio_rw == UIO_WRITE && p == initproc && securelevel > -1) + return EPERM; /* XXX NJWLWP * The entire procfs interface needs work to be useful to @@ -310,26 +318,6 @@ procfs_rw(v) */ l = proc_representative_lwp(p); - switch (pfs->pfs_type) { - case PFSregs: - case PFSfpregs: - case PFSmem: -#if defined(__HAVE_PROCFS_MACHDEP) && defined(PROCFS_MACHDEP_PROTECT_CASES) - PROCFS_MACHDEP_PROTECT_CASES -#endif - /* - * Do not allow init to be modified while in secure mode; it - * could be duped into changing the security level. - */ - if (uio->uio_rw == UIO_WRITE && - p == initproc && securelevel > -1) - return (EPERM); - break; - - default: - break; - } - switch (pfs->pfs_type) { case PFSnote: case PFSnotepg: -- cgit