Print this page
5798 fexecve() needed per POSIX 2008

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/exec.c
          +++ new/usr/src/uts/common/os/exec.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  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  
  22   22  /*
       23 + * Copyright 2015 Garrett D'Amore <garrett@damore.org>
  23   24   * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  24   25   */
  25   26  
  26   27  /*      Copyright (c) 1988 AT&T */
  27   28  /*        All Rights Reserved   */
  28   29  /*
  29   30   * Copyright 2014, Joyent, Inc.  All rights reserved.
  30   31   */
  31   32  
  32   33  #include <sys/types.h>
↓ open down ↓ 58 lines elided ↑ open up ↑
  91   92  
  92   93  uint_t auxv_hwcap = 0;  /* auxv AT_SUN_HWCAP value; determined on the fly */
  93   94  uint_t auxv_hwcap_2 = 0;        /* AT_SUN_HWCAP2 */
  94   95  #if defined(_SYSCALL32_IMPL)
  95   96  uint_t auxv_hwcap32 = 0;        /* 32-bit version of auxv_hwcap */
  96   97  uint_t auxv_hwcap32_2 = 0;      /* 32-bit version of auxv_hwcap2 */
  97   98  #endif
  98   99  
  99  100  #define PSUIDFLAGS              (SNOCD|SUGID)
 100  101  
      102 +#define DEVFD                   "/dev/fd/"
      103 +
 101  104  /*
 102  105   * exece() - system call wrapper around exec_common()
 103  106   */
 104  107  int
 105  108  exece(const char *fname, const char **argp, const char **envp)
 106  109  {
 107  110          int error;
 108  111  
 109  112          error = exec_common(fname, argp, envp, EBA_NONE);
 110  113          return (error ? (set_errno(error)) : 0);
↓ open down ↓ 80 lines elided ↑ open up ↑
 191  194           * the directory containing the executable in p_execdir. The
 192  195           * first call to lookuppn() may fail and return EINVAL because
 193  196           * dirvpp is non-NULL. In that case, we make a second call to
 194  197           * lookuppn() with dirvpp set to NULL; p_execdir will be NULL,
 195  198           * but coreadm is allowed to expand %d to the empty string and
 196  199           * there are other cases in which that failure may occur.
 197  200           */
 198  201          if ((error = pn_get((char *)fname, UIO_USERSPACE, &pn)) != 0)
 199  202                  goto out;
 200  203          pn_alloc(&resolvepn);
 201      -        if ((error = lookuppn(&pn, &resolvepn, FOLLOW, &dir, &vp)) != 0) {
      204 +
      205 +        if (strncmp(pn.pn_path, DEVFD, strlen(DEVFD)) == 0) {
      206 +                /* looks like a /dev/fd node */
      207 +                char *p = pn.pn_path + strlen(DEVFD);
      208 +                int fd = stoi(&p);
      209 +                if ((fd < 0) || (*p != 0) || (p == pn.pn_path)) {
      210 +                        error = EBADF;
      211 +                        goto out;
      212 +                }
      213 +                if ((error = fgetstartvp(fd, NULL, &vp)) != 0) {
      214 +                        goto out;       /* error will be EBADF */
      215 +                }
      216 +                (void) pn_set(&resolvepn, pn.pn_path);
      217 +
      218 +        } else if ((error =
      219 +            lookuppn(&pn, &resolvepn, FOLLOW, &dir, &vp)) != 0) {
 202  220                  pn_free(&resolvepn);
 203  221                  pn_free(&pn);
 204  222                  if (error != EINVAL)
 205  223                          goto out;
 206  224  
 207  225                  dir = NULL;
 208  226                  if ((error = pn_get((char *)fname, UIO_USERSPACE, &pn)) != 0)
 209  227                          goto out;
 210  228                  pn_alloc(&resolvepn);
 211  229                  if ((error = lookuppn(&pn, &resolvepn, FOLLOW, NULLVPP,
↓ open down ↓ 1822 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX