Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/miscfs/procfs If the procfs mount is marked as linux-com...



details:   https://anonhg.NetBSD.org/src/rev/da79db568ff5
branches:  trunk
changeset: 971592:da79db568ff5
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Apr 29 01:56:54 2020 +0000

description:
If the procfs mount is marked as linux-compat, then allow proc lookup
by any LWP ID in the proc, not just the canonical PID.

diffstat:

 sys/miscfs/procfs/procfs.h        |   6 ++-
 sys/miscfs/procfs/procfs_subr.c   |  28 ++++++++++++++++---
 sys/miscfs/procfs/procfs_vfsops.c |   6 ++--
 sys/miscfs/procfs/procfs_vnops.c  |  56 ++++++++++++++++++++++----------------
 4 files changed, 63 insertions(+), 33 deletions(-)

diffs (296 lines):

diff -r c25a5f77ca84 -r da79db568ff5 sys/miscfs/procfs/procfs.h
--- a/sys/miscfs/procfs/procfs.h        Wed Apr 29 01:55:52 2020 +0000
+++ b/sys/miscfs/procfs/procfs.h        Wed Apr 29 01:56:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs.h,v 1.78 2020/01/17 20:08:09 ad Exp $   */
+/*     $NetBSD: procfs.h,v 1.79 2020/04/29 01:56:54 thorpej Exp $      */
 
 /*
  * Copyright (c) 1993
@@ -209,7 +209,9 @@
 int vfs_getuserstr(struct uio *, char *, int *);
 const vfs_namemap_t *vfs_findname(const vfs_namemap_t *, const char *, int);
 
-int procfs_proc_lock(int, struct proc **, int);
+struct proc *procfs_proc_find(struct mount *, pid_t);
+bool procfs_use_linux_compat(struct mount *);
+int procfs_proc_lock(struct mount *, int, struct proc **, int);
 void procfs_proc_unlock(struct proc *);
 struct mount;
 int procfs_allocvp(struct mount *, struct vnode **, pid_t, pfstype, int);
diff -r c25a5f77ca84 -r da79db568ff5 sys/miscfs/procfs/procfs_subr.c
--- a/sys/miscfs/procfs/procfs_subr.c   Wed Apr 29 01:55:52 2020 +0000
+++ b/sys/miscfs/procfs/procfs_subr.c   Wed Apr 29 01:56:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_subr.c,v 1.114 2019/09/26 17:34:08 christos Exp $       */
+/*     $NetBSD: procfs_subr.c,v 1.115 2020/04/29 01:56:54 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.114 2019/09/26 17:34:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.115 2020/04/29 01:56:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -152,7 +152,8 @@
        if (uio->uio_offset < 0)
                return EINVAL;
 
-       if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ESRCH)) != 0)
+       if ((error =
+            procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &p, ESRCH)) != 0)
                return error;
 
        curl = curlwp;
@@ -408,8 +409,25 @@
        vfs_vnode_iterator_destroy(marker);
 }
 
+bool
+procfs_use_linux_compat(struct mount *mp)
+{
+       const int flags = VFSTOPROC(mp)->pmnt_flags;
+
+       return (flags & PROCFSMNT_LINUXCOMPAT) ? true : false;
+}
+
+struct proc *
+procfs_proc_find(struct mount *mp, pid_t pid)
+{
+       KASSERT(mutex_owned(proc_lock));
+       return procfs_use_linux_compat(mp) ? proc_find_lwpid(pid)
+                                          : proc_find(pid);
+}
+
 int
-procfs_proc_lock(int pid, struct proc **bunghole, int notfound)
+procfs_proc_lock(struct mount *mp, int pid, struct proc **bunghole,
+                int notfound)
 {
        struct proc *tp;
        int error = 0;
@@ -418,7 +436,7 @@
 
        if (pid == 0)
                tp = &proc0;
-       else if ((tp = proc_find(pid)) == NULL)
+       else if ((tp = procfs_proc_find(mp, pid)) == NULL)
                error = notfound;
        if (tp != NULL && !rw_tryenter(&tp->p_reflock, RW_READER))
                error = EBUSY;
diff -r c25a5f77ca84 -r da79db568ff5 sys/miscfs/procfs/procfs_vfsops.c
--- a/sys/miscfs/procfs/procfs_vfsops.c Wed Apr 29 01:55:52 2020 +0000
+++ b/sys/miscfs/procfs/procfs_vfsops.c Wed Apr 29 01:56:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vfsops.c,v 1.107 2020/04/20 05:22:28 htodd Exp $        */
+/*     $NetBSD: procfs_vfsops.c,v 1.108 2020/04/29 01:56:54 thorpej Exp $      */
 
 /*
  * Copyright (c) 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.107 2020/04/20 05:22:28 htodd Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.108 2020/04/29 01:56:54 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -322,7 +322,7 @@
                        struct proc *p;
 
                        mutex_enter(proc_lock);
-                       p = proc_find(pfs->pfs_pid);
+                       p = procfs_proc_find(mp, pfs->pfs_pid);
                        mutex_exit(proc_lock);
                        if (p == NULL) {
                                error = ENOENT;
diff -r c25a5f77ca84 -r da79db568ff5 sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c  Wed Apr 29 01:55:52 2020 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c  Wed Apr 29 01:56:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vnops.c,v 1.211 2020/04/21 21:42:47 ad Exp $    */
+/*     $NetBSD: procfs_vnops.c,v 1.212 2020/04/29 01:56:54 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.211 2020/04/21 21:42:47 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.212 2020/04/29 01:56:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -318,12 +318,14 @@
                int  a_mode;
                kauth_cred_t a_cred;
        } */ *ap = v;
-       struct pfsnode *pfs = VTOPFS(ap->a_vp);
+       struct vnode *vp = ap->a_vp;
+       struct pfsnode *pfs = VTOPFS(vp);
        struct lwp *l1;
        struct proc *p2;
        int error;
 
-       if ((error = procfs_proc_lock(pfs->pfs_pid, &p2, ENOENT)) != 0)
+       if ((error =
+            procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &p2, ENOENT)) != 0)
                return error;
 
        l1 = curlwp;                            /* tracer */
@@ -428,7 +430,7 @@
        struct pfsnode *pfs = VTOPFS(vp);
 
        mutex_enter(proc_lock);
-       *ap->a_recycle = (proc_find(pfs->pfs_pid) == NULL);
+       *ap->a_recycle = (procfs_proc_find(vp->v_mount, pfs->pfs_pid) == NULL);
        mutex_exit(proc_lock);
 
        return (0);
@@ -638,7 +640,8 @@
                struct vattr *a_vap;
                kauth_cred_t a_cred;
        } */ *ap = v;
-       struct pfsnode *pfs = VTOPFS(ap->a_vp);
+       struct vnode *vp = ap->a_vp;
+       struct pfsnode *pfs = VTOPFS(vp);
        struct vattr *vap = ap->a_vap;
        struct proc *procp;
        char *path, *bp, bf[16];
@@ -653,7 +656,8 @@
                break;
 
        default:
-               error = procfs_proc_lock(pfs->pfs_pid, &procp, ENOENT);
+               error =
+                   procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &procp, ENOENT);
                if (error != 0)
                        return (error);
                break;
@@ -1074,7 +1078,7 @@
                        type = PFSproc;
                }
 
-               if (procfs_proc_lock(pid, &p, ESRCH) != 0)
+               if (procfs_proc_lock(dvp->v_mount, pid, &p, ESRCH) != 0)
                        break;
                error = procfs_allocvp(dvp->v_mount, vpp, vnpid, type, -1);
                procfs_proc_unlock(p);
@@ -1087,7 +1091,8 @@
                        return (error);
                }
 
-               if (procfs_proc_lock(pfs->pfs_pid, &p, ESRCH) != 0)
+               if (procfs_proc_lock(dvp->v_mount, pfs->pfs_pid, &p,
+                                    ESRCH) != 0)
                        break;
 
                mutex_enter(p->p_lock);
@@ -1139,7 +1144,8 @@
                int fd;
                file_t *fp;
 
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ENOENT)) != 0)
+               if ((error = procfs_proc_lock(dvp->v_mount, pfs->pfs_pid, &p,
+                                             ENOENT)) != 0)
                        return error;
 
                if (cnp->cn_flags & ISDOTDOT) {
@@ -1175,7 +1181,8 @@
        case PFStask: {
                int xpid;
 
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ENOENT)) != 0)
+               if ((error = procfs_proc_lock(dvp->v_mount, pfs->pfs_pid, &p,
+                                             ENOENT)) != 0)
                        return error;
 
                if (cnp->cn_flags & ISDOTDOT) {
@@ -1211,10 +1218,7 @@
 static int
 procfs_validfile_linux(struct lwp *l, struct mount *mp)
 {
-       int flags;
-
-       flags = VFSTOPROC(mp)->pmnt_flags;
-       return (flags & PROCFSMNT_LINUXCOMPAT) &&
+       return procfs_use_linux_compat(mp) &&
            (l == NULL || l->l_proc == NULL || procfs_validfile(l, mp));
 }
 
@@ -1334,7 +1338,7 @@
                if (i >= nproc_targets)
                        return 0;
 
-               if (procfs_proc_lock(pfs->pfs_pid, &p, ESRCH) != 0)
+               if (procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &p, ESRCH) != 0)
                        break;
 
                if (ap->a_ncookies) {
@@ -1376,7 +1380,8 @@
                file_t *fp;
                int lim, nc = 0;
 
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ESRCH)) != 0)
+               if ((error = procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &p,
+                                             ESRCH)) != 0)
                        return error;
 
                /* XXX Should this be by file as well? */
@@ -1444,7 +1449,8 @@
                struct proc *p;
                int nc = 0;
 
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ESRCH)) != 0)
+               if ((error = procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &p,
+                                             ESRCH)) != 0)
                        return error;
 
                nfd = 3;        /* ., .., pid */
@@ -1617,7 +1623,8 @@
        char *path = NULL;
        int len = 0;
        int error = 0;
-       struct pfsnode *pfs = VTOPFS(ap->a_vp);
+       struct vnode *vp = ap->a_vp;
+       struct pfsnode *pfs = VTOPFS(vp);
        struct proc *pown = NULL;
 
        if (pfs->pfs_fileno == PROCFS_FILENO(0, PFScurproc, -1))
@@ -1627,13 +1634,15 @@
        else if (pfs->pfs_fileno == PROCFS_FILENO(pfs->pfs_pid, PFStask, 0))
                len = snprintf(bf, sizeof(bf), "..");
        else if (pfs->pfs_fileno == PROCFS_FILENO(pfs->pfs_pid, PFSexe, -1)) {
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &pown, ESRCH)) != 0)
+               if ((error = procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &pown,
+                                             ESRCH)) != 0)
                        return error;
                bp = pown->p_path;
                len = strlen(bp);
        } else if (pfs->pfs_fileno == PROCFS_FILENO(pfs->pfs_pid, PFScwd, -1) ||
            pfs->pfs_fileno == PROCFS_FILENO(pfs->pfs_pid, PFSchroot, -1)) {
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &pown, ESRCH)) != 0)
+               if ((error = procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &pown,
+                                             ESRCH)) != 0)
                        return error;
                path = malloc(MAXPATHLEN + 4, M_TEMP, M_WAITOK);
                if (path == NULL) {
@@ -1647,9 +1656,10 @@
                len = strlen(bp);
        } else {
                file_t *fp;
-               struct vnode *vxp, *vp;
+               struct vnode *vxp;
 
-               if ((error = procfs_proc_lock(pfs->pfs_pid, &pown, ESRCH)) != 0)
+               if ((error = procfs_proc_lock(vp->v_mount, pfs->pfs_pid, &pown,
+                                             ESRCH)) != 0)
                        return error;
 
                fp = fd_getfile2(pown, pfs->pfs_fd);



Home | Main Index | Thread Index | Old Index