Print this page
12306 XPG4v2 slave pty behaviour should generally be disabled
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Change-ID: I7ccd399c22866f34dd20c6bb9d28e77ba4e24c67

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/streamio.c
          +++ new/usr/src/uts/common/os/streamio.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  22   22  /*        All Rights Reserved   */
  23   23  
  24   24  
  25   25  /*
  26   26   * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  27   27   * Copyright 2017 Joyent, Inc.
  28      - * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
       28 + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
  29   29   */
  30   30  
  31   31  #include <sys/types.h>
  32   32  #include <sys/sysmacros.h>
  33   33  #include <sys/param.h>
  34   34  #include <sys/errno.h>
  35   35  #include <sys/signal.h>
  36   36  #include <sys/stat.h>
  37   37  #include <sys/proc.h>
  38   38  #include <sys/cred.h>
↓ open down ↓ 32 lines elided ↑ open up ↑
  71   71  #include <sys/tty.h>
  72   72  #include <sys/ptyvar.h>
  73   73  #include <sys/vuid_event.h>
  74   74  #include <sys/modctl.h>
  75   75  #include <sys/sunddi.h>
  76   76  #include <sys/sunldi_impl.h>
  77   77  #include <sys/autoconf.h>
  78   78  #include <sys/policy.h>
  79   79  #include <sys/dld.h>
  80   80  #include <sys/zone.h>
       81 +#include <sys/ptms.h>
  81   82  #include <c2/audit.h>
  82   83  
  83   84  /*
  84   85   * This define helps improve the readability of streams code while
  85   86   * still maintaining a very old streams performance enhancement.  The
  86   87   * performance enhancement basically involved having all callers
  87   88   * of straccess() perform the first check that straccess() will do
  88   89   * locally before actually calling straccess().  (There by reducing
  89   90   * the number of unnecessary calls to straccess().)
  90   91   */
↓ open down ↓ 133 lines elided ↑ open up ↑
 224  225          mutex_enter(&stp->sd_lock);
 225  226          if (anchor == stp->sd_pushcnt) {
 226  227                  stp->sd_anchor = stp->sd_pushcnt;
 227  228                  stp->sd_anchorzone = anchor_zoneid;
 228  229          }
 229  230          mutex_exit(&stp->sd_lock);
 230  231  
 231  232          return (0);
 232  233  }
 233  234  
      235 +static int
      236 +xpg4_fixup(queue_t *qp, dev_t *devp, struct stdata *stp, cred_t *crp)
      237 +{
      238 +        static const char *ptsmods[] = {
      239 +            "ptem", "ldterm", "ttcompat"
      240 +        };
      241 +        dev_t dummydev = *devp;
      242 +        struct strioctl strioc;
      243 +        zoneid_t zoneid;
      244 +        int32_t rval;
      245 +        uint_t i;
      246 +
      247 +        /*
      248 +         * Push modules required for the slave PTY to have terminal
      249 +         * semantics out of the box; this is required by XPG4v2.
      250 +         * These three modules are flagged as single-instance so that
      251 +         * the system will never end up with duplicate copies pushed
      252 +         * onto a stream.
      253 +         */
      254 +
      255 +        zoneid = crgetzoneid(crp);
      256 +        for (i = 0; i < ARRAY_SIZE(ptsmods); i++) {
      257 +                int error;
      258 +
      259 +                error = push_mod(qp, &dummydev, stp, ptsmods[i], 0,
      260 +                    crp, zoneid);
      261 +                if (error != 0)
      262 +                        return (error);
      263 +        }
      264 +
      265 +        /*
      266 +         * Send PTSSTTY down the stream
      267 +         */
      268 +
      269 +        strioc.ic_cmd = PTSSTTY;
      270 +        strioc.ic_timout = 0;
      271 +        strioc.ic_len = 0;
      272 +        strioc.ic_dp = NULL;
      273 +
      274 +        (void) strdoioctl(stp, &strioc, FNATIVE, K_TO_K, crp, &rval);
      275 +
      276 +        return (0);
      277 +}
      278 +
 234  279  /*
 235  280   * Open a stream device.
 236  281   */
 237  282  int
 238  283  stropen(vnode_t *vp, dev_t *devp, int flag, cred_t *crp)
 239  284  {
 240  285          struct stdata *stp;
 241  286          queue_t *qp;
 242  287          int s;
 243  288          dev_t dummydev, savedev;
↓ open down ↓ 298 lines elided ↑ open up ↑
 542  587                  error = push_mod(qp, &dummydev, stp, ap->ap_list[s],
 543  588                      anchor, crp, zoneid);
 544  589                  if (error != 0)
 545  590                          break;
 546  591          }
 547  592          sad_ap_rele(ap, ss);
 548  593          netstack_rele(ss->ss_netstack);
 549  594  
 550  595  opendone:
 551  596  
      597 +        if (error == 0 &&
      598 +            (stp->sd_flag & (STRISTTY|STRXPG4TTY)) == (STRISTTY|STRXPG4TTY)) {
      599 +                error = xpg4_fixup(qp, devp, stp, crp);
      600 +        }
      601 +
 552  602          /*
 553  603           * let specfs know that open failed part way through
 554  604           */
 555      -        if (error) {
      605 +        if (error != 0) {
 556  606                  mutex_enter(&stp->sd_lock);
 557  607                  stp->sd_flag |= STREOPENFAIL;
 558  608                  mutex_exit(&stp->sd_lock);
 559  609          }
 560  610  
 561  611          /*
 562  612           * Wake up others that are waiting for stream to be created.
 563  613           */
 564  614          mutex_enter(&stp->sd_lock);
 565  615          stp->sd_flag &= ~STWOPEN;
↓ open down ↓ 8099 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX