-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test OOM by control frames attack #615
Open
kingluo
wants to merge
11
commits into
master
Choose a base branch
from
jinhua/fix-1346-flood
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+196
−1
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
681847e
test OOM by control frames attack
kingluo 157f796
correct code
kingluo 63e2a8c
trivial fix
kingluo 9b306ee
fix PR
kingluo 5ac7312
update tests_disabled_tcpseg.json
kingluo 5dcb07f
rework http2 flood tests:
RomanBelozerov 37a67e1
move and rename `test_flood.py` from `t_stress/test_flood.py` to `htt…
RomanBelozerov bc02233
add assert message and disable net_ratelimit.
RomanBelozerov a7c2473
rename __fill_tcp_buffer_and_disable_readable
kingluo fcd22dc
improve the stability of tests
RomanBelozerov b8096d4
increase max_concurrent_streams due to http2 stream prioritization re…
kingluo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
"""The functional tests for `max_queued_control_frames` directive.""" | ||
|
||
__author__ = "Tempesta Technologies, Inc." | ||
__copyright__ = "Copyright (C) 2024 Tempesta Technologies, Inc." | ||
__license__ = "GPL2" | ||
|
||
import socket | ||
import time | ||
|
||
from h2.settings import SettingCodes | ||
from hyperframe.frame import HeadersFrame, PingFrame, PriorityFrame, SettingsFrame | ||
|
||
from framework import tester | ||
from framework.parameterize import param, parameterize | ||
from helpers import dmesg | ||
|
||
|
||
class TestH2ControlFramesFlood(tester.TempestaTest): | ||
clients = [ | ||
{ | ||
"id": "deproxy", | ||
"type": "deproxy_h2", # "deproxy" for HTTP/1 | ||
"addr": "${tempesta_ip}", | ||
"port": "443", | ||
"ssl": True, | ||
"ssl_hostname": "tempesta-tech.com", | ||
}, | ||
] | ||
|
||
backends = [ | ||
{ | ||
"id": "deproxy", | ||
"type": "deproxy", | ||
"port": "8000", | ||
"response": "static", | ||
"response_content": ( | ||
"HTTP/1.1 200 OK\r\n" + "Content-Length: 200000\r\n\r\n" + ("a" * 200000) | ||
), | ||
} | ||
] | ||
|
||
tempesta = { | ||
"config": """ | ||
keepalive_timeout 1000; | ||
listen 443 proto=h2; | ||
max_concurrent_streams 20000; | ||
|
||
tls_match_any_server_name; | ||
|
||
srv_group default { | ||
server ${server_ip}:8000; | ||
} | ||
%s | ||
vhost tempesta-tech.com { | ||
tls_certificate ${tempesta_workdir}/tempesta.crt; | ||
tls_certificate_key ${tempesta_workdir}/tempesta.key; | ||
proxy_pass default; | ||
} | ||
""" | ||
} | ||
|
||
def __update_tempesta_config(self, limit: int) -> None: | ||
limit = "" if limit == 10000 else f"max_queued_control_frames {limit};" | ||
self.get_tempesta().config.defconfig = self.get_tempesta().config.defconfig % limit | ||
|
||
def __init_connection_and_disable_readable(self, client) -> None: | ||
client.update_initial_settings() | ||
client.send_bytes(client.h2_connection.data_to_send()) | ||
self.assertTrue(client.wait_for_ack_settings()) | ||
|
||
client.make_request(client.create_request(method="GET", headers=[])) | ||
client.readable = lambda: False # disable socket for reading | ||
|
||
@parameterize.expand( | ||
[ | ||
param( | ||
name="ping", | ||
frame=PingFrame(0, b"\x00\x01\x02\x03\x04\x05\x06\x07").serialize(), | ||
), | ||
param( | ||
name="settings", | ||
frame=SettingsFrame( | ||
settings={k: 100 for k in (SettingCodes.MAX_CONCURRENT_STREAMS,)} | ||
).serialize(), | ||
), | ||
] | ||
) | ||
@dmesg.unlimited_rate_on_tempesta_node | ||
def test(self, name, frame): | ||
self.__update_tempesta_config(100) | ||
|
||
client = self.get_client("deproxy") | ||
# Set a small buffer for the client. it is needed for stability of tests. | ||
# The different VMs have a different size of buffer | ||
client.add_socket_options(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024) | ||
|
||
self.start_all_services() | ||
# requests a large data from backend and disable socket for reading. | ||
# Tempesta can not send any data to the client until the client enable socket for reading | ||
self.__init_connection_and_disable_readable(client) | ||
|
||
# wait until the client buffer is full | ||
time.sleep(2) | ||
|
||
# the client should send more frames for stability of test | ||
for _ in range(110): # max_queued_control_frames is 100. | ||
client.send_bytes(frame, expect_response=False) | ||
|
||
self.assertTrue( | ||
self.oops.find( | ||
"Warning: Too many control frames in send queue, closing connection", | ||
dmesg.amount_positive, | ||
), | ||
"An unexpected number of dmesg warnings", | ||
) | ||
client.readable = lambda: True # enable socket for reading | ||
self.assertTrue( | ||
client.wait_for_connection_close(), | ||
"TempestaFW did not block client after exceeding `max_queued_control_frames` limit.", | ||
) | ||
|
||
@parameterize.expand( | ||
[ | ||
param(name="default_limit", limit=10000), | ||
param(name="100_limit", limit=100), | ||
] | ||
) | ||
@dmesg.unlimited_rate_on_tempesta_node | ||
def test_reset_stream(self, name, limit: int): | ||
self.__update_tempesta_config(limit) | ||
|
||
client = self.get_client("deproxy") | ||
# Set a small buffer for the client. it is needed for stability of tests. | ||
# The different VMs have a different size of buffer | ||
client.add_socket_options(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024) | ||
|
||
self.start_all_services() | ||
# requests a large data from backend and disable socket for reading. | ||
# Tempesta can not send any data to the client until the client enable socket for reading | ||
self.__init_connection_and_disable_readable(client) | ||
|
||
# wait until the client buffer is full | ||
time.sleep(2) | ||
|
||
headers = [ | ||
(":method", "GET"), | ||
(":path", "/"), | ||
(":authority", "tempesta-tech.com"), | ||
(":scheme", "https"), | ||
] | ||
|
||
# the client should send more frames for stability of test | ||
for i in range(3, int(limit * 2.2), 2): | ||
hf = HeadersFrame( | ||
stream_id=i, | ||
data=client.h2_connection.encoder.encode(headers), | ||
flags=["END_HEADERS"], | ||
).serialize() | ||
prio = PriorityFrame(stream_id=i, depends_on=i).serialize() | ||
client.send_bytes(hf + prio, expect_response=False) | ||
|
||
self.assertTrue( | ||
self.oops.find( | ||
"Warning: Too many control frames in send queue, closing connection", | ||
dmesg.amount_positive, | ||
), | ||
"An unexpected number of dmesg warnings", | ||
) | ||
client.readable = lambda: True # enable socket for reading | ||
self.assertTrue( | ||
client.wait_for_connection_close(), | ||
"TempestaFW did not block client after exceeding `max_queued_control_frames` limit.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to request a large response now, because the sockbuf is already set to a small enough size. Also we don't need the backend, because control-frame-slow-read does not involve the backend.