Skip to content

Commit

Permalink
net: ip: Fix for improper offset return by net_pkt_find_offset()
Browse files Browse the repository at this point in the history
The original packet's link-layer destination and source address can be
stored in separately allocated memory. This allocated memory can be
placed just after pkt data buffers.
In case when `net_pkt_find_offset()` uses condition:
`if (buf->data <= ptr && ptr <= (buf->data + buf->len)) {`
the offset is set outside the packet's buffer and the function returns
incorrect offset instead of error code.
Finally the offset is used to set ll address in cloned packet, and
this can have unexpected behavior (e.g. crash when cursor will be set
to empty memory).

Signed-off-by: Marcin Gasiorek <[email protected]>
(cherry picked from commit fb99f65)
  • Loading branch information
MarGasiorek authored and github-actions[bot] committed Mar 6, 2024
1 parent 0de7085 commit b517a80
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subsys/net/ip/net_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ static int32_t net_pkt_find_offset(struct net_pkt *pkt, uint8_t *ptr)
buf = pkt->buffer;

while (buf) {
if (buf->data <= ptr && ptr <= (buf->data + buf->len)) {
if (buf->data <= ptr && ptr < (buf->data + buf->len)) {
ret = offset + (ptr - buf->data);
break;
}
Expand Down

0 comments on commit b517a80

Please sign in to comment.