Print this page
12505 Answer KEBE question about cred in unexport()

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/nfs/nfs_export.c
          +++ new/usr/src/uts/common/fs/nfs/nfs_export.c
↓ open down ↓ 77 lines elided ↑ open up ↑
  78   78   * nfs_exi_id_lock      Lock to protect the export ID list
  79   79   *
  80   80   * All exi_id_next, exi_id_overflow, and exi_id_tree are protected by
  81   81   * nfs_exi_id_lock.
  82   82   */
  83   83  static int exi_id_next;
  84   84  static bool_t exi_id_overflow;
  85   85  avl_tree_t exi_id_tree;
  86   86  kmutex_t nfs_exi_id_lock;
  87   87  
  88      -static int      unexport(nfs_export_t *, exportinfo_t *);
       88 +static int      unexport(nfs_export_t *, exportinfo_t *, cred_t *);
  89   89  static void     exportfree(exportinfo_t *);
  90   90  static int      loadindex(exportdata_t *);
  91   91  
  92   92  extern void     nfsauth_cache_free(exportinfo_t *);
  93   93  extern int      sec_svc_loadrootnames(int, int, caddr_t **, model_t);
  94   94  extern void     sec_svc_freerootnames(int, int, caddr_t *);
  95   95  
  96   96  static int      build_seclist_nodups(exportdata_t *, secinfo_t *, int);
  97   97  static void     srv_secinfo_add(secinfo_t **, int *, secinfo_t *, int, int);
  98   98  static void     srv_secinfo_remove(secinfo_t **, int *, secinfo_t *, int);
↓ open down ↓ 869 lines elided ↑ open up ↑
 968  968  
 969  969  /*
 970  970   * During zone shutdown, remove exports
 971  971   */
 972  972  void
 973  973  nfs_export_zone_shutdown(nfs_globals_t *ng)
 974  974  {
 975  975          nfs_export_t *ne = ng->nfs_export;
 976  976          struct exportinfo *exi, *nexi;
 977  977          int i, errors;
      978 +        zoneid_t zoneid = ng->nfs_zoneid;
      979 +        cred_t *cr;
 978  980  
      981 +        /*
      982 +         * Use the zone's credential.  Since this is a zone shutdown method,
      983 +         * the zone_t should still be around for a zone_get_kcred() call.
      984 +         */
      985 +        cr = zone_get_kcred(zoneid);
      986 +        VERIFY(cr != NULL);
 979  987          rw_enter(&ne->exported_lock, RW_READER);
 980  988  
 981  989          errors = 0;
 982  990          for (i = 0; i < EXPTABLESIZE; i++) {
 983  991  
 984  992                  exi = ne->exptable[i];
 985  993                  if (exi != NULL)
 986  994                          exi_hold(exi);
 987  995  
 988  996                  while (exi != NULL) {
 989      -
      997 +                        ASSERT3U(zoneid, ==, exi->exi_zoneid);
 990  998                          /*
 991  999                           * Get and hold next export before
 992 1000                           * dropping the rwlock and unexport
 993 1001                           */
 994 1002                          nexi = exi->fid_hash.next;
 995 1003                          if (nexi != NULL)
 996 1004                                  exi_hold(nexi);
 997 1005  
 998 1006                          rw_exit(&ne->exported_lock);
 999 1007  
1000 1008                          /*
1001 1009                           * Skip ne->exi_root which gets special
1002 1010                           * create/destroy handling.
1003 1011                           */
1004 1012                          if (exi != ne->exi_root &&
1005      -                            unexport(ne, exi) != 0)
     1013 +                            unexport(ne, exi, cr) != 0)
1006 1014                                  errors++;
1007 1015                          exi_rele(exi);
1008 1016  
1009 1017                          rw_enter(&ne->exported_lock, RW_READER);
1010 1018                          exi = nexi;
1011 1019                  }
1012 1020          }
1013 1021          if (errors > 0) {
1014 1022                  cmn_err(CE_NOTE, "NFS: failed un-exports in zone %d",
1015 1023                      (int)ng->nfs_zoneid);
1016 1024          }
1017 1025  
1018 1026          rw_exit(&ne->exported_lock);
     1027 +        crfree(cr);
1019 1028  }
1020 1029  
1021 1030  void
1022 1031  nfs_export_zone_fini(nfs_globals_t *ng)
1023 1032  {
1024 1033          int i;
1025 1034          nfs_export_t *ne = ng->nfs_export;
1026 1035          struct exportinfo *exi;
1027 1036  
1028 1037          ng->nfs_export = NULL;
↓ open down ↓ 250 lines elided ↑ open up ↑
1279 1288                  }
1280 1289          }
1281 1290          DTRACE_PROBE(nfss__i__exported_lock1_stop);
1282 1291          rw_exit(&ne->exported_lock);
1283 1292  
1284 1293          /* Is this an unshare? */
1285 1294          if (STRUCT_FGETP(uap, uex) == NULL) {
1286 1295                  pn_free(&lookpn);
1287 1296                  if (ex1 == NULL)
1288 1297                          return (EINVAL);
1289      -                error = unexport(ne, ex1);
     1298 +                error = unexport(ne, ex1, cr);
1290 1299                  exi_rele(ex1);
1291 1300                  return (error);
1292 1301          }
1293 1302  
1294 1303          /* It is a share or a re-share */
1295 1304          error = lookupname(STRUCT_FGETP(uap, dname), UIO_USERSPACE,
1296 1305              FOLLOW, &dvp, &vp);
1297 1306          if (error == EINVAL) {
1298 1307                  /*
1299 1308                   * if fname resolves to / we get EINVAL error
↓ open down ↓ 579 lines elided ↑ open up ↑
1879 1888          exp_hash_unlink(exi, fid_hash);
1880 1889          exp_hash_unlink(exi, path_hash);
1881 1890          ASSERT3P(exi->exi_ne, ==, ne);
1882 1891          exi->exi_ne = NULL;
1883 1892  }
1884 1893  
1885 1894  /*
1886 1895   * Unexport an exported filesystem
1887 1896   */
1888 1897  static int
1889      -unexport(nfs_export_t *ne, struct exportinfo *exi)
     1898 +unexport(nfs_export_t *ne, struct exportinfo *exi, cred_t *cr)
1890 1899  {
1891 1900          struct secinfo cursec[MAX_FLAVORS];
1892 1901          int curcnt;
1893 1902  
1894 1903          rw_enter(&ne->exported_lock, RW_WRITER);
1895 1904  
1896 1905          /* Check if exi is still linked in the export table */
1897 1906          if (!EXP_LINKED(exi) || PSEUDO(exi)) {
1898 1907                  rw_exit(&ne->exported_lock);
1899 1908                  return (EINVAL);
↓ open down ↓ 47 lines elided ↑ open up ↑
1947 1956           * Notify the lock manager that the filesystem is being
1948 1957           * unexported.
1949 1958           */
1950 1959          lm_unexport(exi);
1951 1960  
1952 1961          /*
1953 1962           * If this was a public export, restore
1954 1963           * the public filehandle to the root.
1955 1964           */
1956 1965  
1957      -        /*
1958      -         * XXX KEBE ASKS --> Should CRED() instead be
1959      -         * exi->exi_zone->zone_kcred?
1960      -         */
1961 1966          if (exi == ne->exi_public) {
1962 1967                  ne->exi_public = ne->exi_root;
1963 1968  
1964      -                nfslog_share_record(ne->exi_public, CRED());
     1969 +                nfslog_share_record(ne->exi_public, cr);
1965 1970          }
1966 1971  
1967 1972          if (exi->exi_export.ex_flags & EX_LOG)
1968      -                nfslog_unshare_record(exi, CRED());
     1973 +                nfslog_unshare_record(exi, cr);
1969 1974  
1970 1975          exi_rele(exi);
1971 1976          return (0);
1972 1977  }
1973 1978  
1974 1979  /*
1975 1980   * Get file handle system call.
1976 1981   * Takes file name and returns a file handle for it.
1977 1982   * Credentials must be verified before calling.
1978 1983   */
↓ open down ↓ 1012 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX