0053-telnetd-Fix-arbitrary-remote-code-execution-via-shor.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. From 99afdd5ecd787e40f06473304125eee93139031a Mon Sep 17 00:00:00 2001
  2. From: Michal Ruprich <michalruprich@gmail.com>
  3. Date: Sun, 12 Apr 2020 22:41:50 +0200
  4. Subject: [PATCH 53/60] telnetd: Fix arbitrary remote code execution via short
  5. writes or urgent data
  6. Fixes: CVE-2020-10188
  7. Closes: #956084
  8. Bug-RedHat: https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2020-10188
  9. Patch-Origin: Fedora / RedHat
  10. Patch-URL: https://src.fedoraproject.org/rpms/telnet/raw/master/f/telnet-0.17-overflow-exploit.patch
  11. ---
  12. telnetd/telnetd.h | 2 +-
  13. telnetd/utility.c | 35 ++++++++++++++++++++++-------------
  14. 2 files changed, 23 insertions(+), 14 deletions(-)
  15. diff --git a/telnetd/telnetd.h b/telnetd/telnetd.h
  16. index 044025d2..fa970e24 100644
  17. --- a/telnetd/telnetd.h
  18. +++ b/telnetd/telnetd.h
  19. @@ -271,7 +271,7 @@ void io_drain (void);
  20. int stilloob (int s);
  21. void ptyflush (void);
  22. -char *nextitem (char *current);
  23. +char *nextitem (char *current, const char *endp);
  24. void netclear (void);
  25. void netflush (void);
  26. diff --git a/telnetd/utility.c b/telnetd/utility.c
  27. index db93c205..c9df8a79 100644
  28. --- a/telnetd/utility.c
  29. +++ b/telnetd/utility.c
  30. @@ -484,10 +484,14 @@ stilloob (int s)
  31. * character.
  32. */
  33. char *
  34. -nextitem (char *current)
  35. +nextitem (char *current, const char *endp)
  36. {
  37. + if (current >= endp)
  38. + return NULL;
  39. if ((*current & 0xff) != IAC)
  40. return current + 1;
  41. + if (current + 1 >= endp)
  42. + return NULL;
  43. switch (*(current + 1) & 0xff)
  44. {
  45. @@ -495,19 +499,20 @@ nextitem (char *current)
  46. case DONT:
  47. case WILL:
  48. case WONT:
  49. - return current + 3;
  50. + return current + 3 <= endp ? current + 3 : NULL;
  51. case SB: /* loop forever looking for the SE */
  52. {
  53. char *look = current + 2;
  54. - for (;;)
  55. - if ((*look++ & 0xff) == IAC && (*look++ & 0xff) == SE)
  56. + while (look < endp)
  57. + if ((*look++ & 0xff) == IAC && look < endp && (*look++ & 0xff) == SE)
  58. return look;
  59. - default:
  60. - return current + 2;
  61. + return NULL;
  62. }
  63. + default:
  64. + return current + 2 <= endp ? current + 2 : NULL;
  65. }
  66. } /* end of nextitem */
  67. @@ -529,8 +534,9 @@ nextitem (char *current)
  68. * us in any case.
  69. */
  70. #define wewant(p) \
  71. - ((nfrontp > p) && ((*p&0xff) == IAC) && \
  72. - ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
  73. + ((nfrontp > p) && ((*p & 0xff) == IAC) && \
  74. + (nfrontp > p + 1 && (((*(p + 1) & 0xff) != EC) && \
  75. + ((*(p + 1)&0xff) != EL))))
  76. void
  77. @@ -545,7 +551,7 @@ netclear (void)
  78. thisitem = netobuf;
  79. #endif /* ENCRYPTION */
  80. - while ((next = nextitem (thisitem)) <= nbackp)
  81. + while ((next = nextitem (thisitem, nbackp)) != NULL && next <= nbackp)
  82. thisitem = next;
  83. /* Now, thisitem is first before/at boundary. */
  84. @@ -556,15 +562,18 @@ netclear (void)
  85. good = netobuf; /* where the good bytes go */
  86. #endif /* ENCRYPTION */
  87. - while (nfrontp > thisitem)
  88. + while (thisitem != NULL && nfrontp > thisitem)
  89. {
  90. if (wewant (thisitem))
  91. {
  92. int length;
  93. - for (next = thisitem; wewant (next) && nfrontp > next;
  94. - next = nextitem (next))
  95. + for (next = thisitem;
  96. + next != NULL && wewant (next) && nfrontp > next;
  97. + next = nextitem (next, nfrontp))
  98. ;
  99. + if (next == NULL)
  100. + next = nfrontp;
  101. length = next - thisitem;
  102. memmove (good, thisitem, length);
  103. @@ -573,7 +582,7 @@ netclear (void)
  104. }
  105. else
  106. {
  107. - thisitem = nextitem (thisitem);
  108. + thisitem = nextitem (thisitem, nfrontp);
  109. }
  110. }
  111. --
  112. 2.26.0.292.g33ef6b2f38