0001-telnetd-utility.c-Fix-buffer-overflow-in-netoprintf.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From 9c81c8e5bc7782e8ae12c078615abc3c896059f2 Mon Sep 17 00:00:00 2001
  2. From: Julius Hemanth Pitti <jpitti@cisco.com>
  3. Date: Tue, 14 Jul 2020 22:34:19 -0700
  4. Subject: [PATCH] telnetd/utility.c: Fix buffer overflow in netoprintf
  5. As per man page of vsnprintf, when formated
  6. string size is greater than "size"(2nd argument),
  7. then vsnprintf returns size of formated string,
  8. not "size"(2nd argument).
  9. netoprintf() was not handling a case where
  10. return value of vsnprintf is greater than
  11. "size"(2nd argument), results in buffer overflow
  12. while adjusting "nfrontp" pointer to point
  13. beyond "netobuf" buffer.
  14. Here is one such case where "nfrontp"
  15. crossed boundaries of "netobuf", and
  16. pointing to another global variable.
  17. (gdb) p &netobuf[8255]
  18. $5 = 0x55c93afe8b1f <netobuf+8255> ""
  19. (gdb) p nfrontp
  20. $6 = 0x55c93afe8c20 <terminaltype> "\377"
  21. (gdb) p &terminaltype
  22. $7 = (char **) 0x55c93afe8c20 <terminaltype>
  23. (gdb)
  24. This resulted in crash of telnetd service
  25. with segmentation fault.
  26. Though this is DoS security bug, I couldn't
  27. find any CVE ID for this.
  28. Upstream-Status: Pending
  29. Signed-off-by: Julius Hemanth Pitti <jpitti@cisco.com>
  30. ---
  31. telnetd/utility.c | 2 +-
  32. 1 file changed, 1 insertion(+), 1 deletion(-)
  33. diff --git a/telnetd/utility.c b/telnetd/utility.c
  34. index b9a46a6..4811f14 100644
  35. --- a/telnetd/utility.c
  36. +++ b/telnetd/utility.c
  37. @@ -66,7 +66,7 @@ netoprintf(const char *fmt, ...)
  38. len = vsnprintf(nfrontp, maxsize, fmt, ap);
  39. va_end(ap);
  40. - if (len<0 || len==maxsize) {
  41. + if (len<0 || len>=maxsize) {
  42. /* didn't fit */
  43. netflush();
  44. }
  45. --
  46. 2.19.1