Print this page
OS-208 DTrace needs to use zone_did to match zone-limited enablings
OS-192 zone_create() warning on headnode

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/zone.c
          +++ new/usr/src/uts/common/os/zone.c
↓ open down ↓ 411 lines elided ↑ open up ↑
 412  412   * Version 2 alters the zone_create system call in order to support more
 413  413   *     arguments by moving the args into a structure; and to do better
 414  414   *     error reporting when zone_create() fails.
 415  415   * Version 3 alters the zone_create system call in order to support the
 416  416   *     import of ZFS datasets to zones.
 417  417   * Version 4 alters the zone_create system call in order to support
 418  418   *     Trusted Extensions.
 419  419   * Version 5 alters the zone_boot system call, and converts its old
 420  420   *     bootargs parameter to be set by the zone_setattr API instead.
 421  421   * Version 6 adds the flag argument to zone_create.
      422 + * Version 7 adds the requested zone_did to zone_create.
 422  423   */
 423      -static const int ZONE_SYSCALL_API_VERSION = 6;
      424 +static const int ZONE_SYSCALL_API_VERSION = 7;
 424  425  
 425  426  /*
 426  427   * Certain filesystems (such as NFS and autofs) need to know which zone
 427  428   * the mount is being placed in.  Because of this, we need to be able to
 428  429   * ensure that a zone isn't in the process of being created/destroyed such
 429  430   * that nfs_mount() thinks it is in the global/NGZ zone, while by the time
 430  431   * it gets added the list of mounted zones, it ends up on the wrong zone's
 431  432   * mount list. Since a zone can't reside on an NFS file system, we don't
 432  433   * have to worry about the zonepath itself.
 433  434   *
↓ open down ↓ 2579 lines elided ↑ open up ↑
3013 3014          mutex_exit(&zone_status_lock);
3014 3015          zone_rele(zone);
3015 3016  }
3016 3017  
3017 3018  zoneid_t
3018 3019  getzoneid(void)
3019 3020  {
3020 3021          return (curproc->p_zone->zone_id);
3021 3022  }
3022 3023  
     3024 +zoneid_t
     3025 +getzonedid(void)
     3026 +{
     3027 +        return (curproc->p_zone->zone_did);
     3028 +}
     3029 +
3023 3030  /*
3024 3031   * Internal versions of zone_find_by_*().  These don't zone_hold() or
3025 3032   * check the validity of a zone's state.
3026 3033   */
3027 3034  static zone_t *
3028 3035  zone_find_all_by_id(zoneid_t zoneid)
3029 3036  {
3030 3037          mod_hash_val_t hv;
3031 3038          zone_t *zone = NULL;
3032 3039  
↓ open down ↓ 1362 lines elided ↑ open up ↑
4395 4402   *
4396 4403   * If extended error is non-null, we may use it to return more detailed
4397 4404   * error information.
4398 4405   */
4399 4406  static zoneid_t
4400 4407  zone_create(const char *zone_name, const char *zone_root,
4401 4408      const priv_set_t *zone_privs, size_t zone_privssz,
4402 4409      caddr_t rctlbuf, size_t rctlbufsz,
4403 4410      caddr_t zfsbuf, size_t zfsbufsz, int *extended_error,
4404 4411      int match, uint32_t doi, const bslabel_t *label,
4405      -    int flags)
     4412 +    int flags, zoneid_t zone_did)
4406 4413  {
4407 4414          struct zsched_arg zarg;
4408 4415          nvlist_t *rctls = NULL;
4409 4416          proc_t *pp = curproc;
4410 4417          zone_t *zone, *ztmp;
4411 4418          zoneid_t zoneid, start = GLOBAL_ZONEID;
4412 4419          int error;
4413 4420          int error2 = 0;
4414 4421          char *str;
4415 4422          cred_t *zkcr;
4416 4423          boolean_t insert_label_hash;
4417 4424  
4418 4425          if (secpolicy_zone_config(CRED()) != 0)
4419 4426                  return (set_errno(EPERM));
4420 4427  
4421 4428          /* can't boot zone from within chroot environment */
4422 4429          if (PTOU(pp)->u_rdir != NULL && PTOU(pp)->u_rdir != rootdir)
4423 4430                  return (zone_create_error(ENOTSUP, ZE_CHROOTED,
4424 4431                      extended_error));
     4432 +
4425 4433          /*
4426 4434           * As the first step of zone creation, we want to allocate a zoneid.
4427 4435           * This allocation is complicated by the fact that netstacks use the
4428 4436           * zoneid to determine their stackid, but netstacks themselves are
4429 4437           * freed asynchronously with respect to zone destruction.  This means
4430 4438           * that a netstack reference leak (or in principle, an extraordinarily
4431 4439           * long netstack reference hold) could result in a zoneid being
4432 4440           * allocated that in fact corresponds to a stackid from an active
4433 4441           * (referenced) netstack -- unleashing all sorts of havoc when that
4434 4442           * netstack is actually (re)used.  (In the abstract, we might wish a
↓ open down ↓ 31 lines elided ↑ open up ↑
4466 4474                          cmn_err(CE_WARN, "zone_create() failed: all available "
4467 4475                              "zone IDs have netstacks still in use");
4468 4476                          return (set_errno(ENFILE));
4469 4477                  }
4470 4478  
4471 4479                  cmn_err(CE_WARN, "unable to reuse zone ID %d; "
4472 4480                      "netstack still in use", zoneid);
4473 4481          }
4474 4482  
4475 4483          zone = kmem_zalloc(sizeof (zone_t), KM_SLEEP);
     4484 +
4476 4485          zone->zone_id = zoneid;
     4486 +        zone->zone_did = zone_did;
4477 4487          zone->zone_status = ZONE_IS_UNINITIALIZED;
4478 4488          zone->zone_pool = pool_default;
4479 4489          zone->zone_pool_mod = gethrtime();
4480 4490          zone->zone_psetid = ZONE_PS_INVAL;
4481 4491          zone->zone_ncpus = 0;
4482 4492          zone->zone_ncpus_online = 0;
4483 4493          zone->zone_restart_init = B_TRUE;
4484 4494          zone->zone_brand = &native_brand;
4485 4495          zone->zone_initname = NULL;
4486 4496          mutex_init(&zone->zone_lock, NULL, MUTEX_DEFAULT, NULL);
↓ open down ↓ 1183 lines elided ↑ open up ↑
5670 5680                  zbuf = kmem_alloc(bufsize, KM_SLEEP);
5671 5681                  if (copyin(buf, zbuf, bufsize) != 0) {
5672 5682                          error = EFAULT;
5673 5683                  } else {
5674 5684                          error = zone_get_network(zoneid, zbuf);
5675 5685                          if (error == 0 && copyout(zbuf, buf, bufsize) != 0)
5676 5686                                  error = EFAULT;
5677 5687                  }
5678 5688                  kmem_free(zbuf, bufsize);
5679 5689                  break;
     5690 +        case ZONE_ATTR_DID:
     5691 +                size = sizeof (zoneid_t);
     5692 +                if (bufsize > size)
     5693 +                        bufsize = size;
     5694 +
     5695 +                if (buf != NULL && copyout(&zone->zone_did, buf, bufsize) != 0)
     5696 +                        error = EFAULT;
     5697 +                break;
5680 5698          default:
5681 5699                  if ((attr >= ZONE_ATTR_BRAND_ATTRS) && ZONE_IS_BRANDED(zone)) {
5682 5700                          size = bufsize;
5683 5701                          error = ZBROP(zone)->b_getattr(zone, attr, buf, &size);
5684 5702                  } else {
5685 5703                          error = EINVAL;
5686 5704                  }
5687 5705          }
5688 5706          zone_rele(zone);
5689 5707  
↓ open down ↓ 784 lines elided ↑ open up ↑
6474 6492                          zs.rctlbuf = (caddr_t)(unsigned long)zs32.rctlbuf;
6475 6493                          zs.rctlbufsz = zs32.rctlbufsz;
6476 6494                          zs.zfsbuf = (caddr_t)(unsigned long)zs32.zfsbuf;
6477 6495                          zs.zfsbufsz = zs32.zfsbufsz;
6478 6496                          zs.extended_error =
6479 6497                              (int *)(unsigned long)zs32.extended_error;
6480 6498                          zs.match = zs32.match;
6481 6499                          zs.doi = zs32.doi;
6482 6500                          zs.label = (const bslabel_t *)(uintptr_t)zs32.label;
6483 6501                          zs.flags = zs32.flags;
     6502 +                        zs.zone_did = zs32.zone_did;
6484 6503  #else
6485 6504                          panic("get_udatamodel() returned bogus result\n");
6486 6505  #endif
6487 6506                  }
6488 6507  
6489 6508                  return (zone_create(zs.zone_name, zs.zone_root,
6490 6509                      zs.zone_privs, zs.zone_privssz,
6491 6510                      (caddr_t)zs.rctlbuf, zs.rctlbufsz,
6492 6511                      (caddr_t)zs.zfsbuf, zs.zfsbufsz,
6493 6512                      zs.extended_error, zs.match, zs.doi,
6494      -                    zs.label, zs.flags));
     6513 +                    zs.label, zs.flags, zs.zone_did));
6495 6514          case ZONE_BOOT:
6496 6515                  return (zone_boot((zoneid_t)(uintptr_t)arg1));
6497 6516          case ZONE_DESTROY:
6498 6517                  return (zone_destroy((zoneid_t)(uintptr_t)arg1));
6499 6518          case ZONE_GETATTR:
6500 6519                  return (zone_getattr((zoneid_t)(uintptr_t)arg1,
6501 6520                      (int)(uintptr_t)arg2, arg3, (size_t)arg4));
6502 6521          case ZONE_SETATTR:
6503 6522                  return (zone_setattr((zoneid_t)(uintptr_t)arg1,
6504 6523                      (int)(uintptr_t)arg2, arg3, (size_t)arg4));
↓ open down ↓ 881 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX