Skip to content

Commit 60f83dc

Browse files
jukkarjhedberg
authored andcommitted
net: Do not access possibly freed net_pkt
As the net_pkt might have already been sent by net_if_try_send_data() function, the pkt might already contain garbage data. So do not try to access if after that send call but remember the used iface and family and use them to update the statistics. The issue was seen with qemu_x86_64 and qemu_cortex_a53 when CONFIG_SMP was enabled. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 6a95243 commit 60f83dc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

subsys/net/ip/net_core.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ static inline bool process_multicast(struct net_pkt *pkt)
366366

367367
int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
368368
{
369+
struct net_if *iface;
370+
int family;
369371
int status;
370372
int ret;
371373

@@ -439,18 +441,27 @@ int net_try_send_data(struct net_pkt *pkt, k_timeout_t timeout)
439441
}
440442
#endif
441443

444+
/* The pkt might contain garbage already after the call to
445+
* net_if_try_send_data(), so do not use pkt after that call.
446+
* Remember the iface and family for statistics update.
447+
*/
448+
if (IS_ENABLED(CONFIG_NET_STATISTICS)) {
449+
iface = net_pkt_iface(pkt);
450+
family = net_pkt_family(pkt);
451+
}
452+
442453
if (net_if_try_send_data(net_pkt_iface(pkt), pkt, timeout) == NET_DROP) {
443454
ret = -EIO;
444455
goto err;
445456
}
446457

447458
if (IS_ENABLED(CONFIG_NET_STATISTICS)) {
448-
switch (net_pkt_family(pkt)) {
459+
switch (family) {
449460
case AF_INET:
450-
net_stats_update_ipv4_sent(net_pkt_iface(pkt));
461+
net_stats_update_ipv4_sent(iface);
451462
break;
452463
case AF_INET6:
453-
net_stats_update_ipv6_sent(net_pkt_iface(pkt));
464+
net_stats_update_ipv6_sent(iface);
454465
break;
455466
}
456467
}

0 commit comments

Comments
 (0)