Print this page
6474 getupeercred causes spurious event port wakeups on FIFOs

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/fifofs/fifovnops.c
          +++ new/usr/src/uts/common/fs/fifofs/fifovnops.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  22      -/*        All rights reserved.          */
       22 +/*        All rights reserved.          */
  23   23  
  24   24  
  25   25  /*
  26   26   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  27   27   * Use is subject to license terms.
  28   28   */
  29   29  
  30   30  /*
  31   31   * Copyright 2015, Joyent, Inc.
  32   32   * Copyright (c) 2017 by Delphix. All rights reserved.
↓ open down ↓ 525 lines elided ↑ open up ↑
 558  558           * opened pipes will probably fail.
 559  559           */
 560  560  
 561  561          if (fn_dest->fn_open && senthang == 0)
 562  562                  (void) putnextctl_wait(sd_wrq, M_HANGUP);
 563  563  
 564  564  
 565  565          /*
 566  566           * If this a pipe and this is the first end to close,
 567  567           * then we have a bit of cleanup work to do.
 568      -         *      Mark both ends of pipe as closed.
 569      -         *      Wake up anybody blocked at the other end and for named pipes,
      568 +         *      Mark both ends of pipe as closed.
      569 +         *      Wake up anybody blocked at the other end and for named pipes,
 570  570           *      Close down this end of the stream
 571  571           *      Allow other opens/closes to continue
 572      -         *      force an unmount of other end.
      572 +         *      force an unmount of other end.
 573  573           * Otherwise if this is last close,
 574  574           *      flush messages,
 575  575           *      close down the stream
 576  576           *      allow other opens/closes to continue
 577  577           */
 578  578          fnp->fn_flag &= ~FIFOISOPEN;
 579  579          if ((fnp->fn_flag & ISPIPE) && !(fnp->fn_flag & FIFOCLOSE)) {
 580  580                  fnp->fn_flag |= FIFOCLOSE;
 581  581                  fn_dest->fn_flag |= FIFOCLOSE;
 582  582                  if (fnp->fn_flag & FIFOFAST)
↓ open down ↓ 537 lines elided ↑ open up ↑
1120 1120           * Just a quick check
1121 1121           * Once we go to streams mode we don't ever revert back
1122 1122           * So we do this quick check so as not to incur the overhead
1123 1123           * associated with acquiring the lock
1124 1124           */
1125 1125          return ((VTOF(vp)->fn_flag & FIFOFAST) ?
1126 1126              fifo_fastioctl(vp, cmd, arg, mode, cr, rvalp) :
1127 1127              fifo_strioctl(vp, cmd, arg, mode, cr, rvalp));
1128 1128  }
1129 1129  
     1130 +static inline int
     1131 +fifo_ioctl_getpeercred(fifonode_t *fnp, intptr_t arg, int mode)
     1132 +{
     1133 +        k_peercred_t *kp = (k_peercred_t *)arg;
     1134 +
     1135 +        if (mode == FKIOCTL && fnp->fn_pcredp != NULL) {
     1136 +                crhold(fnp->fn_pcredp);
     1137 +                kp->pc_cr = fnp->fn_pcredp;
     1138 +                kp->pc_cpid = fnp->fn_cpid;
     1139 +                return (0);
     1140 +        } else {
     1141 +                return (ENOTSUP);
     1142 +        }
     1143 +}
     1144 +
1130 1145  static int
1131 1146  fifo_fastioctl(vnode_t *vp, int cmd, intptr_t arg, int mode, cred_t *cr,
1132 1147      int *rvalp)
1133 1148  {
1134 1149          fifonode_t      *fnp            = VTOF(vp);
1135 1150          fifonode_t      *fn_dest;
1136 1151          int             error           = 0;
1137 1152          fifolock_t      *fn_lock        = fnp->fn_lock;
1138 1153          int             cnt;
1139 1154  
↓ open down ↓ 199 lines elided ↑ open up ↑
1339 1354  
1340 1355          /*
1341 1356           * Since no band data can ever get on a fifo in fast mode
1342 1357           * just return 0.
1343 1358           */
1344 1359          case I_FLUSHBAND:
1345 1360                  error = 0;
1346 1361                  *rvalp = 0;
1347 1362                  break;
1348 1363  
     1364 +        case _I_GETPEERCRED:
     1365 +                error = fifo_ioctl_getpeercred(fnp, arg, mode);
     1366 +                break;
     1367 +
1349 1368          /*
1350 1369           * invalid calls for stream head or fifos
1351 1370           */
1352 1371  
1353 1372          case I_POP:             /* shouldn't happen */
1354 1373          case I_LOOK:
1355 1374          case I_LINK:
1356 1375          case I_PLINK:
1357 1376          case I_UNLINK:
1358 1377          case I_PUNLINK:
↓ open down ↓ 27 lines elided ↑ open up ↑
1386 1405   * FIFO is in STREAMS mode; STREAMS framework does most of the work.
1387 1406   */
1388 1407  static int
1389 1408  fifo_strioctl(vnode_t *vp, int cmd, intptr_t arg, int mode, cred_t *cr,
1390 1409      int *rvalp)
1391 1410  {
1392 1411          fifonode_t      *fnp = VTOF(vp);
1393 1412          int             error;
1394 1413          fifolock_t      *fn_lock;
1395 1414  
1396      -        if (cmd == _I_GETPEERCRED) {
1397      -                if (mode == FKIOCTL && fnp->fn_pcredp != NULL) {
1398      -                        k_peercred_t *kp = (k_peercred_t *)arg;
1399      -                        crhold(fnp->fn_pcredp);
1400      -                        kp->pc_cr = fnp->fn_pcredp;
1401      -                        kp->pc_cpid = fnp->fn_cpid;
1402      -                        return (0);
1403      -                } else {
1404      -                        return (ENOTSUP);
1405      -                }
1406      -        }
     1415 +        if (cmd == _I_GETPEERCRED)
     1416 +                return (fifo_ioctl_getpeercred(fnp, arg, mode));
1407 1417  
1408 1418          error = strioctl(vp, cmd, arg, mode, U_TO_K, cr, rvalp);
1409 1419  
1410 1420          switch (cmd) {
1411 1421          /*
1412 1422           * The FIFOSEND flag is set to inform other processes that a file
1413 1423           * descriptor is pending at the stream head of this pipe.
1414 1424           * The flag is cleared and the sending process is awoken when
1415 1425           * this process has completed receiving the file descriptor.
1416 1426           * XXX This could become out of sync if the process does I_SENDFDs
↓ open down ↓ 609 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX