1
0

0002-BUG-MEDIUM-ssl-Shutdown-the-connection-for-reading-on-SSL_ERROR_SYSCALL.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From f7fa1d461aa71bbc8a6c23fdcfc305f2e52ce5dd Mon Sep 17 00:00:00 2001
  2. From: Christopher Faulet <cfaulet@haproxy.com>
  3. Date: Mon, 19 Feb 2018 14:25:15 +0100
  4. Subject: [PATCH] BUG/MEDIUM: ssl: Shutdown the connection for reading on
  5. SSL_ERROR_SYSCALL
  6. When SSL_read returns SSL_ERROR_SYSCALL and errno is unset or set to EAGAIN, the
  7. connection must be shut down for reading. Else, the connection loops infinitly,
  8. consuming all the CPU.
  9. The bug was introduced in the commit 7e2e50500 ("BUG/MEDIUM: ssl: Don't always
  10. treat SSL_ERROR_SYSCALL as unrecovarable."). This patch must be backported in
  11. 1.8 too.
  12. (cherry picked from commit 4ac77a98cda3d0f9b1d9de7bbbda2c91357f0767)
  13. Signed-off-by: Willy Tarreau <w@1wt.eu>
  14. ---
  15. src/ssl_sock.c | 14 ++++++++------
  16. 1 file changed, 8 insertions(+), 6 deletions(-)
  17. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  18. index f118724..a065bbb 100644
  19. --- a/src/ssl_sock.c
  20. +++ b/src/ssl_sock.c
  21. @@ -5437,10 +5437,9 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
  22. break;
  23. } else if (ret == SSL_ERROR_ZERO_RETURN)
  24. goto read0;
  25. - /* For SSL_ERROR_SYSCALL, make sure the error is
  26. - * unrecoverable before flagging the connection as
  27. - * in error.
  28. - */
  29. + /* For SSL_ERROR_SYSCALL, make sure to clear the error
  30. + * stack before shutting down the connection for
  31. + * reading. */
  32. if (ret == SSL_ERROR_SYSCALL && (!errno || errno == EAGAIN))
  33. goto clear_ssl_error;
  34. /* otherwise it's a real error */
  35. @@ -5453,16 +5452,19 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
  36. conn_cond_update_sock_polling(conn);
  37. return done;
  38. + clear_ssl_error:
  39. + /* Clear openssl global errors stack */
  40. + ssl_sock_dump_errors(conn);
  41. + ERR_clear_error();
  42. read0:
  43. conn_sock_read0(conn);
  44. goto leave;
  45. +
  46. out_error:
  47. conn->flags |= CO_FL_ERROR;
  48. -clear_ssl_error:
  49. /* Clear openssl global errors stack */
  50. ssl_sock_dump_errors(conn);
  51. ERR_clear_error();
  52. -
  53. goto leave;
  54. }
  55. --
  56. 1.7.10.4