-
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
Re-alignment logic in LwIPReceiveUDPMessage() makes incorrect assumptions #17213
Comments
kpschoedel
added a commit
to kpschoedel/connectedhomeip
that referenced
this issue
Jun 3, 2022
#### Problem Some UDPEndPoint implementation code assumes that IPPacketInfo is aligned to 4 bytes, when storing one inside PacketBuffer reserved space. It would also fail to identify the available reserve if there was enough space, but less that 3 bytes more than enough. See project-chip#17213 Re-alignment logic makes incorrect assumptions #### Change overview Adds a PacketBuffer::GetReserve<T>() that returns a pointer in the buffer reserve space suitable in size and alignment for a T, and uses it for `GetPacketInfo()` in `UDPEndPointImplLwIP` and `UDPEndPointImplOT`. #### Testing Added a unit test, `PacketBufferTest::CheckGetReserve()`.
kpschoedel
added a commit
to kpschoedel/connectedhomeip
that referenced
this issue
Jun 6, 2022
#### Problem Some UDPEndPoint implementation code assumes that IPPacketInfo is aligned to 4 bytes, when storing one inside PacketBuffer reserved space. It would also fail to identify the available reserve if there was enough space, but less that 3 bytes more than enough. See project-chip#17213 Re-alignment logic makes incorrect assumptions #### Change overview Adds a PacketBuffer::GetReserve<T>() that returns a pointer in the buffer reserve space suitable in size and alignment for a T, and uses it for `GetPacketInfo()` in `UDPEndPointImplLwIP` and `UDPEndPointImplOT`. #### Testing Added a unit test, `PacketBufferTest::CheckGetReserve()`.
kpschoedel
added a commit
to kpschoedel/connectedhomeip
that referenced
this issue
Jun 6, 2022
#### Problem Some UDPEndPoint implementation code assumes that IPPacketInfo is aligned to 4 bytes, when storing one inside PacketBuffer reserved space. It would also fail to identify the available reserve if there was enough space, but less that 3 bytes more than enough. See project-chip#17213 Re-alignment logic makes incorrect assumptions #### Change overview Adds a PacketBuffer::GetReserve<T>() that returns a pointer in the buffer reserve space suitable in size and alignment for a T, and uses it for `GetPacketInfo()` in `UDPEndPointImplLwIP` and `UDPEndPointImplOT`. #### Testing Added a unit test, `PacketBufferTest::CheckGetReserve()`.
kpschoedel
added a commit
to kpschoedel/connectedhomeip
that referenced
this issue
Jun 6, 2022
#### Problem Some UDPEndPoint implementation code assumes that IPPacketInfo is aligned to 4 bytes, when storing one inside PacketBuffer reserved space. It would also fail to identify the available reserve if there was enough space, but less that 3 bytes more than enough. See project-chip#17213 Re-alignment logic makes incorrect assumptions #### Change overview Adds a PacketBuffer::GetReserve<T>() that returns a pointer in the buffer reserve space suitable in size and alignment for a T, and uses it for `GetPacketInfo()` in `UDPEndPointImplLwIP` and `UDPEndPointImplOT`. #### Testing Added a unit test, `PacketBufferTest::CheckGetReserve()`.
andy31415
pushed a commit
that referenced
this issue
Jun 7, 2022
* Fix alignment when using PacketBuffer reserve space #### Problem Some UDPEndPoint implementation code assumes that IPPacketInfo is aligned to 4 bytes, when storing one inside PacketBuffer reserved space. It would also fail to identify the available reserve if there was enough space, but less that 3 bytes more than enough. See #17213 Re-alignment logic makes incorrect assumptions #### Change overview Adds a PacketBuffer::GetReserve<T>() that returns a pointer in the buffer reserve space suitable in size and alignment for a T, and uses it for `GetPacketInfo()` in `UDPEndPointImplLwIP` and `UDPEndPointImplOT`. #### Testing Added a unit test, `PacketBufferTest::CheckGetReserve()`. * Use EnsureReservedSize()
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This stale issue has been automatically closed. Thank you for your contributions. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
In
UDPEndPointImplLwIP::GetPacketInfo
, there is a check ofif (!aBuffer->EnsureReservedSize(sizeof(IPPacketInfo) + 3))
which implies desire to re-align. However, the code makes assumptions about the remaining use of the information consumed until now.GetPacketInfo()
returns a pointer to "loose data" before the actual payload, which is first gotten to set the info.It is first used in the chain in
UDPEndPointImplLwIP::LwIPReceiveUDPMessage()
:Then it's used to get the data elsewhere:
The re-alignment logic makes 2 bad assumptions that no longer hold at this point in Matter
1- That the platform is 32 bits
2- That the size of the struct
IPPacketInfo
will always fit within the "consumed IP header space" from before, which implies we do not growIPPacketInfo
too muchProposed Solution
sizeof(IPPacketInfo)
is < the minimum set of headers one could receiveThe text was updated successfully, but these errors were encountered: