CVE-2019-7665.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. From 4323d46c4a369b614aa1f574805860b3434552df Mon Sep 17 00:00:00 2001
  2. From: Mark Wielaard <mark@klomp.org>
  3. Date: Wed, 16 Jan 2019 15:41:31 +0100
  4. Subject: [PATCH] CVE: CVE-2019-7665
  5. Upstream-Status: Backport
  6. Sign off: Shubham Agrawal <shuagr@microsoft.com>
  7. libebl: Check NT_PLATFORM core notes contain a zero terminated string.
  8. Most strings in core notes are fixed size. But NT_PLATFORM contains just
  9. a variable length string. Check that it is actually zero terminated
  10. before passing to readelf to print.
  11. https://sourceware.org/bugzilla/show_bug.cgi?id=24089
  12. Signed-off-by: Mark Wielaard <mark@klomp.org>
  13. Signed-off-by: Ubuntu <lisa@shuagr-yocto-build.mdn4q2lr1oauhmizmzsslly3ad.xx.internal.cloudapp.net>
  14. ---
  15. libdwfl/linux-core-attach.c | 9 +++++----
  16. libebl/eblcorenote.c | 39 +++++++++++++++++++--------------------
  17. libebl/libebl.h | 3 ++-
  18. src/readelf.c | 2 +-
  19. 4 files changed, 27 insertions(+), 26 deletions(-)
  20. diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c
  21. index 6c99b9e..c0f1b0d 100644
  22. --- a/libdwfl/linux-core-attach.c
  23. +++ b/libdwfl/linux-core-attach.c
  24. @@ -137,7 +137,7 @@ core_next_thread (Dwfl *dwfl __attribute__ ((unused)), void *dwfl_arg,
  25. const Ebl_Register_Location *reglocs;
  26. size_t nitems;
  27. const Ebl_Core_Item *items;
  28. - if (! ebl_core_note (core_arg->ebl, &nhdr, name,
  29. + if (! ebl_core_note (core_arg->ebl, &nhdr, name, desc,
  30. &regs_offset, &nregloc, &reglocs, &nitems, &items))
  31. {
  32. /* This note may be just not recognized, skip it. */
  33. @@ -191,8 +191,9 @@ core_set_initial_registers (Dwfl_Thread *thread, void *thread_arg_voidp)
  34. const Ebl_Register_Location *reglocs;
  35. size_t nitems;
  36. const Ebl_Core_Item *items;
  37. - int core_note_err = ebl_core_note (core_arg->ebl, &nhdr, name, &regs_offset,
  38. - &nregloc, &reglocs, &nitems, &items);
  39. + int core_note_err = ebl_core_note (core_arg->ebl, &nhdr, name, desc,
  40. + &regs_offset, &nregloc, &reglocs,
  41. + &nitems, &items);
  42. /* __libdwfl_attach_state_for_core already verified the note is there. */
  43. assert (core_note_err != 0);
  44. assert (nhdr.n_type == NT_PRSTATUS);
  45. @@ -383,7 +384,7 @@ dwfl_core_file_attach (Dwfl *dwfl, Elf *core)
  46. const Ebl_Register_Location *reglocs;
  47. size_t nitems;
  48. const Ebl_Core_Item *items;
  49. - if (! ebl_core_note (ebl, &nhdr, name,
  50. + if (! ebl_core_note (ebl, &nhdr, name, desc,
  51. &regs_offset, &nregloc, &reglocs, &nitems, &items))
  52. {
  53. /* This note may be just not recognized, skip it. */
  54. diff --git a/libebl/eblcorenote.c b/libebl/eblcorenote.c
  55. index 783f981..7fab397 100644
  56. --- a/libebl/eblcorenote.c
  57. +++ b/libebl/eblcorenote.c
  58. @@ -36,11 +36,13 @@
  59. #include <inttypes.h>
  60. #include <stdio.h>
  61. #include <stddef.h>
  62. +#include <string.h>
  63. #include <libeblP.h>
  64. int
  65. ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr, const char *name,
  66. + const char *desc,
  67. GElf_Word *regs_offset, size_t *nregloc,
  68. const Ebl_Register_Location **reglocs, size_t *nitems,
  69. const Ebl_Core_Item **items)
  70. @@ -51,28 +53,25 @@ ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr, const char *name,
  71. {
  72. /* The machine specific function did not know this type. */
  73. - *regs_offset = 0;
  74. - *nregloc = 0;
  75. - *reglocs = NULL;
  76. - switch (nhdr->n_type)
  77. + /* NT_PLATFORM is kind of special since it needs a zero terminated
  78. + string (other notes often have a fixed size string). */
  79. + static const Ebl_Core_Item platform[] =
  80. {
  81. -#define ITEMS(type, table) \
  82. - case type: \
  83. - *items = table; \
  84. - *nitems = sizeof table / sizeof table[0]; \
  85. - result = 1; \
  86. - break
  87. + {
  88. + .name = "Platform",
  89. + .type = ELF_T_BYTE, .count = 0, .format = 's'
  90. + }
  91. + };
  92. - static const Ebl_Core_Item platform[] =
  93. - {
  94. - {
  95. - .name = "Platform",
  96. - .type = ELF_T_BYTE, .count = 0, .format = 's'
  97. - }
  98. - };
  99. - ITEMS (NT_PLATFORM, platform);
  100. -
  101. -#undef ITEMS
  102. + if (nhdr->n_type == NT_PLATFORM
  103. + && memchr (desc, '\0', nhdr->n_descsz) != NULL)
  104. + {
  105. + *regs_offset = 0;
  106. + *nregloc = 0;
  107. + *reglocs = NULL;
  108. + *items = platform;
  109. + *nitems = 1;
  110. + result = 1;
  111. }
  112. }
  113. diff --git a/libebl/libebl.h b/libebl/libebl.h
  114. index ca9b9fe..24922eb 100644
  115. --- a/libebl/libebl.h
  116. +++ b/libebl/libebl.h
  117. @@ -319,7 +319,8 @@ typedef struct
  118. /* Describe the format of a core file note with the given header and NAME.
  119. NAME is not guaranteed terminated, it's NHDR->n_namesz raw bytes. */
  120. -extern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr, const char *name,
  121. +extern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
  122. + const char *name, const char *desc,
  123. GElf_Word *regs_offset, size_t *nregloc,
  124. const Ebl_Register_Location **reglocs,
  125. size_t *nitems, const Ebl_Core_Item **items)
  126. diff --git a/src/readelf.c b/src/readelf.c
  127. index 3a73710..71651e0 100644
  128. --- a/src/readelf.c
  129. +++ b/src/readelf.c
  130. @@ -12153,7 +12153,7 @@ handle_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
  131. size_t nitems;
  132. const Ebl_Core_Item *items;
  133. - if (! ebl_core_note (ebl, nhdr, name,
  134. + if (! ebl_core_note (ebl, nhdr, name, desc,
  135. &regs_offset, &nregloc, &reglocs, &nitems, &items))
  136. return;
  137. --
  138. 2.7.4