TEMP-0000000-B67840.2.9b5bdd7.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Subject: Add PaX note
  2. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  3. Date: Fri Sep 20 00:39:43 2013 +0000
  4. Origin: FILE5_14-67-g9b5bdd7
  5. Last-Update: 2015-01-05
  6. (prequisite for TEMP-0000000-B67840)
  7. diff --git a/src/readelf.c b/src/readelf.c
  8. index 314adb7..87c19a3 100644
  9. --- a/src/readelf.c
  10. +++ b/src/readelf.c
  11. @@ -471,6 +471,36 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
  12. *flags |= FLAGS_DID_BUILD_ID;
  13. }
  14. + if (namesz == 4 && strcmp((char *)&nbuf[noff], "PaX") == 0 &&
  15. + xnh_type == NT_NETBSD_PAX && descsz == 4) {
  16. + static const char *pax[] = {
  17. + "+mprotect",
  18. + "-mprotect",
  19. + "+segvguard",
  20. + "-segvguard",
  21. + "+ASLR",
  22. + "-ASLR",
  23. + };
  24. + uint32_t desc;
  25. + size_t i;
  26. + int did = 0;
  27. +
  28. + (void)memcpy(&desc, &nbuf[doff], sizeof(desc));
  29. + desc = elf_getu32(swap, desc);
  30. +
  31. + if (desc && file_printf(ms, ", PaX: ") == -1)
  32. + return size;
  33. +
  34. + for (i = 0; i < __arraycount(pax); i++) {
  35. + if (((1 << i) & desc) == 0)
  36. + continue;
  37. + if (file_printf(ms, "%s%s", did++ ? "," : "",
  38. + pax[i]) == -1)
  39. + return size;
  40. + }
  41. + *flags |= FLAGS_DID_BUILD_ID;
  42. + }
  43. +
  44. if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0 &&
  45. xnh_type == NT_NETBSD_VERSION && descsz == 4) {
  46. uint32_t desc;
  47. @@ -687,6 +717,7 @@ core:
  48. default:
  49. if (xnh_type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {
  50. +/*###709 [cc] warning: declaration of 'i' shadows previous non-variable%%%*/
  51. size_t i, j;
  52. unsigned char c;
  53. /*
  54. diff --git a/src/readelf.h b/src/readelf.h
  55. index 4308e6a..df6955c 100644
  56. --- a/src/readelf.h
  57. +++ b/src/readelf.h
  58. @@ -263,6 +263,23 @@ typedef struct {
  59. */
  60. #define NT_GNU_BUILD_ID 3
  61. +/*
  62. + * NetBSD-specific note type: PaX.
  63. + * There should be 1 NOTE per executable.
  64. + * name: PaX\0
  65. + * namesz: 4
  66. + * desc:
  67. + * word[0]: capability bitmask
  68. + * descsz: 4
  69. + */
  70. +#define NT_NETBSD_PAX 3
  71. +#define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */
  72. +#define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
  73. +#define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */
  74. +#define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */
  75. +#define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */
  76. +#define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */
  77. +
  78. /* SunOS 5.x hardware/software capabilities */
  79. typedef struct {
  80. Elf32_Word c_tag;