Skip to content

Conversation

@EvgeniiMekhanik
Copy link
Contributor

There was a memory leak if tfw_connection_recv
fails with T_BAD in tfw_tls_connection_recv - because we continue to process skbs in this case but don't call tfw_connection_recvand do not free skbs. But if error occurs we should decrypt skbs and pass it totfw_connection_recv` to process WINDOW_UPDATE frames (it is necessary to send
custom error responses with long body).
Also fix some replated problems:

  • we should check Conn_Shutdown bit in all places where we check Conn_Stop bit to prevent processing any other frames.
  • we should continue to process frames if tfw_http_msg_process_generic fails same as we do it in tls.c.
  • add ALLOW_ERROR_INJECTION marso to check fixes.

Closes #2149 #2117

@EvgeniiMekhanik EvgeniiMekhanik requested review from const-t and krizhanovsky and removed request for krizhanovsky October 8, 2024 16:25
@EvgeniiMekhanik EvgeniiMekhanik marked this pull request as draft October 8, 2024 17:45
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-2149 branch from 0c01528 to 9ba0c85 Compare October 9, 2024 12:03
@EvgeniiMekhanik EvgeniiMekhanik marked this pull request as ready for review October 9, 2024 12:29
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-2149 branch from 9ba0c85 to bb894ad Compare October 10, 2024 15:06
Copy link
Contributor

@const-t const-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks correct, but I must notice TFW_CONN_PROCESS_RESULT is confusing and does implicit return. Maybe we would rewrite it?

@krizhanovsky
Copy link
Contributor

krizhanovsky commented Oct 13, 2024

It seems the only test we have for this is tempesta-tech/tempesta-test#615 , which tests other HTTP/2 floods. So it seems we're going to merge this with no any tests. @RomanBelozerov @EvgeniiMekhanik can we enable at least part of the test PR to test this memory leak?

@EvgeniiMekhanik could you please also check if the issue #1940 (comment) still exists and update the #1940 status for this fix.

Copy link
Contributor

@krizhanovsky krizhanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, looks good, but I ask @ai-tmpst to review this as well since the code isn't trivial and still could have non-obvious problems

fw/connection.h Outdated
* responses to client. We should continue to process \
* WINDOW_UPDATE frames so, we should decrypt all skbs, \
* not drop them. \
*/ \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment is misaligned

fw/connection.h Outdated
if (extra_cond_to_out) { \
kfree_skb(nskb); \
goto out; \
} \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is used only in http_frame.c

fw/http_frame.c Outdated
* and can immediately close connection.
*/
TFW_CONN_PROCESS_RESULT(r, was_stopped,
!(TFW_CONN_TYPE(c) & Conn_Stop), nskb);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tfw_http_msg_process_generic() and TFW_CONN_PROCESS_RESULT() are identical, so instead of the macro we can just introduce a function to call tfw_http_msg_process_generic() and process the result

fw/connection.h Outdated
} else if (save_err_code != T_OK) { \
r = save_err_code; \
} \
} while(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro isn't really generic and treats result of different function in different way. We can reduce copy & paste in http_frame.c and I'm not sure about keeping such a macro just for 2, still bit different, code places. Personally I'd prefer just to reference the each other code in comment.

@EvgeniiMekhanik EvgeniiMekhanik marked this pull request as draft October 14, 2024 15:22
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-2149 branch 3 times, most recently from 0651a08 to 8c9d48a Compare October 14, 2024 21:54
@EvgeniiMekhanik EvgeniiMekhanik marked this pull request as ready for review October 14, 2024 22:05
return (TFW_CONN_TYPE(conn) & Conn_Stop) &&
(!((TFW_CONN_TYPE(conn) & Conn_H2Clnt) == Conn_H2Clnt));
return (tfw_connection_was_stopped(conn)
&& (!((TFW_CONN_TYPE(conn) & Conn_H2Clnt) == Conn_H2Clnt)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!((TFW_CONN_TYPE(conn) & Conn_H2Clnt) == Conn_H2Clnt)
Couldn't it be reduced to !((TFW_CONN_TYPE(conn) & Conn_H2Clnt)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because Conn_H2Clnt = 2 | TFW_FSM_HTTPS, so !((TFW_CONN_TYPE(conn) & Conn_H2Clnt) is false for H2 connections but it also false for https connection. But we should not process anything if error occurs in https connection. For http2 connection we should do it because we should process window_update frames from the client to have ability to send error response with body

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, it's not a one-bit flag. Sorry, I should look at it by myself.

@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-2149 branch from 8c9d48a to f393ea3 Compare October 17, 2024 14:47
There was a memory leak if `tfw_connection_recv`
fails with T_BAD in `tfw_tls_connection_recv -
because we continue to process skbs in this case
but don't call `tfw_connection_recv` and do not
free skbs. But if error occurs we should decrypt
skbs and pass it to `tfw_connection_recv` to process
WINDOW_UPDATE frames (it is necessary to send
custom error responses with long body).
Also fix some replated problems:
- we should check Conn_Shutdown bit in all places
where we check Conn_Stop bit to prevent processing any
other frames.
- we should continue to process frames if
`tfw_http_msg_process_generic` fails same as we do it
in tls.c.
- add ALLOW_ERROR_INJECTION marso to check fixes.

Closes #2149 #2117
- Split `TFW_CONN_PROCESS_RESULT` into two part
  first part is used in tls.c. Second part is a
  new macro `TFW_H2_CONN_PROCESS_RESULT` is
  defined in `tfw_h2_frame_process` and used only
  in this function.
- Add WARN_ON_ONCE to check that `next` pointer is
  always zero for HTTP2 requests after calling
  `tfw_http_msg_process_generic` (see also existing
  appropriate warning in `tfw_http_req_process`.
- Align `streams_num_exceeded` statistic.
@EvgeniiMekhanik EvgeniiMekhanik force-pushed the MekhanikEvgenii/fix-2149 branch from f393ea3 to 717cbd0 Compare October 17, 2024 15:48
@krizhanovsky krizhanovsky merged commit fe21386 into master Oct 18, 2024
@krizhanovsky krizhanovsky deleted the MekhanikEvgenii/fix-2149 branch October 18, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak found in ping flood

5 participants