Print this page
11927 Log, or optionally panic, on zero-length kmem allocations
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/nfs/nfs_auth.c
          +++ new/usr/src/uts/common/fs/nfs/nfs_auth.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  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   23   * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  24   24   * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
  25   25   * Copyright (c) 2015 by Delphix. All rights reserved.
       26 + * Copyright (c) 2015 Joyent, Inc.  All rights reserved.
  26   27   */
  27   28  
  28   29  #include <sys/param.h>
  29   30  #include <sys/errno.h>
  30   31  #include <sys/vfs.h>
  31   32  #include <sys/vnode.h>
  32   33  #include <sys/cred.h>
  33   34  #include <sys/cmn_err.h>
  34   35  #include <sys/systm.h>
  35   36  #include <sys/kmem.h>
↓ open down ↓ 518 lines elided ↑ open up ↑
 554  555          }
 555  556          XDR_DESTROY(&xdrs);
 556  557          kmem_free(da.rbuf, da.rsize);
 557  558  
 558  559          DTRACE_PROBE1(nfsserv__func__nfsauth__results, nfsauth_res_t *, &res);
 559  560          switch (res.stat) {
 560  561                  case NFSAUTH_DR_OKAY:
 561  562                          *access = res.ares.auth_perm;
 562  563                          *srv_uid = res.ares.auth_srv_uid;
 563  564                          *srv_gid = res.ares.auth_srv_gid;
 564      -                        *srv_gids_cnt = res.ares.auth_srv_gids.len;
 565      -                        *srv_gids = kmem_alloc(*srv_gids_cnt * sizeof (gid_t),
 566      -                            KM_SLEEP);
 567      -                        bcopy(res.ares.auth_srv_gids.val, *srv_gids,
 568      -                            *srv_gids_cnt * sizeof (gid_t));
      565 +
      566 +                        if ((*srv_gids_cnt = res.ares.auth_srv_gids.len) != 0) {
      567 +                                *srv_gids = kmem_alloc(*srv_gids_cnt *
      568 +                                    sizeof (gid_t), KM_SLEEP);
      569 +                                bcopy(res.ares.auth_srv_gids.val, *srv_gids,
      570 +                                    *srv_gids_cnt * sizeof (gid_t));
      571 +                        } else {
      572 +                                *srv_gids = NULL;
      573 +                        }
      574 +
 569  575                          break;
 570  576  
 571  577                  case NFSAUTH_DR_EFAIL:
 572  578                  case NFSAUTH_DR_DECERR:
 573  579                  case NFSAUTH_DR_BADCMD:
 574  580                  default:
 575  581                          xdr_free(xdr_nfsauth_res, (char *)&res);
 576  582  fail:
 577  583                          *access = NFSAUTH_DENIED;
 578  584                          kmem_free(abuf, absz);
↓ open down ↓ 468 lines elided ↑ open up ↑
1047 1053  
1048 1054                  refresh = gethrestime_sec() - p->auth_freshness;
1049 1055  
1050 1056                  p->auth_time = gethrestime_sec();
1051 1057  
1052 1058                  if (uid != NULL)
1053 1059                          *uid = p->auth_srv_uid;
1054 1060                  if (gid != NULL)
1055 1061                          *gid = p->auth_srv_gid;
1056 1062                  if (ngids != NULL && gids != NULL) {
1057      -                        *ngids = p->auth_srv_ngids;
1058      -                        *gids = kmem_alloc(*ngids * sizeof (gid_t), KM_SLEEP);
1059      -                        bcopy(p->auth_srv_gids, *gids, *ngids * sizeof (gid_t));
     1063 +                        if ((*ngids = p->auth_srv_ngids) != 0) {
     1064 +                                size_t sz = *ngids * sizeof (gid_t);
     1065 +                                *gids = kmem_alloc(sz, KM_SLEEP);
     1066 +                                bcopy(p->auth_srv_gids, *gids, sz);
     1067 +                        } else {
     1068 +                                *gids = NULL;
     1069 +                        }
1060 1070                  }
1061 1071  
1062 1072                  access = p->auth_access;
1063 1073  
1064 1074                  if ((refresh > NFSAUTH_CACHE_REFRESH) &&
1065 1075                      p->auth_state == NFS_AUTH_FRESH) {
1066 1076                          refreshq_auth_node_t *ran;
1067 1077                          uint_t nacr;
1068 1078  
1069 1079                          p->auth_state = NFS_AUTH_STALE;
↓ open down ↓ 452 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX