Print this page
uts: Allow for address space randomisation.
Randomise the base addresses of shared objects, non-fixed mappings, the
stack and the heap.  Introduce a service, svc:/system/process-security,
and a tool psecflags(1) to control and observe it


 755         { AF_SUN_SETUGID,       "setugid" },
 756 };
 757 
 758 /*ARGSUSED*/
 759 static void
 760 at_flags(long val, char *instr, size_t n, char *str)
 761 {
 762         int i;
 763 
 764         *str = '\0';
 765 
 766         for (i = 0; i < sizeof (auxfl)/sizeof (struct auxfl); i++) {
 767                 if ((val & auxfl[i].af_flag) != 0) {
 768                         if (*str != '\0')
 769                                 (void) strlcat(str, ",", n);
 770                         (void) strlcat(str, auxfl[i].af_name, n);
 771                 }
 772         }
 773 }
 774 
























 775 #define MAX_AT_NAME_LEN 15
 776 
 777 struct aux_id {
 778         int aux_type;
 779         const char *aux_name;
 780         void (*aux_decode)(long, char *, size_t, char *);
 781 };
 782 
 783 static struct aux_id aux_arr[] = {
 784         { AT_NULL,              "AT_NULL",              at_null },
 785         { AT_IGNORE,            "AT_IGNORE",            at_null },
 786         { AT_EXECFD,            "AT_EXECFD",            at_null },
 787         { AT_PHDR,              "AT_PHDR",              at_null },
 788         { AT_PHENT,             "AT_PHENT",             at_null },
 789         { AT_PHNUM,             "AT_PHNUM",             at_null },
 790         { AT_PAGESZ,            "AT_PAGESZ",            at_null },
 791         { AT_BASE,              "AT_BASE",              at_null },
 792         { AT_FLAGS,             "AT_FLAGS",             at_null },
 793         { AT_ENTRY,             "AT_ENTRY",             at_null },
 794         { AT_SUN_UID,           "AT_SUN_UID",           at_uid  },
 795         { AT_SUN_RUID,          "AT_SUN_RUID",          at_uid  },
 796         { AT_SUN_GID,           "AT_SUN_GID",           at_gid  },
 797         { AT_SUN_RGID,          "AT_SUN_RGID",          at_gid  },
 798         { AT_SUN_LDELF,         "AT_SUN_LDELF",         at_null },
 799         { AT_SUN_LDSHDR,        "AT_SUN_LDSHDR",        at_null },
 800         { AT_SUN_LDNAME,        "AT_SUN_LDNAME",        at_null },
 801         { AT_SUN_LPAGESZ,       "AT_SUN_LPAGESZ",       at_null },
 802         { AT_SUN_PLATFORM,      "AT_SUN_PLATFORM",      at_str  },
 803         { AT_SUN_EXECNAME,      "AT_SUN_EXECNAME",      at_str  },
 804         { AT_SUN_HWCAP,         "AT_SUN_HWCAP",         at_hwcap },
 805         { AT_SUN_HWCAP2,        "AT_SUN_HWCAP2",        at_hwcap2 },
 806         { AT_SUN_IFLUSH,        "AT_SUN_IFLUSH",        at_null },
 807         { AT_SUN_CPU,           "AT_SUN_CPU",           at_null },
 808         { AT_SUN_MMU,           "AT_SUN_MMU",           at_null },
 809         { AT_SUN_LDDATA,        "AT_SUN_LDDATA",        at_null },
 810         { AT_SUN_AUXFLAGS,      "AT_SUN_AUXFLAGS",      at_flags },
 811         { AT_SUN_EMULATOR,      "AT_SUN_EMULATOR",      at_str  },
 812         { AT_SUN_BRANDNAME,     "AT_SUN_BRANDNAME",     at_str  },
 813         { AT_SUN_BRAND_AUX1,    "AT_SUN_BRAND_AUX1",    at_null },
 814         { AT_SUN_BRAND_AUX2,    "AT_SUN_BRAND_AUX2",    at_null },
 815         { AT_SUN_BRAND_AUX3,    "AT_SUN_BRAND_AUX3",    at_null }

 816 };
 817 
 818 #define N_AT_ENTS (sizeof (aux_arr) / sizeof (struct aux_id))
 819 
 820 /*
 821  * Return the aux_id entry for the given aux type; returns NULL if not found.
 822  */
 823 static struct aux_id *
 824 aux_find(int type)
 825 {
 826         int i;
 827 
 828         for (i = 0; i < N_AT_ENTS; i++) {
 829                 if (type == aux_arr[i].aux_type)
 830                         return (&aux_arr[i]);
 831         }
 832 
 833         return (NULL);
 834 }
 835 




 755         { AF_SUN_SETUGID,       "setugid" },
 756 };
 757 
 758 /*ARGSUSED*/
 759 static void
 760 at_flags(long val, char *instr, size_t n, char *str)
 761 {
 762         int i;
 763 
 764         *str = '\0';
 765 
 766         for (i = 0; i < sizeof (auxfl)/sizeof (struct auxfl); i++) {
 767                 if ((val & auxfl[i].af_flag) != 0) {
 768                         if (*str != '\0')
 769                                 (void) strlcat(str, ",", n);
 770                         (void) strlcat(str, auxfl[i].af_name, n);
 771                 }
 772         }
 773 }
 774 
 775 static struct auxsecfl {
 776         uint_t af_flag;
 777         const char *af_name;
 778 } auxsecfl[] = {
 779         { PROC_SEC_ASLR,        "aslr" },
 780 };
 781 
 782 /*ARGSUSED*/
 783 static void
 784 at_secflags(long val, char *instr, size_t n, char *str)
 785 {
 786         int i;
 787 
 788         *str = '\0';
 789 
 790         for (i = 0; i < sizeof (auxsecfl)/sizeof (struct auxsecfl); i++) {
 791                 if ((val & auxsecfl[i].af_flag) != 0) {
 792                         if (*str != '\0')
 793                                 (void) strlcat(str, ",", n);
 794                         (void) strlcat(str, auxsecfl[i].af_name, n);
 795                 }
 796         }
 797 }
 798 
 799 #define MAX_AT_NAME_LEN 15
 800 
 801 struct aux_id {
 802         int aux_type;
 803         const char *aux_name;
 804         void (*aux_decode)(long, char *, size_t, char *);
 805 };
 806 
 807 static struct aux_id aux_arr[] = {
 808         { AT_NULL,              "AT_NULL",              at_null },
 809         { AT_IGNORE,            "AT_IGNORE",            at_null },
 810         { AT_EXECFD,            "AT_EXECFD",            at_null },
 811         { AT_PHDR,              "AT_PHDR",              at_null },
 812         { AT_PHENT,             "AT_PHENT",             at_null },
 813         { AT_PHNUM,             "AT_PHNUM",             at_null },
 814         { AT_PAGESZ,            "AT_PAGESZ",            at_null },
 815         { AT_BASE,              "AT_BASE",              at_null },
 816         { AT_FLAGS,             "AT_FLAGS",             at_null },
 817         { AT_ENTRY,             "AT_ENTRY",             at_null },
 818         { AT_SUN_UID,           "AT_SUN_UID",           at_uid  },
 819         { AT_SUN_RUID,          "AT_SUN_RUID",          at_uid  },
 820         { AT_SUN_GID,           "AT_SUN_GID",           at_gid  },
 821         { AT_SUN_RGID,          "AT_SUN_RGID",          at_gid  },
 822         { AT_SUN_LDELF,         "AT_SUN_LDELF",         at_null },
 823         { AT_SUN_LDSHDR,        "AT_SUN_LDSHDR",        at_null },
 824         { AT_SUN_LDNAME,        "AT_SUN_LDNAME",        at_null },
 825         { AT_SUN_LPAGESZ,       "AT_SUN_LPAGESZ",       at_null },
 826         { AT_SUN_PLATFORM,      "AT_SUN_PLATFORM",      at_str  },
 827         { AT_SUN_EXECNAME,      "AT_SUN_EXECNAME",      at_str  },
 828         { AT_SUN_HWCAP,         "AT_SUN_HWCAP",         at_hwcap },
 829         { AT_SUN_HWCAP2,        "AT_SUN_HWCAP2",        at_hwcap2 },
 830         { AT_SUN_IFLUSH,        "AT_SUN_IFLUSH",        at_null },
 831         { AT_SUN_CPU,           "AT_SUN_CPU",           at_null },
 832         { AT_SUN_MMU,           "AT_SUN_MMU",           at_null },
 833         { AT_SUN_LDDATA,        "AT_SUN_LDDATA",        at_null },
 834         { AT_SUN_AUXFLAGS,      "AT_SUN_AUXFLAGS",      at_flags },
 835         { AT_SUN_EMULATOR,      "AT_SUN_EMULATOR",      at_str  },
 836         { AT_SUN_BRANDNAME,     "AT_SUN_BRANDNAME",     at_str  },
 837         { AT_SUN_BRAND_AUX1,    "AT_SUN_BRAND_AUX1",    at_null },
 838         { AT_SUN_BRAND_AUX2,    "AT_SUN_BRAND_AUX2",    at_null },
 839         { AT_SUN_BRAND_AUX3,    "AT_SUN_BRAND_AUX3",    at_null },
 840         { AT_SUN_SECFLAGS,      "AT_SUN_SECFLAGS",      at_secflags },
 841 };
 842 
 843 #define N_AT_ENTS (sizeof (aux_arr) / sizeof (struct aux_id))
 844 
 845 /*
 846  * Return the aux_id entry for the given aux type; returns NULL if not found.
 847  */
 848 static struct aux_id *
 849 aux_find(int type)
 850 {
 851         int i;
 852 
 853         for (i = 0; i < N_AT_ENTS; i++) {
 854                 if (type == aux_arr[i].aux_type)
 855                         return (&aux_arr[i]);
 856         }
 857 
 858         return (NULL);
 859 }
 860