Skip to content

Commit

Permalink
net: ethernet: Check that header is valid
Browse files Browse the repository at this point in the history
Saw this crash with heavily loaded system in mimxrt1050_evk:

<err> os: ***** MPU FAULT *****
<err> os:   Data Access Violation
<err> os:   MMFAR Address: 0xc
<err> os: r0/a1:  0x80000ab0  r1/a2:  0x800f6a60  r2/a3:  0x00000000
<err> os: r3/a4:  0x800f72a0 r12/ip:  0x00000000 r14/lr:  0x6000eb43
<err> os:  xpsr:  0x41000000
<err> os: Faulting instruction address (r15/pc): 0x6000dc82
<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
<err> os: Current thread: 0x80001a18 (rx_workq)
<err> os: Halting system

Where the fault at 0x6000dc82 points to ethernet_recv()

	uint16_t type = ntohs(hdr->type);
6000dc82:	89ab      	ldrh	r3, [r5, zephyrproject-rtos#12]

Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar committed Sep 28, 2020
1 parent baf83c2 commit be072b1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion subsys/net/l2/ethernet/ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,16 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
struct ethernet_context *ctx = net_if_l2_data(iface);
struct net_eth_hdr *hdr = NET_ETH_HDR(pkt);
uint8_t hdr_len = sizeof(struct net_eth_hdr);
uint16_t type = ntohs(hdr->type);
uint16_t type;
struct net_linkaddr *lladdr;
sa_family_t family;

if (hdr == NULL) {
goto drop;
}

type = ntohs(hdr->type);

if (net_eth_is_vlan_enabled(ctx, iface) &&
type == NET_ETH_PTYPE_VLAN &&
!eth_is_vlan_tag_stripped(iface)) {
Expand Down

0 comments on commit be072b1

Please sign in to comment.