Print this page
    
    
      
        | 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
  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   24   * Copyright 2016, Joyent, Inc.
  25   25   */
  26   26  
  27   27  #ifndef _SYS_BRAND_H
  28   28  #define _SYS_BRAND_H
  29   29  
  30   30  #ifdef  __cplusplus
  31   31  extern "C" {
  32   32  #endif
  33   33  
  34   34  #include <sys/proc.h>
  35   35  #include <sys/exec.h>
  36   36  #include <sys/modctl.h>
  37   37  #include <sys/types.h>
  38   38  
  39   39  /*
  40   40   * All Brands supported by this kernel must use BRAND_VER_1.
  41   41   */
  42   42  #define BRAND_VER_1     1
  43   43  
  44   44  /*
  45   45   * sub-commands to brandsys.
  46   46   * 1 - 128 are for common commands
  47   47   * 128+ are available for brand-specific commands.
  48   48   */
  49   49  #define B_REGISTER              1
  50   50  #define B_TTYMODES              2
  51   51  #define B_ELFDATA               3
  52   52  #define B_EXEC_NATIVE           4
  53   53  #define B_EXEC_BRAND            5
  54   54  #define B_TRUSS_POINT           6
  55   55  
  56   56  /*
  57   57   * Structure used by zoneadmd to communicate the name of a brand and the
  58   58   * supporting brand module into the kernel.
  59   59   */
  60   60  struct brand_attr {
  61   61          char    ba_brandname[MAXNAMELEN];
  62   62          char    ba_modname[MAXPATHLEN];
  63   63  };
  64   64  
  65   65  /* What we call the native brand. */
  66   66  #define NATIVE_BRAND_NAME       "native"
  67   67  
  68   68  /* What we call the labeled brand. */
  69   69  #define LABELED_BRAND_NAME      "labeled"
  70   70  
  71   71  /*
  72   72   * Aux vector containing lddata pointer of brand library linkmap.
  73   73   * Used by common {brand}_librtld_db.
  74   74   */
  75   75  #define AT_SUN_BRAND_COMMON_LDDATA      AT_SUN_BRAND_AUX1
  76   76  
  77   77  /*
  78   78   * Information needed by the brand library to launch an executable.
  79   79   */
  80   80  typedef struct brand_elf_data {
  81   81          ulong_t         sed_phdr;
  82   82          ulong_t         sed_phent;
  83   83          ulong_t         sed_phnum;
  84   84          ulong_t         sed_entry;
  85   85          ulong_t         sed_base;
  86   86          ulong_t         sed_ldentry;
  87   87          ulong_t         sed_lddata;
  88   88  } brand_elf_data_t;
  89   89  
  90   90  /*
  91   91   * Common structure used to register a branded processes
  92   92   */
  93   93  typedef struct brand_proc_reg {
  94   94          uint_t          sbr_version;    /* version number */
  95   95          caddr_t         sbr_handler;    /* base address of handler */
  96   96  } brand_proc_reg_t;
  97   97  
  98   98  #ifdef  _KERNEL
  99   99  
 100  100  struct proc;
 101  101  struct uarg;
 102  102  struct brand_mach_ops;
 103  103  struct intpdata;
 104  104  struct execa;
 105  105  
 106  106  /*
 107  107   * Common structure to define hooks for brand operation.
 108  108   *
 109  109   * Required Fields:
 110  110   * b_init_brand_data - Setup zone brand data during zone_setbrand
 111  111   * b_free_brand_data - Free zone brand data during zone_destroy
 112  112   * b_brandsys - Syscall handler for brandsys
 113  113   * b_setbrand - Initialize process brand data
 114  114   * b_getattr - Get brand-custom zone attribute
 115  115   * b_setattr - Set brand-custom zone attribute
 116  116   * b_copy_procdata - Copy process brand data during fork
 117  117   * b_proc_exit - Perform process brand exit processing
 118  118   * b_exec - Reset branded process state on exec
 119  119   * b_lwp_setrval - Set return code for forked child
 120  120   * b_initlwp - Initialize lwp brand data (cannot drop p->p_lock)
 121  121   * b_forklwp - Copy lwp brand data during fork
 122  122   * b_freelwp - Free lwp brand data
 123  123   * b_lwpexit - Perform lwp-specific brand exit processing
 124  124   * b_elfexec - Load and execute ELF binary
 125  125   * b_sigset_native_to_brand - Convert sigset native->brand
 126  126   * b_sigset_brand_to_native - Convert sigset brand->native
 127  127   * b_nsig - Maxiumum signal number
 128  128   * b_sendsig - Update process state after sendsig
 129  129   *
 130  130   * Optional Fields:
 131  131   * b_lwpdata_alloc - Speculatively allocate data for use in b_initlwp
 132  132   * b_lwpdata_free - Free data from allocated by b_lwpdata_alloc if errors occur
 133  133   *                  during lwp creation before b_initlwp could be called.
 134  134   * b_initlwp_post - Complete lwp branding (can temporarily drop p->p_lock)
 135  135   * b_exit_with_sig - Instead of sending SIGCLD, exit with custom behavior
 136  136   * b_psig_to_proc - Custom additional behavior during psig
 137  137   * b_wait_filter - Filter processes from being matched by waitid
 138  138   * b_native_exec - Provide interpreter path prefix for executables
 139  139   * b_ptrace_exectrap - Custom behavior for legacy ptrace traps
 140  140   * b_map32limit - Specify alternate limit for MAP_32BIT mappings
 141  141   * b_stop_notify - Hook process stop events
 142  142   * b_waitid_helper - Generate synthetic results for waitid
 143  143   * b_sigcld_repost - Post synthetic SIGCLD signals
 144  144   * b_issig_stop - Alter/suppress signal delivery during issig
 145  145   * b_sig_ignorable - Disallow discarding of signals
 146  146   * b_savecontext - Alter context during savecontext
 147  147   * b_restorecontext - Alter context during restorecontext
 148  148   * b_sendsig_stack - Override stack used for signal delivery
 149  149   * b_setid_clear - Override setid_clear behavior
 150  150   * b_pagefault - Trap pagefault events
 151  151   * b_intp_parse_arg - Controls interpreter argument handling (allow 1 or all)
 152  152   */
 153  153  struct brand_ops {
 154  154          void    (*b_init_brand_data)(zone_t *, kmutex_t *);
 155  155          void    (*b_free_brand_data)(zone_t *);
 156  156          int     (*b_brandsys)(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
 157  157                  uintptr_t);
 158  158          void    (*b_setbrand)(struct proc *);
 159  159          int     (*b_getattr)(zone_t *, int, void *, size_t *);
 160  160          int     (*b_setattr)(zone_t *, int, void *, size_t);
 161  161          void    (*b_copy_procdata)(struct proc *, struct proc *);
 162  162          void    (*b_proc_exit)(struct proc *);
 163  163          void    (*b_exec)();
 164  164          void    (*b_lwp_setrval)(klwp_t *, int, int);
 165  165          void    *(*b_lwpdata_alloc)(struct proc *);
 166  166          void    (*b_lwpdata_free)(void *);
 167  167          void    (*b_initlwp)(klwp_t *, void *);
 168  168          void    (*b_initlwp_post)(klwp_t *);
 169  169          void    (*b_forklwp)(klwp_t *, klwp_t *);
 170  170          void    (*b_freelwp)(klwp_t *);
 171  171          void    (*b_lwpexit)(klwp_t *);
 172  172          int     (*b_elfexec)(struct vnode *vp, struct execa *uap,
 173  173              struct uarg *args, struct intpdata *idata, int level,
 174  174              long *execsz, int setid, caddr_t exec_file,
 175  175              struct cred *cred, int *brand_action);
 176  176          void    (*b_sigset_native_to_brand)(sigset_t *);
 177  177          void    (*b_sigset_brand_to_native)(sigset_t *);
 178  178          void    (*b_sigfd_translate)(k_siginfo_t *);
 179  179          int     b_nsig;
 180  180          void    (*b_exit_with_sig)(proc_t *, sigqueue_t *);
 181  181          boolean_t (*b_wait_filter)(proc_t *, proc_t *);
 182  182          boolean_t (*b_native_exec)(uint8_t, const char **);
 183  183          uint32_t (*b_map32limit)(proc_t *);
 184  184          void    (*b_stop_notify)(proc_t *, klwp_t *, ushort_t, ushort_t);
 185  185          int     (*b_waitid_helper)(idtype_t, id_t, k_siginfo_t *, int,
 186  186              boolean_t *, int *);
 187  187          int     (*b_sigcld_repost)(proc_t *, sigqueue_t *);
 188  188          int     (*b_issig_stop)(proc_t *, klwp_t *);
 189  189          boolean_t (*b_sig_ignorable)(proc_t *, klwp_t *, int);
 190  190          void    (*b_savecontext)(ucontext_t *);
 191  191  #if defined(_SYSCALL32_IMPL)
 192  192          void    (*b_savecontext32)(ucontext32_t *);
 193  193  #endif
 194  194          void    (*b_restorecontext)(ucontext_t *);
 195  195          caddr_t (*b_sendsig_stack)(int);
 196  196          void    (*b_sendsig)(int);
 197  197          int     (*b_setid_clear)(vattr_t *vap, cred_t *cr);
 198  198          int     (*b_pagefault)(proc_t *, klwp_t *, caddr_t, enum fault_type,
 199  199              enum seg_rw);
 200  200          boolean_t b_intp_parse_arg;
 201  201  };
 202  202  
 203  203  /*
 204  204   * The b_version field must always be the first entry in this struct.
 205  205   */
 206  206  typedef struct brand {
 207  207          int                     b_version;
 208  208          char                    *b_name;
 209  209          struct brand_ops        *b_ops;
 210  210          struct brand_mach_ops   *b_machops;
 211  211          size_t                  b_data_size;
 212  212  } brand_t;
 213  213  
 214  214  extern brand_t native_brand;
 215  215  
 216  216  /*
 217  217   * Convenience macros
 218  218   */
 219  219  #define lwptolwpbrand(l)        ((l)->lwp_brand)
 220  220  #define ttolwpbrand(t)          (lwptolwpbrand(ttolwp(t)))
 221  221  #define PROC_IS_BRANDED(p)      ((p)->p_brand != &native_brand)
 222  222  #define ZONE_IS_BRANDED(z)      ((z)->zone_brand != &native_brand)
 223  223  #define BROP(p)                 ((p)->p_brand->b_ops)
 224  224  #define ZBROP(z)                ((z)->zone_brand->b_ops)
 225  225  #define BRMOP(p)                ((p)->p_brand->b_machops)
 226  226  #define SIGSET_NATIVE_TO_BRAND(sigset)                          \
 227  227          if (PROC_IS_BRANDED(curproc) &&                         \
 228  228              BROP(curproc)->b_sigset_native_to_brand)            \
 229  229                  BROP(curproc)->b_sigset_native_to_brand(sigset)
 230  230  #define SIGSET_BRAND_TO_NATIVE(sigset)                          \
 231  231          if (PROC_IS_BRANDED(curproc) &&                         \
 232  232              BROP(curproc)->b_sigset_brand_to_native)            \
 233  233                  BROP(curproc)->b_sigset_brand_to_native(sigset)
 234  234  
 235  235  extern void     brand_init();
 236  236  extern int      brand_register(brand_t *);
 237  237  extern int      brand_unregister(brand_t *);
 238  238  extern brand_t  *brand_register_zone(struct brand_attr *);
 239  239  extern brand_t  *brand_find_name(char *);
 240  240  extern void     brand_unregister_zone(brand_t *);
 241  241  extern int      brand_zone_count(brand_t *);
 242  242  extern int      brand_setbrand(proc_t *, boolean_t);
 243  243  extern void     brand_clearbrand(proc_t *, boolean_t);
 244  244  
 245  245  /*
 246  246   * The following functions can be shared among kernel brand modules which
 247  247   * implement Solaris-derived brands, all of which need to do similar tasks to
 248  248   * manage the brand.
 249  249   */
 250  250  extern int      brand_solaris_cmd(int, uintptr_t, uintptr_t, uintptr_t,
 251  251                      struct brand *, int);
 252  252  extern void     brand_solaris_copy_procdata(proc_t *, proc_t *,
 253  253                      struct brand *);
 254  254  extern int      brand_solaris_elfexec(vnode_t *, execa_t *, uarg_t *,
 255  255                      intpdata_t *, int, long *, int, caddr_t, cred_t *, int *,
 256  256                      struct brand *, char *, char *, char *);
 257  257  extern void     brand_solaris_exec(struct brand *);
 258  258  extern int      brand_solaris_fini(char **, struct modlinkage *,
 259  259                      struct brand *);
 260  260  extern void     brand_solaris_forklwp(klwp_t *, klwp_t *, struct brand *);
 261  261  extern void     brand_solaris_freelwp(klwp_t *, struct brand *);
 262  262  extern void     brand_solaris_initlwp(klwp_t *, struct brand *);
 263  263  extern void     brand_solaris_lwpexit(klwp_t *, struct brand *);
 264  264  extern void     brand_solaris_proc_exit(struct proc *, struct brand *);
 265  265  extern void     brand_solaris_setbrand(proc_t *, struct brand *);
 266  266  
 267  267  #if defined(_SYSCALL32)
 268  268  typedef struct brand_elf_data32 {
 269  269          uint32_t        sed_phdr;
 270  270          uint32_t        sed_phent;
 271  271          uint32_t        sed_phnum;
 272  272          uint32_t        sed_entry;
 273  273          uint32_t        sed_base;
 274  274          uint32_t        sed_ldentry;
 275  275          uint32_t        sed_lddata;
 276  276  } brand_elf_data32_t;
 277  277  
 278  278  typedef struct brand_common_reg32 {
 279  279          uint32_t        sbr_version;    /* version number */
 280  280          caddr32_t       sbr_handler;    /* base address of handler */
 281  281  } brand_common_reg32_t;
 282  282  #endif /* _SYSCALL32 */
 283  283  
 284  284  /*
 285  285   * Common information associated with all branded processes
 286  286   */
 287  287  typedef struct brand_proc_data {
 288  288          caddr_t         spd_handler;    /* address of user-space handler */
 289  289          brand_elf_data_t spd_elf_data;  /* common ELF data for branded app. */
 290  290  } brand_proc_data_t;
 291  291  
 292  292  #define BRAND_NATIVE_DIR        "/.SUNWnative/"
 293  293  #define BRAND_NATIVE_LINKER32   BRAND_NATIVE_DIR "lib/ld.so.1"
 294  294  #define BRAND_NATIVE_LINKER64   BRAND_NATIVE_DIR "lib/64/ld.so.1"
 295  295  
 296  296  #endif  /* _KERNEL */
 297  297  
 298  298  #ifdef  __cplusplus
 299  299  }
 300  300  #endif
 301  301  
 302  302  #endif  /* _SYS_BRAND_H */
  
    | 
      ↓ open down ↓ | 
    302 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX