Print this page
Code review comments from jeffpc
7029 want per-process exploit mitigation features (secflags)
7030 want basic address space layout randomization (aslr)
7031 noexec_user_stack should be a secflag
7032 want a means to forbid mappings around NULL.


  20  */
  21 
  22 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  28  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  29  */
  30 
  31 /*
  32  * String conversion routines the system structs found in
  33  * Solaris core file note sections. These items are not
  34  * ELF constructs. However, elfdump contains code for decoding
  35  * them, and therefore requires formatting support.
  36  */
  37 #include        <stdio.h>
  38 #include        <procfs.h>
  39 #include        <sys/corectl.h>

  40 #include        <string.h>
  41 #include        <_conv.h>
  42 #include        <corenote_msg.h>
  43 
  44 const char *
  45 conv_cnote_type(Word type, Conv_fmt_flags_t fmt_flags,
  46     Conv_inv_buf_t *inv_buf)
  47 {
  48         static const Msg        types[] = {
  49                 MSG_NT_PRSTATUS,        MSG_NT_PRFPREG,
  50                 MSG_NT_PRPSINFO,        MSG_NT_PRXREG,
  51                 MSG_NT_PLATFORM,        MSG_NT_AUXV,
  52                 MSG_NT_GWINDOWS,        MSG_NT_ASRS,
  53                 MSG_NT_LDT,             MSG_NT_PSTATUS,
  54                 0,                      0,
  55                 MSG_NT_PSINFO,          MSG_NT_PRCRED,
  56                 MSG_NT_UTSNAME,         MSG_NT_LWPSTATUS,
  57                 MSG_NT_LWPSINFO,        MSG_NT_PRPRIV,
  58                 MSG_NT_PRPRIVINFO,      MSG_NT_CONTENT,
  59                 MSG_NT_ZONENAME,        MSG_NT_FDINFO,
  60                 MSG_NT_SPYMASTER
  61         };
  62 #if NT_NUM != NT_SPYMASTER
  63 #error "NT_NUM has grown. Update core note types[]"
  64 #endif
  65         static const conv_ds_msg_t ds_types = {
  66             CONV_DS_MSG_INIT(NT_PRSTATUS, types) };
  67         static const conv_ds_t  *ds[] = { CONV_DS_ADDR(ds_types), NULL };
  68 
  69 
  70         return (conv_map_ds(ELFOSABI_NONE, EM_NONE, type, ds, fmt_flags,
  71             inv_buf));
  72 }
  73 
  74 
  75 const char *
  76 conv_cnote_auxv_type(Word type, Conv_fmt_flags_t fmt_flags,
  77     Conv_inv_buf_t *inv_buf)
  78 {
  79         static const Msg        types_0_22[] = {
  80                 MSG_AUXV_AT_NULL,               MSG_AUXV_AT_IGNORE,
  81                 MSG_AUXV_AT_EXECFD,             MSG_AUXV_AT_PHDR,
  82                 MSG_AUXV_AT_PHENT,              MSG_AUXV_AT_PHNUM,


  92         };
  93         static const conv_ds_msg_t ds_types_0_22 = {
  94             CONV_DS_MSG_INIT(0, types_0_22) };
  95 
  96         static const Msg        types_2000_2011[] = {
  97                 MSG_AUXV_AT_SUN_UID,            MSG_AUXV_AT_SUN_RUID,
  98                 MSG_AUXV_AT_SUN_GID,            MSG_AUXV_AT_SUN_RGID,
  99                 MSG_AUXV_AT_SUN_LDELF,          MSG_AUXV_AT_SUN_LDSHDR,
 100                 MSG_AUXV_AT_SUN_LDNAME,         MSG_AUXV_AT_SUN_LPAGESZ,
 101                 MSG_AUXV_AT_SUN_PLATFORM,       MSG_AUXV_AT_SUN_HWCAP,
 102                 MSG_AUXV_AT_SUN_IFLUSH,         MSG_AUXV_AT_SUN_CPU
 103         };
 104         static const conv_ds_msg_t ds_types_2000_2011 = {
 105             CONV_DS_MSG_INIT(2000, types_2000_2011) };
 106 
 107         static const Msg        types_2014_2023[] = {
 108                 MSG_AUXV_AT_SUN_EXECNAME,       MSG_AUXV_AT_SUN_MMU,
 109                 MSG_AUXV_AT_SUN_LDDATA,         MSG_AUXV_AT_SUN_AUXFLAGS,
 110                 MSG_AUXV_AT_SUN_EMULATOR,       MSG_AUXV_AT_SUN_BRANDNAME,
 111                 MSG_AUXV_AT_SUN_BRAND_AUX1,     MSG_AUXV_AT_SUN_BRAND_AUX2,
 112                 MSG_AUXV_AT_SUN_BRAND_AUX3,     MSG_AUXV_AT_SUN_HWCAP2
 113         };
 114         static const conv_ds_msg_t ds_types_2014_2023 = {
 115             CONV_DS_MSG_INIT(2014, types_2014_2023) };
 116 
 117         static const conv_ds_t  *ds[] = {
 118                 CONV_DS_ADDR(ds_types_0_22), CONV_DS_ADDR(ds_types_2000_2011),
 119                 CONV_DS_ADDR(ds_types_2014_2023), NULL };
 120 
 121         return (conv_map_ds(ELFOSABI_NONE, EM_NONE, type, ds, fmt_flags,
 122             inv_buf));
 123 }
 124 
 125 
 126 const char *
 127 conv_cnote_signal(Word sig, Conv_fmt_flags_t fmt_flags,
 128     Conv_inv_buf_t *inv_buf)
 129 {
 130         static const Msg        sigarr[] = {
 131                 MSG_SIGHUP,             MSG_SIGINT,
 132                 MSG_SIGQUIT,            MSG_SIGILL,


2565                 break;
2566         default:
2567                 s = NULL;
2568                 break;
2569         }
2570 
2571         if (s) {
2572                 arg.oflags |= 0x1000;
2573                 arg.rflags |= 0x1000;
2574                 vda[0].v_msg = s;
2575         } else {
2576                 arg.rflags = mode;
2577         }
2578 
2579         if (mode == 0)
2580                 return (MSG_ORIG(MSG_GBL_ZERO));
2581 
2582         (void) conv_expn_field(&arg, vda, fmt_flags);
2583         return (buf);
2584 }
























































  20  */
  21 
  22 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  28  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  29  */
  30 
  31 /*
  32  * String conversion routines the system structs found in
  33  * Solaris core file note sections. These items are not
  34  * ELF constructs. However, elfdump contains code for decoding
  35  * them, and therefore requires formatting support.
  36  */
  37 #include        <stdio.h>
  38 #include        <procfs.h>
  39 #include        <sys/corectl.h>
  40 #include        <sys/secflags.h>
  41 #include        <string.h>
  42 #include        <_conv.h>
  43 #include        <corenote_msg.h>
  44 
  45 const char *
  46 conv_cnote_type(Word type, Conv_fmt_flags_t fmt_flags,
  47     Conv_inv_buf_t *inv_buf)
  48 {
  49         static const Msg        types[] = {
  50                 MSG_NT_PRSTATUS,        MSG_NT_PRFPREG,
  51                 MSG_NT_PRPSINFO,        MSG_NT_PRXREG,
  52                 MSG_NT_PLATFORM,        MSG_NT_AUXV,
  53                 MSG_NT_GWINDOWS,        MSG_NT_ASRS,
  54                 MSG_NT_LDT,             MSG_NT_PSTATUS,
  55                 0,                      0,
  56                 MSG_NT_PSINFO,          MSG_NT_PRCRED,
  57                 MSG_NT_UTSNAME,         MSG_NT_LWPSTATUS,
  58                 MSG_NT_LWPSINFO,        MSG_NT_PRPRIV,
  59                 MSG_NT_PRPRIVINFO,      MSG_NT_CONTENT,
  60                 MSG_NT_ZONENAME,        MSG_NT_FDINFO,
  61                 MSG_NT_SPYMASTER,       MSG_NT_SECFLAGS
  62         };
  63 #if NT_NUM != NT_SECFLAGS
  64 #error "NT_NUM has grown. Update core note types[]"
  65 #endif
  66         static const conv_ds_msg_t ds_types = {
  67             CONV_DS_MSG_INIT(NT_PRSTATUS, types) };
  68         static const conv_ds_t  *ds[] = { CONV_DS_ADDR(ds_types), NULL };
  69 
  70 
  71         return (conv_map_ds(ELFOSABI_NONE, EM_NONE, type, ds, fmt_flags,
  72             inv_buf));
  73 }
  74 
  75 
  76 const char *
  77 conv_cnote_auxv_type(Word type, Conv_fmt_flags_t fmt_flags,
  78     Conv_inv_buf_t *inv_buf)
  79 {
  80         static const Msg        types_0_22[] = {
  81                 MSG_AUXV_AT_NULL,               MSG_AUXV_AT_IGNORE,
  82                 MSG_AUXV_AT_EXECFD,             MSG_AUXV_AT_PHDR,
  83                 MSG_AUXV_AT_PHENT,              MSG_AUXV_AT_PHNUM,


  93         };
  94         static const conv_ds_msg_t ds_types_0_22 = {
  95             CONV_DS_MSG_INIT(0, types_0_22) };
  96 
  97         static const Msg        types_2000_2011[] = {
  98                 MSG_AUXV_AT_SUN_UID,            MSG_AUXV_AT_SUN_RUID,
  99                 MSG_AUXV_AT_SUN_GID,            MSG_AUXV_AT_SUN_RGID,
 100                 MSG_AUXV_AT_SUN_LDELF,          MSG_AUXV_AT_SUN_LDSHDR,
 101                 MSG_AUXV_AT_SUN_LDNAME,         MSG_AUXV_AT_SUN_LPAGESZ,
 102                 MSG_AUXV_AT_SUN_PLATFORM,       MSG_AUXV_AT_SUN_HWCAP,
 103                 MSG_AUXV_AT_SUN_IFLUSH,         MSG_AUXV_AT_SUN_CPU
 104         };
 105         static const conv_ds_msg_t ds_types_2000_2011 = {
 106             CONV_DS_MSG_INIT(2000, types_2000_2011) };
 107 
 108         static const Msg        types_2014_2023[] = {
 109                 MSG_AUXV_AT_SUN_EXECNAME,       MSG_AUXV_AT_SUN_MMU,
 110                 MSG_AUXV_AT_SUN_LDDATA,         MSG_AUXV_AT_SUN_AUXFLAGS,
 111                 MSG_AUXV_AT_SUN_EMULATOR,       MSG_AUXV_AT_SUN_BRANDNAME,
 112                 MSG_AUXV_AT_SUN_BRAND_AUX1,     MSG_AUXV_AT_SUN_BRAND_AUX2,
 113                 MSG_AUXV_AT_SUN_BRAND_AUX3,     MSG_AUXV_AT_SUN_HWCAP2,
 114         };
 115         static const conv_ds_msg_t ds_types_2014_2023 = {
 116             CONV_DS_MSG_INIT(2014, types_2014_2023) };
 117 
 118         static const conv_ds_t  *ds[] = {
 119                 CONV_DS_ADDR(ds_types_0_22), CONV_DS_ADDR(ds_types_2000_2011),
 120                 CONV_DS_ADDR(ds_types_2014_2023), NULL };
 121 
 122         return (conv_map_ds(ELFOSABI_NONE, EM_NONE, type, ds, fmt_flags,
 123             inv_buf));
 124 }
 125 
 126 
 127 const char *
 128 conv_cnote_signal(Word sig, Conv_fmt_flags_t fmt_flags,
 129     Conv_inv_buf_t *inv_buf)
 130 {
 131         static const Msg        sigarr[] = {
 132                 MSG_SIGHUP,             MSG_SIGINT,
 133                 MSG_SIGQUIT,            MSG_SIGILL,


2566                 break;
2567         default:
2568                 s = NULL;
2569                 break;
2570         }
2571 
2572         if (s) {
2573                 arg.oflags |= 0x1000;
2574                 arg.rflags |= 0x1000;
2575                 vda[0].v_msg = s;
2576         } else {
2577                 arg.rflags = mode;
2578         }
2579 
2580         if (mode == 0)
2581                 return (MSG_ORIG(MSG_GBL_ZERO));
2582 
2583         (void) conv_expn_field(&arg, vda, fmt_flags);
2584         return (buf);
2585 }
2586 
2587 
2588 #define PROCSECFLGSZ    CONV_EXPN_FIELD_DEF_PREFIX_SIZE +               \
2589         MSG_ASLR_SIZE           + CONV_EXPN_FIELD_DEF_SEP_SIZE +        \
2590         MSG_FORBIDNULLMAP_SIZE  + CONV_EXPN_FIELD_DEF_SEP_SIZE +        \
2591         MSG_NOEXECSTACK_SIZE    + CONV_EXPN_FIELD_DEF_SEP_SIZE +        \
2592         CONV_INV_BUFSIZE        + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
2593 
2594 /*
2595  * Ensure that Conv_cnote_pr_secflags_buf_t is large enough:
2596  *
2597  * PROCSECFLGSZ is the real minimum size of the buffer required by
2598  * conv_prsecflags(). However, Conv_cnote_pr_secflags_buf_t uses
2599  * CONV_CNOTE_PSECFLAGS_FLAG_BUFSIZE to set the buffer size. We do things this
2600  * way because the definition of PROCSECFLGSZ uses information that is not
2601  * available in the environment of other programs that include the conv.h
2602  * header file.
2603  */
2604 #if (CONV_PRSECFLAGS_BUFSIZE != PROCSECFLGSZ) && !defined(__lint)
2605 #define REPORT_BUFSIZE PROCSECFLGSZ
2606 #include "report_bufsize.h"
2607 #error "CONV_PRSECFLAGS_BUFSIZE does not match PROCSECFLGSZ"
2608 #endif
2609 
2610 const char *
2611 conv_prsecflags(secflagset_t flags, Conv_fmt_flags_t fmt_flags,
2612     Conv_secflags_buf_t *secflags_buf)
2613 {
2614         /*
2615          * The values are initialized later, based on position in this array
2616          */
2617         static Val_desc vda[] = {
2618                 { 0, MSG_ASLR },
2619                 { 0, MSG_FORBIDNULLMAP },
2620                 { 0, MSG_NOEXECSTACK },
2621                 { 0, 0 }
2622         };
2623         static CONV_EXPN_FIELD_ARG conv_arg = {
2624             NULL, sizeof (secflags_buf->buf)
2625         };
2626         int i;
2627 
2628         for (i = 0; vda[i].v_msg != 0; i++)
2629                 vda[i].v_val = secflag_to_bit(i);
2630 
2631         if (flags == 0)
2632                 return (MSG_ORIG(MSG_GBL_ZERO));
2633 
2634         conv_arg.buf = secflags_buf->buf;
2635         conv_arg.oflags = conv_arg.rflags = flags;
2636         (void) conv_expn_field(&conv_arg, vda, fmt_flags);
2637 
2638         return ((const char *)secflags_buf->buf);
2639 }