You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.2 KiB

  1. commit 96b88f2e605e76f2a472cf9fa83398ff242d47bb
  2. Author: Christopher Faulet <cfaulet@haproxy.com>
  3. Date: Mon Sep 23 15:28:20 2019 +0200
  4. BUG/MAJOR: mux-h2: Handle HEADERS frames received after a RST_STREAM frame
  5. As stated in the RFC7540#5.1, an endpoint that receives any frame other than
  6. PRIORITY after receiving a RST_STREAM MUST treat that as a stream error of type
  7. STREAM_CLOSED. However, frames carrying compression state must still be
  8. processed before being dropped to keep the HPACK decoder synchronized. This had
  9. to be the purpose of the commit 8d9ac3ed8b ("BUG/MEDIUM: mux-h2: do not abort
  10. HEADERS frame before decoding them"). But, the test on the frame type was
  11. inverted.
  12. This bug is major because desynchronizing the HPACK decoder leads to mixup
  13. indexed headers in messages. From the time an HEADERS frame is received and
  14. ignored for a closed stream, wrong headers may be sent to the following streams.
  15. This patch may fix several bugs reported on github (#116, #290, #292). It must
  16. be backported to 2.0 and 1.9.
  17. (cherry picked from commit 6884aa3eb00d1a5eb6f9c81a3a00288c13652938)
  18. Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  19. diff --git a/src/mux_h2.c b/src/mux_h2.c
  20. index e6bfd03d..eb773a26 100644
  21. --- a/src/mux_h2.c
  22. +++ b/src/mux_h2.c
  23. @@ -2106,6 +2106,9 @@ static struct h2s *h2c_frt_handle_headers(struct h2c *h2c, struct h2s *h2s)
  24. */
  25. static struct h2s *h2c_bck_handle_headers(struct h2c *h2c, struct h2s *h2s)
  26. {
  27. + struct buffer rxbuf = BUF_NULL;
  28. + unsigned long long body_len = 0;
  29. + uint32_t flags = 0;
  30. int error;
  31. if (!b_size(&h2c->dbuf))
  32. @@ -2114,7 +2117,18 @@ static struct h2s *h2c_bck_handle_headers(struct h2c *h2c, struct h2s *h2s)
  33. if (b_data(&h2c->dbuf) < h2c->dfl && !b_full(&h2c->dbuf))
  34. return NULL; // incomplete frame
  35. - error = h2c_decode_headers(h2c, &h2s->rxbuf, &h2s->flags, &h2s->body_len);
  36. + if (h2s->st != H2_SS_CLOSED) {
  37. + error = h2c_decode_headers(h2c, &h2s->rxbuf, &h2s->flags, &h2s->body_len);
  38. + }
  39. + else {
  40. + /* the connection was already killed by an RST, let's consume
  41. + * the data and send another RST.
  42. + */
  43. + error = h2c_decode_headers(h2c, &rxbuf, &flags, &body_len);
  44. + h2s_error(h2s, H2_ERR_STREAM_CLOSED);
  45. + h2c->st0 = H2_CS_FRAME_E;
  46. + goto send_rst;
  47. + }
  48. /* unrecoverable error ? */
  49. if (h2c->st0 >= H2_CS_ERROR)
  50. @@ -2150,6 +2164,15 @@ static struct h2s *h2c_bck_handle_headers(struct h2c *h2c, struct h2s *h2s)
  51. }
  52. return h2s;
  53. +
  54. + send_rst:
  55. + /* make the demux send an RST for the current stream. We may only
  56. + * do this if we're certain that the HEADERS frame was properly
  57. + * decompressed so that the HPACK decoder is still kept up to date.
  58. + */
  59. + h2_release_buf(h2c, &rxbuf);
  60. + h2c->st0 = H2_CS_FRAME_E;
  61. + return h2s;
  62. }
  63. /* processes a DATA frame. Returns > 0 on success or zero on missing data.
  64. @@ -2459,7 +2482,7 @@ static void h2_process_demux(struct h2c *h2c)
  65. goto strm_err;
  66. }
  67. - if (h2s->flags & H2_SF_RST_RCVD && h2_ft_bit(h2c->dft) & H2_FT_HDR_MASK) {
  68. + if (h2s->flags & H2_SF_RST_RCVD && !(h2_ft_bit(h2c->dft) & H2_FT_HDR_MASK)) {
  69. /* RFC7540#5.1:closed: an endpoint that
  70. * receives any frame other than PRIORITY after
  71. * receiving a RST_STREAM MUST treat that as a