Skip to content

Commit fa0bbaf

Browse files
icsys-aalcarlescufi
authored andcommitted
net: promiscuous: Fix crash in promiscuous mode
When a packet can't be cloned we crash as we try to initialize the cursor on a nullptr. We should check if we have a valid pointer, and if we don't we drop the packet along with a warning. Signed-off-by: Andreas Ålgård <[email protected]>
1 parent 47396e1 commit fa0bbaf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

subsys/net/ip/net_if.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -4145,12 +4145,15 @@ enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt)
41454145
/* L2 has modified the buffer starting point, it is easier
41464146
* to re-initialize the cursor rather than updating it.
41474147
*/
4148-
net_pkt_cursor_init(new_pkt);
4148+
if (new_pkt) {
4149+
net_pkt_cursor_init(new_pkt);
41494150

4150-
if (net_promisc_mode_input(new_pkt) == NET_DROP) {
4151-
net_pkt_unref(new_pkt);
4151+
if (net_promisc_mode_input(new_pkt) == NET_DROP) {
4152+
net_pkt_unref(new_pkt);
4153+
}
4154+
} else {
4155+
NET_WARN("promiscuous packet dropped, unable to clone packet");
41524156
}
4153-
41544157
net_pkt_unref(pkt);
41554158

41564159
return verdict;

0 commit comments

Comments
 (0)