Skip to content

Commit c684dab

Browse files
glarsennordichenrikbrixandersen
authored andcommitted
net: net_if: fix net_if_send_data for offloaded ifaces
Some offloaded ifaces have an L2, but lack support for net_l2->send. This edge case is not handled by net_if_send_data, resulting in a NULL dereference under rare circumstances. This patch expands the offloaded iface guard in net_if_send_data to handle this edge case. Signed-off-by: Georges Oates_Larsen <[email protected]> (cherry picked from commit 1c79445)
1 parent 7c5e43a commit c684dab

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

subsys/net/ip/net_if.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ static inline void init_iface(struct net_if *iface)
435435

436436
enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
437437
{
438+
const struct net_l2 *l2;
438439
struct net_context *context = net_pkt_context(pkt);
439440
struct net_linkaddr *dst = net_pkt_lladdr_dst(pkt);
440441
enum net_verdict verdict = NET_OK;
@@ -449,10 +450,24 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
449450
goto done;
450451
}
451452

452-
if (IS_ENABLED(CONFIG_NET_OFFLOAD) && !net_if_l2(iface)) {
453-
NET_WARN("no l2 for iface %p, discard pkt", iface);
454-
verdict = NET_DROP;
455-
goto done;
453+
/* The check for CONFIG_NET_*_OFFLOAD here is an optimization;
454+
* This is currently the only way for net_if_l2 to be NULL or missing send().
455+
*/
456+
if (IS_ENABLED(CONFIG_NET_OFFLOAD) || IS_ENABLED(CONFIG_NET_SOCKETS_OFFLOAD)) {
457+
l2 = net_if_l2(iface);
458+
if (l2 == NULL) {
459+
/* Offloaded ifaces may choose not to use an L2 at all. */
460+
NET_WARN("no l2 for iface %p, discard pkt", iface);
461+
verdict = NET_DROP;
462+
goto done;
463+
} else if (l2->send == NULL) {
464+
/* Or, their chosen L2 (for example, OFFLOADED_NETDEV_L2)
465+
* might simply not implement send.
466+
*/
467+
NET_WARN("l2 for iface %p cannot send, discard pkt", iface);
468+
verdict = NET_DROP;
469+
goto done;
470+
}
456471
}
457472

458473
/* If the ll address is not set at all, then we must set

0 commit comments

Comments
 (0)