Print this page
    
OS-5462 lxbrand kernel should be lint clean
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-5354 lx shebang argument handling is incorrect
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
OS-5189 lx dev enumeration can deadlock with zfs
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
OS-4937 lxbrand ptracer count updates can race
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4460 exec brands processes that still have multiple threads
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4437 lxbrand ptrace turns harmless signals deadly
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-3742 lxbrand add support for signalfd
OS-4382 remove obsolete brand hooks added during lx development
OS-4306 lxbrand setsockopt(IP_MULTICAST_TTL) handles optlen poorly
OS-4303 lxbrand ltp ptrace05 fails
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4188 NULL dereference in lwp_hash_in
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4119 lxbrand panic when running native perl inside lx zone
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-4151 setbrand hooks should be sane during fork
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-4129 lxbrand should not abuse p_brand_data for storing exit signal
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
OS-3825 lxbrand rsyslogd abort on centos6
OS-4047 lxbrand vsyscall while SIGSEGV? on next trap we're handler-free!
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-3926 lxbrand in-kernel fchownat(2), fchown(2), lchown(2), chown(2) and 16-bit ID counterparts
OS-3920 lxbrand use native *at(2) system calls for LX emulation
OS-3561 lxbrand emulation library should execute on alternate stack
OS-3558 lxbrand add support for full in-kernel syscall handling
OS-3545 lx_syscall_regs should not walk stack
OS-3868 many LTP testcases now hang
OS-3901 lxbrand lx_recvmsg fails to translate control messages when 64-bit
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-3820 lxbrand ptrace(2): the next generation
OS-3685 lxbrand PTRACE_O_TRACEFORK race condition
OS-3834 lxbrand 64-bit strace(1) reports 64-bit process as using x32 ABI
OS-3794 lxbrand panic on init signal death
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-3602 lxbrand LTP recv* tests failing on MSG_ERRQUEUE flag
OS-3600 lxbrand 32bit cannot boot with OS-3594 fix
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Bryan Cantrill <bryan@joyent.com>
OS-3594 lx brand: need support for MAP_32BIT
OS-3554 lx brand: node.js test test-fs-append-file.js hangs on 64-bit
OS-3517 lx brand: branded zones don't interpret .interp section
OS-3438 lx brand: "start rsyslog" hangs
OS-2844 lx brand should support 64-bit user-land
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
OS-3149 lx brand always sends SIGCHLD to parent processes, regardless of how clone was invoked
OS-2887 lxbrand add WALL, WCLONE, WNOTHREAD support to waitid
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/sys/brand.h
          +++ new/usr/src/uts/common/sys/brand.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  
    | 
      ↓ open down ↓ | 
    13 lines elided | 
    
      ↑ open up ↑ | 
  
  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   23   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2016, Joyent, Inc.
  24   25   */
  25   26  
  26   27  #ifndef _SYS_BRAND_H
  27   28  #define _SYS_BRAND_H
  28   29  
  29   30  #ifdef  __cplusplus
  30   31  extern "C" {
  31   32  #endif
  32   33  
  33   34  #include <sys/proc.h>
  34   35  #include <sys/exec.h>
  35   36  #include <sys/modctl.h>
  36   37  #include <sys/types.h>
  37   38  
  38   39  /*
  39   40   * All Brands supported by this kernel must use BRAND_VER_1.
  40   41   */
  41   42  #define BRAND_VER_1     1
  42   43  
  43   44  /*
  44   45   * sub-commands to brandsys.
  45   46   * 1 - 128 are for common commands
  46   47   * 128+ are available for brand-specific commands.
  47   48   */
  48   49  #define B_REGISTER              1
  49   50  #define B_TTYMODES              2
  50   51  #define B_ELFDATA               3
  51   52  #define B_EXEC_NATIVE           4
  52   53  #define B_EXEC_BRAND            5
  53   54  #define B_TRUSS_POINT           6
  54   55  
  55   56  /*
  56   57   * Structure used by zoneadmd to communicate the name of a brand and the
  57   58   * supporting brand module into the kernel.
  58   59   */
  59   60  struct brand_attr {
  60   61          char    ba_brandname[MAXNAMELEN];
  61   62          char    ba_modname[MAXPATHLEN];
  62   63  };
  63   64  
  64   65  /* What we call the native brand. */
  65   66  #define NATIVE_BRAND_NAME       "native"
  66   67  
  67   68  /* What we call the labeled brand. */
  68   69  #define LABELED_BRAND_NAME      "labeled"
  69   70  
  70   71  /*
  71   72   * Aux vector containing lddata pointer of brand library linkmap.
  72   73   * Used by common {brand}_librtld_db.
  73   74   */
  74   75  #define AT_SUN_BRAND_COMMON_LDDATA      AT_SUN_BRAND_AUX1
  75   76  
  76   77  /*
  77   78   * Information needed by the brand library to launch an executable.
  78   79   */
  79   80  typedef struct brand_elf_data {
  80   81          ulong_t         sed_phdr;
  81   82          ulong_t         sed_phent;
  82   83          ulong_t         sed_phnum;
  83   84          ulong_t         sed_entry;
  84   85          ulong_t         sed_base;
  85   86          ulong_t         sed_ldentry;
  86   87          ulong_t         sed_lddata;
  87   88  } brand_elf_data_t;
  88   89  
  89   90  /*
  90   91   * Common structure used to register a branded processes
  91   92   */
  92   93  typedef struct brand_proc_reg {
  93   94          uint_t          sbr_version;    /* version number */
  94   95          caddr_t         sbr_handler;    /* base address of handler */
  
    | 
      ↓ open down ↓ | 
    61 lines elided | 
    
      ↑ open up ↑ | 
  
  95   96  } brand_proc_reg_t;
  96   97  
  97   98  #ifdef  _KERNEL
  98   99  
  99  100  struct proc;
 100  101  struct uarg;
 101  102  struct brand_mach_ops;
 102  103  struct intpdata;
 103  104  struct execa;
 104  105  
      106 +/*
      107 + * Common structure to define hooks for brand operation.
      108 + *
      109 + * Required Fields:
      110 + * b_init_brand_data - Setup zone brand data during zone_setbrand
      111 + * b_free_brand_data - Free zone brand data during zone_destroy
      112 + * b_brandsys - Syscall handler for brandsys
      113 + * b_setbrand - Initialize process brand data
      114 + * b_getattr - Get brand-custom zone attribute
      115 + * b_setattr - Set brand-custom zone attribute
      116 + * b_copy_procdata - Copy process brand data during fork
      117 + * b_proc_exit - Perform process brand exit processing
      118 + * b_exec - Reset branded process state on exec
      119 + * b_lwp_setrval - Set return code for forked child
      120 + * b_initlwp - Initialize lwp brand data (cannot drop p->p_lock)
      121 + * b_forklwp - Copy lwp brand data during fork
      122 + * b_freelwp - Free lwp brand data
      123 + * b_lwpexit - Perform lwp-specific brand exit processing
      124 + * b_elfexec - Load and execute ELF binary
      125 + * b_sigset_native_to_brand - Convert sigset native->brand
      126 + * b_sigset_brand_to_native - Convert sigset brand->native
      127 + * b_nsig - Maxiumum signal number
      128 + * b_sendsig - Update process state after sendsig
      129 + *
      130 + * Optional Fields:
      131 + * b_lwpdata_alloc - Speculatively allocate data for use in b_initlwp
      132 + * b_lwpdata_free - Free data from allocated by b_lwpdata_alloc if errors occur
      133 + *                  during lwp creation before b_initlwp could be called.
      134 + * b_initlwp_post - Complete lwp branding (can temporarily drop p->p_lock)
      135 + * b_exit_with_sig - Instead of sending SIGCLD, exit with custom behavior
      136 + * b_psig_to_proc - Custom additional behavior during psig
      137 + * b_wait_filter - Filter processes from being matched by waitid
      138 + * b_native_exec - Provide interpreter path prefix for executables
      139 + * b_ptrace_exectrap - Custom behavior for legacy ptrace traps
      140 + * b_map32limit - Specify alternate limit for MAP_32BIT mappings
      141 + * b_stop_notify - Hook process stop events
      142 + * b_waitid_helper - Generate synthetic results for waitid
      143 + * b_sigcld_repost - Post synthetic SIGCLD signals
      144 + * b_issig_stop - Alter/suppress signal delivery during issig
      145 + * b_sig_ignorable - Disallow discarding of signals
      146 + * b_savecontext - Alter context during savecontext
      147 + * b_restorecontext - Alter context during restorecontext
      148 + * b_sendsig_stack - Override stack used for signal delivery
      149 + * b_setid_clear - Override setid_clear behavior
      150 + * b_pagefault - Trap pagefault events
      151 + * b_intp_parse_arg - Controls interpreter argument handling (allow 1 or all)
      152 + */
 105  153  struct brand_ops {
 106      -        void    (*b_init_brand_data)(zone_t *);
      154 +        void    (*b_init_brand_data)(zone_t *, kmutex_t *);
 107  155          void    (*b_free_brand_data)(zone_t *);
 108  156          int     (*b_brandsys)(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
 109      -                uintptr_t, uintptr_t, uintptr_t);
      157 +                uintptr_t);
 110  158          void    (*b_setbrand)(struct proc *);
 111  159          int     (*b_getattr)(zone_t *, int, void *, size_t *);
 112  160          int     (*b_setattr)(zone_t *, int, void *, size_t);
 113  161          void    (*b_copy_procdata)(struct proc *, struct proc *);
 114      -        void    (*b_proc_exit)(struct proc *, klwp_t *);
      162 +        void    (*b_proc_exit)(struct proc *);
 115  163          void    (*b_exec)();
 116  164          void    (*b_lwp_setrval)(klwp_t *, int, int);
 117      -        int     (*b_initlwp)(klwp_t *);
      165 +        void    *(*b_lwpdata_alloc)(struct proc *);
      166 +        void    (*b_lwpdata_free)(void *);
      167 +        void    (*b_initlwp)(klwp_t *, void *);
      168 +        void    (*b_initlwp_post)(klwp_t *);
 118  169          void    (*b_forklwp)(klwp_t *, klwp_t *);
 119  170          void    (*b_freelwp)(klwp_t *);
 120  171          void    (*b_lwpexit)(klwp_t *);
 121  172          int     (*b_elfexec)(struct vnode *vp, struct execa *uap,
 122  173              struct uarg *args, struct intpdata *idata, int level,
 123  174              long *execsz, int setid, caddr_t exec_file,
 124      -            struct cred *cred, int brand_action);
      175 +            struct cred *cred, int *brand_action);
 125  176          void    (*b_sigset_native_to_brand)(sigset_t *);
 126  177          void    (*b_sigset_brand_to_native)(sigset_t *);
      178 +        void    (*b_sigfd_translate)(k_siginfo_t *);
 127  179          int     b_nsig;
      180 +        void    (*b_exit_with_sig)(proc_t *, sigqueue_t *);
      181 +        boolean_t (*b_wait_filter)(proc_t *, proc_t *);
      182 +        boolean_t (*b_native_exec)(uint8_t, const char **);
      183 +        uint32_t (*b_map32limit)(proc_t *);
      184 +        void    (*b_stop_notify)(proc_t *, klwp_t *, ushort_t, ushort_t);
      185 +        int     (*b_waitid_helper)(idtype_t, id_t, k_siginfo_t *, int,
      186 +            boolean_t *, int *);
      187 +        int     (*b_sigcld_repost)(proc_t *, sigqueue_t *);
      188 +        int     (*b_issig_stop)(proc_t *, klwp_t *);
      189 +        boolean_t (*b_sig_ignorable)(proc_t *, klwp_t *, int);
      190 +        void    (*b_savecontext)(ucontext_t *);
      191 +#if defined(_SYSCALL32_IMPL)
      192 +        void    (*b_savecontext32)(ucontext32_t *);
      193 +#endif
      194 +        void    (*b_restorecontext)(ucontext_t *);
      195 +        caddr_t (*b_sendsig_stack)(int);
      196 +        void    (*b_sendsig)(int);
      197 +        int     (*b_setid_clear)(vattr_t *vap, cred_t *cr);
      198 +        int     (*b_pagefault)(proc_t *, klwp_t *, caddr_t, enum fault_type,
      199 +            enum seg_rw);
      200 +        boolean_t b_intp_parse_arg;
 128  201  };
 129  202  
 130  203  /*
 131  204   * The b_version field must always be the first entry in this struct.
 132  205   */
 133  206  typedef struct brand {
 134  207          int                     b_version;
 135  208          char                    *b_name;
 136  209          struct brand_ops        *b_ops;
 137  210          struct brand_mach_ops   *b_machops;
      211 +        size_t                  b_data_size;
 138  212  } brand_t;
 139  213  
 140  214  extern brand_t native_brand;
 141  215  
 142  216  /*
 143  217   * Convenience macros
 144  218   */
 145  219  #define lwptolwpbrand(l)        ((l)->lwp_brand)
 146  220  #define ttolwpbrand(t)          (lwptolwpbrand(ttolwp(t)))
 147  221  #define PROC_IS_BRANDED(p)      ((p)->p_brand != &native_brand)
 148  222  #define ZONE_IS_BRANDED(z)      ((z)->zone_brand != &native_brand)
 149  223  #define BROP(p)                 ((p)->p_brand->b_ops)
 150  224  #define ZBROP(z)                ((z)->zone_brand->b_ops)
 151  225  #define BRMOP(p)                ((p)->p_brand->b_machops)
 152  226  #define SIGSET_NATIVE_TO_BRAND(sigset)                          \
 153  227          if (PROC_IS_BRANDED(curproc) &&                         \
 154  228              BROP(curproc)->b_sigset_native_to_brand)            \
 155  229                  BROP(curproc)->b_sigset_native_to_brand(sigset)
 156  230  #define SIGSET_BRAND_TO_NATIVE(sigset)                          \
 157  231          if (PROC_IS_BRANDED(curproc) &&                         \
  
    | 
      ↓ open down ↓ | 
    10 lines elided | 
    
      ↑ open up ↑ | 
  
 158  232              BROP(curproc)->b_sigset_brand_to_native)            \
 159  233                  BROP(curproc)->b_sigset_brand_to_native(sigset)
 160  234  
 161  235  extern void     brand_init();
 162  236  extern int      brand_register(brand_t *);
 163  237  extern int      brand_unregister(brand_t *);
 164  238  extern brand_t  *brand_register_zone(struct brand_attr *);
 165  239  extern brand_t  *brand_find_name(char *);
 166  240  extern void     brand_unregister_zone(brand_t *);
 167  241  extern int      brand_zone_count(brand_t *);
 168      -extern void     brand_setbrand(proc_t *);
      242 +extern int      brand_setbrand(proc_t *, boolean_t);
 169  243  extern void     brand_clearbrand(proc_t *, boolean_t);
 170  244  
 171  245  /*
 172  246   * The following functions can be shared among kernel brand modules which
 173  247   * implement Solaris-derived brands, all of which need to do similar tasks to
 174  248   * manage the brand.
 175  249   */
 176  250  extern int      brand_solaris_cmd(int, uintptr_t, uintptr_t, uintptr_t,
 177  251                      struct brand *, int);
 178  252  extern void     brand_solaris_copy_procdata(proc_t *, proc_t *,
 179  253                      struct brand *);
 180  254  extern int      brand_solaris_elfexec(vnode_t *, execa_t *, uarg_t *,
 181      -                    intpdata_t *, int, long *, int, caddr_t, cred_t *, int,
 182      -                    struct brand *, char *, char *, char *, char *, char *);
      255 +                    intpdata_t *, int, long *, int, caddr_t, cred_t *, int *,
      256 +                    struct brand *, char *, char *, char *);
 183  257  extern void     brand_solaris_exec(struct brand *);
 184  258  extern int      brand_solaris_fini(char **, struct modlinkage *,
 185  259                      struct brand *);
 186  260  extern void     brand_solaris_forklwp(klwp_t *, klwp_t *, struct brand *);
 187  261  extern void     brand_solaris_freelwp(klwp_t *, struct brand *);
 188      -extern int      brand_solaris_initlwp(klwp_t *, struct brand *);
      262 +extern void     brand_solaris_initlwp(klwp_t *, struct brand *);
 189  263  extern void     brand_solaris_lwpexit(klwp_t *, struct brand *);
 190      -extern void     brand_solaris_proc_exit(struct proc *, klwp_t *,
 191      -                    struct brand *);
      264 +extern void     brand_solaris_proc_exit(struct proc *, struct brand *);
 192  265  extern void     brand_solaris_setbrand(proc_t *, struct brand *);
 193  266  
 194  267  #if defined(_SYSCALL32)
 195  268  typedef struct brand_elf_data32 {
 196  269          uint32_t        sed_phdr;
 197  270          uint32_t        sed_phent;
 198  271          uint32_t        sed_phnum;
 199  272          uint32_t        sed_entry;
 200  273          uint32_t        sed_base;
 201  274          uint32_t        sed_ldentry;
 202  275          uint32_t        sed_lddata;
 203  276  } brand_elf_data32_t;
 204  277  
 205  278  typedef struct brand_common_reg32 {
 206  279          uint32_t        sbr_version;    /* version number */
 207  280          caddr32_t       sbr_handler;    /* base address of handler */
 208  281  } brand_common_reg32_t;
 209  282  #endif /* _SYSCALL32 */
 210  283  
 211  284  /*
 212  285   * Common information associated with all branded processes
 213  286   */
 214  287  typedef struct brand_proc_data {
 215  288          caddr_t         spd_handler;    /* address of user-space handler */
 216  289          brand_elf_data_t spd_elf_data;  /* common ELF data for branded app. */
 217  290  } brand_proc_data_t;
 218  291  
 219  292  #define BRAND_NATIVE_DIR        "/.SUNWnative/"
 220  293  #define BRAND_NATIVE_LINKER32   BRAND_NATIVE_DIR "lib/ld.so.1"
 221  294  #define BRAND_NATIVE_LINKER64   BRAND_NATIVE_DIR "lib/64/ld.so.1"
 222  295  
 223  296  #endif  /* _KERNEL */
 224  297  
 225  298  #ifdef  __cplusplus
 226  299  }
 227  300  #endif
 228  301  
 229  302  #endif  /* _SYS_BRAND_H */
  
    | 
      ↓ open down ↓ | 
    28 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX