Print this page
OS-3893 sendfile compat checks shouldn't be done in so_sendmblk
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/syscall/sendfile.c
          +++ new/usr/src/uts/common/syscall/sendfile.c
↓ open down ↓ 74 lines elided ↑ open up ↑
  75   75  extern sotpi_info_t *sotpi_sototpi(struct sonode *);
  76   76  
  77   77  #define SEND_MAX_CHUNK  16
  78   78  
  79   79  #if defined(_SYSCALL32_IMPL) || defined(_ILP32)
  80   80  /*
  81   81   * 64 bit offsets for 32 bit applications only running either on
  82   82   * 64 bit kernel or 32 bit kernel. For 32 bit apps, we can't transfer
  83   83   * more than 2GB of data.
  84   84   */
  85      -int
       85 +static int
  86   86  sendvec_chunk64(file_t *fp, u_offset_t *fileoff, struct ksendfilevec64 *sfv,
  87   87      int copy_cnt, ssize32_t *count)
  88   88  {
  89   89          struct vnode *vp;
  90   90          ushort_t fflag;
  91   91          int ioflag;
  92   92          size32_t cnt;
  93   93          ssize32_t sfv_len;
  94   94          ssize32_t tmpcount;
  95   95          u_offset_t sfv_off;
↓ open down ↓ 240 lines elided ↑ open up ↑
 336  336                          }
 337  337                          VOP_RWUNLOCK(readvp, V_WRITELOCK_FALSE, NULL);
 338  338                          releasef(sfv->sfv_fd);
 339  339                          kmem_free(ptr, size);
 340  340                  }
 341  341                  sfv++;
 342  342          }
 343  343          return (0);
 344  344  }
 345  345  
 346      -ssize32_t
      346 +static ssize32_t
 347  347  sendvec64(file_t *fp, const struct ksendfilevec64 *vec, int sfvcnt,
 348  348          size32_t *xferred, int fildes)
 349  349  {
 350  350          u_offset_t              fileoff;
 351  351          int                     copy_cnt;
 352  352          const struct ksendfilevec64 *copy_vec;
 353  353          struct ksendfilevec64 sfv[SEND_MAX_CHUNK];
 354  354          struct vnode *vp;
 355  355          int error;
 356  356          ssize32_t count = 0;
↓ open down ↓ 26 lines elided ↑ open up ↑
 383  383          VOP_RWUNLOCK(vp, V_WRITELOCK_TRUE, NULL);
 384  384          if (copyout(&count, xferred, sizeof (count)))
 385  385                  error = EFAULT;
 386  386          releasef(fildes);
 387  387          if (error != 0)
 388  388                  return (set_errno(error));
 389  389          return (count);
 390  390  }
 391  391  #endif
 392  392  
 393      -int
      393 +static int
 394  394  sendvec_small_chunk(file_t *fp, u_offset_t *fileoff, struct sendfilevec *sfv,
 395  395      int copy_cnt, ssize_t total_size, int maxblk, ssize_t *count)
 396  396  {
 397  397          struct vnode *vp;
 398  398          struct uio auio;
 399  399          struct iovec aiov;
 400  400          ushort_t fflag;
 401  401          int ioflag;
 402  402          int i, error;
 403  403          size_t cnt;
↓ open down ↓ 269 lines elided ↑ open up ↑
 673  673                          freemsg(head);
 674  674                  return (error);
 675  675          }
 676  676          ttolwp(curthread)->lwp_ru.ioch += (ulong_t)size;
 677  677          *count += size;
 678  678  
 679  679          return (0);
 680  680  }
 681  681  
 682  682  
 683      -int
      683 +static int
 684  684  sendvec_chunk(file_t *fp, u_offset_t *fileoff, struct sendfilevec *sfv,
 685  685      int copy_cnt, ssize_t *count)
 686  686  {
 687  687          struct vnode *vp;
 688  688          struct uio auio;
 689  689          struct iovec aiov;
 690  690          ushort_t fflag;
 691  691          int ioflag;
 692  692          int i, error;
 693  693          size_t cnt;
↓ open down ↓ 459 lines elided ↑ open up ↑
1153 1153  
1154 1154          switch (vp->v_type) {
1155 1155          case VSOCK:
1156 1156                  so = VTOSO(vp);
1157 1157                  is_sock = B_TRUE;
1158 1158                  if (SOCK_IS_NONSTR(so)) {
1159 1159                          maxblk = so->so_proto_props.sopp_maxblk;
1160 1160                  } else {
1161 1161                          maxblk = (int)vp->v_stream->sd_maxblk;
1162 1162                  }
     1163 +
     1164 +                /*
     1165 +                 * We need to make sure that the socket that we're sending on
     1166 +                 * supports sendfile behavior. sockfs doesn't know that the APIs
     1167 +                 * we want to use are coming from sendfile, so we can't rely on
     1168 +                 * it to check for us.
     1169 +                 */
     1170 +                if ((so->so_mode & SM_SENDFILESUPP) == 0) {
     1171 +                        error = EOPNOTSUPP;
     1172 +                        goto err;
     1173 +                }
1163 1174                  break;
1164 1175          case VREG:
1165 1176                  break;
1166 1177          default:
1167 1178                  error = EINVAL;
1168 1179                  goto err;
1169 1180          }
1170 1181  
1171 1182          switch (opcode) {
1172 1183          case SENDFILEV :
↓ open down ↓ 188 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX