From fa0bbaf66cd66843f60a4ea9205e14fc17a6ea78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85lg=C3=A5rd?= Date: Mon, 18 Sep 2023 10:07:12 +0200 Subject: [PATCH] net: promiscuous: Fix crash in promiscuous mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- subsys/net/ip/net_if.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 828e48ecf78..d431cbf1334 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4145,12 +4145,15 @@ enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt) /* L2 has modified the buffer starting point, it is easier * to re-initialize the cursor rather than updating it. */ - net_pkt_cursor_init(new_pkt); + if (new_pkt) { + net_pkt_cursor_init(new_pkt); - if (net_promisc_mode_input(new_pkt) == NET_DROP) { - net_pkt_unref(new_pkt); + if (net_promisc_mode_input(new_pkt) == NET_DROP) { + net_pkt_unref(new_pkt); + } + } else { + NET_WARN("promiscuous packet dropped, unable to clone packet"); } - net_pkt_unref(pkt); return verdict;