Skip to contentSkip to conversation

Can we rely on ethernet header padding?

DISCUSSION Michal Kubecek 3 participants 5 messages Mar 19, 2013 – Mar 20, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hello,

a customer of ours ran into

http://bugzilla.netfilter.org/show_bug.cgi?id=765

They checked that commit a504b86e prevents the crash but I'm not sure it is sufficient.

The crash happens when br_nf_pre_routing_finish_bridge() calls neigh_hh_bridge() which copies not only destination MAC address but also the padding with it. IIUC this is for performance reasons (so that aligned 8 bytes are copied rather than 6).

But I wonder whether we can rely on the fact that every skb on an ethernet-like device has ethernet header padded at least to the 16 bytes expected by neigh_hh_bridge() and neigh_hh_output() or whether the bridge code should make sure. I tried to look for such test but couldn't find any, even if commit a504b86e description mentions reallocating the skb rather than a crash.

Thanks in advance,
Michal Kubecek

#1 lore raw
Quoted 14 lines · Michal Kubecek

Hello,

a customer of ours ran into

http://bugzilla.netfilter.org/show_bug.cgi?id=765

They checked that commit a504b86e prevents the crash but I'm not sure it is sufficient.

The crash happens when br_nf_pre_routing_finish_bridge() calls neigh_hh_bridge() which copies not only destination MAC address but also the padding with it. IIUC this is for performance reasons (so that aligned 8 bytes are copied rather than 6).

Quoted 6 lines

But I wonder whether we can rely on the fact that every skb on an ethernet-like device has ethernet header padded at least to the 16 bytes expected by neigh_hh_bridge() and neigh_hh_output() or whether the bridge code should make sure. I tried to look for such test but couldn't find any, even if commit a504b86e description mentions reallocating the skb rather than a crash.

Thats a side effect.

Before calling netif_rx() the driver usually calls eth_type_trans() to pull the ethernet header, so there is the room for 14 bytes.

Normally a driver has NET_SKB_PAD bytes of headroom before the ethernet header, so the bridge code is safe only if all drivers use this NET_SKB_PAD padding on receive side. And they really should for performance reasons.

Better not touch bridge code to catch offending drivers

#2 lore raw
Quoted 7 lines · Eric Dumazet

Normally a driver has NET_SKB_PAD bytes of headroom before the ethernet header, so the bridge code is safe only if all drivers use this NET_SKB_PAD padding on receive side. And they really should for performance reasons.

Better not touch bridge code to catch offending drivers

That makes sense. Thank you for your reply.

Michal Kubecek

#3 lore raw
Quoted 11 lines · On Tue, 19 Mar 2013 16:48:06 +0100 Michal Kubecek <[email protected]> wrote:
Quoted 7 lines · Eric Dumazet

Normally a driver has NET_SKB_PAD bytes of headroom before the ethernet header, so the bridge code is safe only if all drivers use this NET_SKB_PAD padding on receive side. And they really should for performance reasons.

Better not touch bridge code to catch offending drivers

That makes sense. Thank you for your reply.

My view is that the bridge code must check before assuming headroom. But because of that, it means a packet copy would be necessary for cases where packets arrive without enough headroom.

#4 lore raw
Quoted 4 lines · Stephen Hemminger

My view is that the bridge code must check before assuming headroom. But because of that, it means a packet copy would be necessary for cases where packets arrive without enough headroom.

Yes, but for most users this is better than a crash. How about issuing a WARN_ONCE() in such case so that we avoid writing out of the buffer but still allow developers (and users who check logs) to catch the problem?

Michal Kubecek