Skip to content

Commit c736a26

Browse files
jsitnickiKernel Patches Daemon
authored andcommitted
bpf: Make bpf_skb_vlan_push helper metadata-safe
Use the metadata-aware helper to move packet bytes after skb_push(), ensuring metadata remains valid after calling the BPF helper. Also, take care to reserve sufficient headroom for metadata to fit. Signed-off-by: Jakub Sitnicki <[email protected]>
1 parent 4f9db60 commit c736a26

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/linux/if_vlan.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,17 @@ static inline int __vlan_insert_inner_tag(struct sk_buff *skb,
355355
__be16 vlan_proto, u16 vlan_tci,
356356
unsigned int mac_len)
357357
{
358+
const u8 meta_len = mac_len > ETH_TLEN ? skb_metadata_len(skb) : 0;
358359
struct vlan_ethhdr *veth;
359360

360-
if (skb_cow_head(skb, VLAN_HLEN) < 0)
361+
if (skb_cow_head(skb, meta_len + VLAN_HLEN) < 0)
361362
return -ENOMEM;
362363

363364
skb_push(skb, VLAN_HLEN);
364365

365366
/* Move the mac header sans proto to the beginning of the new header. */
366367
if (likely(mac_len > ETH_TLEN))
367-
memmove(skb->data, skb->data + VLAN_HLEN, mac_len - ETH_TLEN);
368+
skb_postpush_data_move(skb, VLAN_HLEN, mac_len - ETH_TLEN);
368369
if (skb_mac_header_was_set(skb))
369370
skb->mac_header -= VLAN_HLEN;
370371

0 commit comments

Comments
 (0)