]> granicus.if.org Git - file/commitdiff
add PaX note
authorChristos Zoulas <christos@zoulas.com>
Fri, 20 Sep 2013 00:39:43 +0000 (00:39 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 20 Sep 2013 00:39:43 +0000 (00:39 +0000)
src/readelf.c
src/readelf.h

index 7144ec62245a9dd85c8c6d5354dc49acf919c202..ebaf09366587c1616c8f453b6b619d81d5f64682 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.96 2013/02/22 01:35:49 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.97 2013/03/06 03:35:30 christos Exp $")
 #endif
 
 #ifdef BUILTIN_ELF
@@ -461,6 +461,36 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
            *flags |= FLAGS_DID_BUILD_ID;
        }
 
+       if (namesz == 4 && strcmp((char *)&nbuf[noff], "PaX") == 0 &&
+           xnh_type == NT_NETBSD_PAX && descsz == 4) {
+               static const char *pax[] = {
+                   "+mprotect",
+                   "-mprotect",
+                   "+segvguard",
+                   "-segvguard",
+                   "+ASLR",
+                   "-ASLR",
+               };
+               uint32_t desc;
+               size_t i;
+               int did = 0;
+
+               (void)memcpy(&desc, &nbuf[doff], sizeof(desc));
+               desc = elf_getu32(swap, desc);
+
+               if (desc && file_printf(ms, ", PaX: ") == -1)
+                       return size;
+
+               for (i = 0; i < __arraycount(pax); i++) {
+                       if (((1 << i) & desc) == 0)
+                               continue;
+                       if (file_printf(ms, "%s%s", did++ ? "," : "",
+                           pax[i]) == -1)
+                               return size;
+               }
+               *flags |= FLAGS_DID_BUILD_ID;
+       }
+
        if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0 &&
            xnh_type == NT_NETBSD_VERSION && descsz == 4) {
                uint32_t desc;
@@ -677,6 +707,7 @@ core:
 
        default:
                if (xnh_type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {
+/*###709 [cc] warning: declaration of 'i' shadows previous non-variable%%%*/
                        size_t i, j;
                        unsigned char c;
                        /*
index e34fcc3207999e5090187ffaa8e7ff99ef36a5c0..10a9e63605212e0b18b4cad2ccfd6e4bb3bae68a 100644 (file)
@@ -255,6 +255,23 @@ typedef struct {
  */
 #define        NT_GNU_BUILD_ID         3
 
+/*
+ * NetBSD-specific note type: PaX.
+ * There should be 1 NOTE per executable.
+ * name: PaX\0
+ * namesz: 4
+ * desc:
+ *     word[0]: capability bitmask
+ * descsz: 4
+ */
+#define NT_NETBSD_PAX          3
+#define NT_NETBSD_PAX_MPROTECT         0x01    /* Force enable Mprotect */
+#define NT_NETBSD_PAX_NOMPROTECT       0x02    /* Force disable Mprotect */
+#define NT_NETBSD_PAX_GUARD            0x04    /* Force enable Segvguard */
+#define NT_NETBSD_PAX_NOGUARD          0x08    /* Force disable Servguard */
+#define NT_NETBSD_PAX_ASLR             0x10    /* Force enable ASLR */
+#define NT_NETBSD_PAX_NOASLR           0x20    /* Force disable ASLR */
+
 /* SunOS 5.x hardware/software capabilities */
 typedef struct {
        Elf32_Word      c_tag;