Skip to content

Commit 621e84d

Browse files
NicolasDichteldavem330
authored andcommitted
dev: introduce skb_scrub_packet()
The goal of this new function is to perform all needed cleanup before sending an skb into another netns. Signed-off-by: Nicolas Dichtel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 38ae92d commit 621e84d

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

include/linux/skbuff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,7 @@ extern void skb_split(struct sk_buff *skb,
23842384
struct sk_buff *skb1, const u32 len);
23852385
extern int skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
23862386
int shiftlen);
2387+
extern void skb_scrub_packet(struct sk_buff *skb);
23872388

23882389
extern struct sk_buff *skb_segment(struct sk_buff *skb,
23892390
netdev_features_t features);

net/core/dev.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,22 +1652,13 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
16521652
}
16531653
}
16541654

1655-
skb_orphan(skb);
1656-
16571655
if (unlikely(!is_skb_forwardable(dev, skb))) {
16581656
atomic_long_inc(&dev->rx_dropped);
16591657
kfree_skb(skb);
16601658
return NET_RX_DROP;
16611659
}
1662-
skb->skb_iif = 0;
1663-
skb_dst_drop(skb);
1664-
skb->tstamp.tv64 = 0;
1665-
skb->pkt_type = PACKET_HOST;
1660+
skb_scrub_packet(skb);
16661661
skb->protocol = eth_type_trans(skb, dev);
1667-
skb->mark = 0;
1668-
secpath_reset(skb);
1669-
nf_reset(skb);
1670-
nf_reset_trace(skb);
16711662
return netif_rx(skb);
16721663
}
16731664
EXPORT_SYMBOL_GPL(dev_forward_skb);

net/core/skbuff.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,3 +3492,26 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
34923492
return true;
34933493
}
34943494
EXPORT_SYMBOL(skb_try_coalesce);
3495+
3496+
/**
3497+
* skb_scrub_packet - scrub an skb before sending it to another netns
3498+
*
3499+
* @skb: buffer to clean
3500+
*
3501+
* skb_scrub_packet can be used to clean an skb before injecting it in
3502+
* another namespace. We have to clear all information in the skb that
3503+
* could impact namespace isolation.
3504+
*/
3505+
void skb_scrub_packet(struct sk_buff *skb)
3506+
{
3507+
skb_orphan(skb);
3508+
skb->tstamp.tv64 = 0;
3509+
skb->pkt_type = PACKET_HOST;
3510+
skb->skb_iif = 0;
3511+
skb_dst_drop(skb);
3512+
skb->mark = 0;
3513+
secpath_reset(skb);
3514+
nf_reset(skb);
3515+
nf_reset_trace(skb);
3516+
}
3517+
EXPORT_SYMBOL_GPL(skb_scrub_packet);

0 commit comments

Comments
 (0)