-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update buffer allocation strategy and maximum buffer size when using TCP as transport #30404
Conversation
PR #30404: Size comparison from dbd6d1d to a419234 Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
PR #30404: Size comparison from dbd6d1d to 0bad674 Increases above 0.2%:
Increases (71 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, nrfconnect, psoc6, qpg, telink)
Decreases (5 builds for cc32xx, linux, mbed)
Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
@@ -47,10 +47,11 @@ namespace SecureMessageCodec { | |||
* @param msgBuf The message buffer that contains the unencrypted message. If | |||
* the operation is successful, this buffer will be mutated to contain | |||
* the encrypted message. | |||
* @param inputMaxLength Max size for input |
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.
What is the point of this argument? Why wouldn't callers just pass msgBuf->TotalLength()
for it?
Either this argument should not exist, or the documentation needs to do a much better job of explaining what this is for and how it should be used.
My temptation is towards the former: why does the crypto stuff care about this length? It doesn't.
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.
so this argument is meant to provide the method the maximum length of payload's length
that means we can't just pass msgBuf->TotalLength() because that would bypass the check :) , i think this place is okay since that check is common for all the places that's calling SecureMessageCodec::Encrypt(
PR #30404: Size comparison from 5fd93c4 to f0609dc Increases (71 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, nrfconnect, psoc6, qpg, stm32, telink)
Decreases (3 builds for bl702l, linux)
Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, stm32, telink)
|
@@ -237,7 +238,17 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P | |||
NodeId sourceNodeId = session->GetLocalScopedNodeId().GetNodeId(); | |||
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), messageCounter, sourceNodeId); | |||
|
|||
ReturnErrorOnFailure(SecureMessageCodec::Encrypt(session->GetCryptoContext(), nonce, payloadHeader, packetHeader, message)); | |||
if (session->GetPeerAddress().GetTransportType() == Transport::Type::kTcp) |
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.
Instead of passing the max size into Encrypt() by having this logic here, a better approach might be to have a utility function hanging off the Session that returns this. It could be in the Session object or could also be in the SessionManager, potentially. That utility can be called from inside Encrypt(and elsewhere) for checks.
@@ -71,6 +71,8 @@ static_assert(detail::kMaxApplicationPayloadAndMICSizeBytes > kMaxTagLen, "Need | |||
// tag we will not have source/destination node IDs, but above we are including | |||
// those in the header sizes. | |||
static constexpr size_t kMaxAppMessageLen = detail::kMaxApplicationPayloadAndMICSizeBytes - kMaxTagLen; | |||
// large payload limit | |||
static constexpr size_t kLargePayloadMaxMessageSizeBytes = 128000; |
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.
Have added a ''CHIP_CONFIG_MAX_TCP_PAYLOAD_SIZE_BYTES 1000000" in a TCPConfig.h file as part of #30339
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Old PR with changes requested and merge conflicts. Assuming stale and closing. |
Depending on the transport choice, the node would have to be able to allocate buffers appropriately. When TCP is supported, buffer allocation would be done from the heap. That choice is made at compile time. However, the max size of the heap-allocated buffer would differ based on whether the node is using MRP or TCP underneath, at run time. We would need a dynamic way to choose that max buffer size allocation so that a larger allocation can be made from the heap when using TCP.
Fixes #29698