Source-Changes-HG archive

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

[src/trunk]: src/sys Kernel portion of the multiple ptyfs mount support. Prot...



details:   https://anonhg.NetBSD.org/src/rev/848c28ab9a2e
branches:  trunk
changeset: 795240:848c28ab9a2e
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Apr 04 18:11:58 2014 +0000

description:
Kernel portion of the multiple ptyfs mount support. Protocol changed
between kernel and module, so bump. (Ilya Zykov)

diffstat:

 sys/kern/tty_bsdpty.c |  15 ++++++++++++---
 sys/kern/tty_ptm.c    |  49 +++++++++++++++++++++++--------------------------
 sys/kern/tty_pty.c    |   8 ++++----
 sys/sys/param.h       |   4 ++--
 sys/sys/pty.h         |   6 +++---
 5 files changed, 44 insertions(+), 38 deletions(-)

diffs (222 lines):

diff -r ae385f6afaad -r 848c28ab9a2e sys/kern/tty_bsdpty.c
--- a/sys/kern/tty_bsdpty.c     Fri Apr 04 18:10:29 2014 +0000
+++ b/sys/kern/tty_bsdpty.c     Fri Apr 04 18:11:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty_bsdpty.c,v 1.19 2014/03/27 17:31:56 christos Exp $ */
+/*     $NetBSD: tty_bsdpty.c,v 1.20 2014/04/04 18:11:58 christos Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.19 2014/03/27 17:31:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.20 2014/04/04 18:11:58 christos Exp $");
 
 #include "opt_ptm.h"
 
@@ -74,12 +74,13 @@
 static int pty_allocvp(struct mount *, struct lwp *, struct vnode **,
     dev_t, char);
 static void pty_getvattr(struct mount *, struct lwp *, struct vattr *);
+static int pty__getmp(struct lwp *, struct mount **);
 
 struct ptm_pty ptm_bsdpty = {
        pty_allocvp,
        pty_makename,
        pty_getvattr,
-       NULL
+       pty__getmp,
 };
 
 static int
@@ -152,5 +153,13 @@
        vattr->va_gid = TTY_GID;
        vattr->va_mode = TTY_PERM;
 }
+
+static int
+pty__getmp(struct lwp *l __unused, struct mount **mpp)
+{
+       *mpp = 0;
+       return 0;
+}
+
 #endif /* COMPAT_BSDPTY */
 #endif /* NO_DEV_PTM */
diff -r ae385f6afaad -r 848c28ab9a2e sys/kern/tty_ptm.c
--- a/sys/kern/tty_ptm.c        Fri Apr 04 18:10:29 2014 +0000
+++ b/sys/kern/tty_ptm.c        Fri Apr 04 18:11:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty_ptm.c,v 1.31 2014/03/27 17:31:56 christos Exp $    */
+/*     $NetBSD: tty_ptm.c,v 1.32 2014/04/04 18:11:58 christos Exp $    */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.31 2014/03/27 17:31:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.32 2014/04/04 18:11:58 christos Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ptm.h"
@@ -90,31 +90,12 @@
 void ptmattach(int);
 
 int
-ptyfs_getmp(struct lwp *l, struct mount **mpp) {
-       struct cwdinfo *cwdi = l->l_proc->p_cwdi;
-       struct mount *mp;
-
+pty_getmp(struct lwp *l, struct mount **mpp)
+{
        if (ptm == NULL)
                return EOPNOTSUPP;
 
-       if (ptm->arg == NULL) { /* BSDPTY */
-               *mpp = NULL;
-               return 0;
-       }
-
-       mp = ptm->arg;  /* PTYFS */
-
-       if (cwdi->cwdi_rdir == NULL)
-               goto ok;
-
-       if (vn_isunder(mp->mnt_vnodecovered, cwdi->cwdi_rdir, l))
-               goto ok;
-
-       *mpp = NULL;
-       return EOPNOTSUPP;
-ok:
-       *mpp = mp;
-       return 0;
+       return (*ptm->getmp)(l, mpp);
 }
 
 dev_t
@@ -192,6 +173,22 @@
                error = EOPNOTSUPP;
                goto bad;
        }
+       /*
+        * XXX Since PTYFS has now multiple instance support, if we mounted
+        * more than one PTYFS we must check here the ptyfs_used_tbl, to find
+        * out if the ptyfsnode is under the appropriate mount and skip the
+        * node if not, because the pty could has been released, but
+        * ptyfs_reclaim didn't get a chance to release the corresponding
+        * node other mount point yet.
+        *
+        * It's important to have only one mount point's ptyfsnode for each
+        * appropriate device in ptyfs_used_tbl, else we will have a security 
+        * problem, because every entry will have access to this device.
+        *
+        * Also we will not have not efficient vnode and memory usage.
+        * You can test this by changing a_recycle from true to false
+        * in ptyfs_inactive.
+        */
        if ((error = (*ptm->allocvp)(mp, l, &vp, *dev, 'p')) != 0) {
                DPRINTF(("pty_allocvp %d\n", error));
                goto bad;
@@ -355,7 +352,7 @@
        switch(minor(dev)) {
        case 0:         /* /dev/ptmx */
        case 2:         /* /emul/linux/dev/ptmx */
-               if ((error = ptyfs_getmp(l, &mp)) != 0)
+               if ((error = pty_getmp(l, &mp)) != 0)
                        return error;
                if ((error = pty_alloc_master(l, &fd, &ttydev, mp)) != 0)
                        return error;
@@ -403,7 +400,7 @@
        error = 0;
        switch (cmd) {
        case TIOCPTMGET:
-               if ((error = ptyfs_getmp(l, &mp)) != 0)
+               if ((error = pty_getmp(l, &mp)) != 0)
                        return error;
 
                if ((error = pty_alloc_master(l, &cfd, &newdev, mp)) != 0)
diff -r ae385f6afaad -r 848c28ab9a2e sys/kern/tty_pty.c
--- a/sys/kern/tty_pty.c        Fri Apr 04 18:10:29 2014 +0000
+++ b/sys/kern/tty_pty.c        Fri Apr 04 18:11:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty_pty.c,v 1.137 2014/03/28 11:55:09 ozaki-r Exp $    */
+/*     $NetBSD: tty_pty.c,v 1.138 2014/04/04 18:11:58 christos Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.137 2014/03/28 11:55:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.138 2014/04/04 18:11:58 christos Exp $");
 
 #include "opt_ptm.h"
 
@@ -1075,7 +1075,7 @@
 #ifndef NO_DEV_PTM
        /* Allow getting the name from either the master or the slave */
        if (cmd == TIOCPTSNAME) {
-               if ((error = ptyfs_getmp(l, &mp)) != 0)
+               if ((error = pty_getmp(l, &mp)) != 0)
                        return error;
                return pty_fill_ptmget(l, dev, -1, -1, data, mp);
        }
@@ -1086,7 +1086,7 @@
                switch (cmd) {
 #ifndef NO_DEV_PTM
                case TIOCGRANTPT:
-                       if ((error = ptyfs_getmp(l, &mp)) != 0)
+                       if ((error = pty_getmp(l, &mp)) != 0)
                                return error;
                        return pty_grant_slave(l, dev, mp);
 #endif
diff -r ae385f6afaad -r 848c28ab9a2e sys/sys/param.h
--- a/sys/sys/param.h   Fri Apr 04 18:10:29 2014 +0000
+++ b/sys/sys/param.h   Fri Apr 04 18:11:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: param.h,v 1.449 2014/03/30 00:13:59 christos Exp $     */
+/*     $NetBSD: param.h,v 1.450 2014/04/04 18:11:58 christos Exp $     */
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -63,7 +63,7 @@
  *     2.99.9          (299000900)
  */
 
-#define        __NetBSD_Version__      699003900       /* NetBSD 6.99.39 */
+#define        __NetBSD_Version__      699004000       /* NetBSD 6.99.40 */
 
 #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
     (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
diff -r ae385f6afaad -r 848c28ab9a2e sys/sys/pty.h
--- a/sys/sys/pty.h     Fri Apr 04 18:10:29 2014 +0000
+++ b/sys/sys/pty.h     Fri Apr 04 18:11:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pty.h,v 1.9 2014/03/27 17:31:56 christos Exp $ */
+/*     $NetBSD: pty.h,v 1.10 2014/04/04 18:11:58 christos Exp $        */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 dev_t pty_makedev(char, int);
 int pty_vn_open(struct vnode *, struct lwp *);
 struct ptm_pty *pty_sethandler(struct ptm_pty *);
-int ptyfs_getmp(struct lwp *, struct mount **);
+int pty_getmp(struct lwp *, struct mount **);
 
 /*
  * Ptm_pty is used for switch ptm{x} driver between BSDPTY, PTYFS.
@@ -53,7 +53,7 @@
            char);
        int (*makename)(struct mount *, struct lwp *, char *, size_t, dev_t, char);
        void (*getvattr)(struct mount *, struct lwp *, struct vattr *);
-       void *arg;
+       int (*getmp)(struct lwp *, struct mount **);
 };
 
 #ifdef COMPAT_BSDPTY



Home | Main Index | Thread Index | Old Index