diff mbox series

net: Check the expect of skb->data at mac header

Message ID 20200820122822.46608-1-linmiaohe@huawei.com
State Rejected
Delegated to: David Miller
Headers show
Series net: Check the expect of skb->data at mac header | expand

Commit Message

Miaohe Lin Aug. 20, 2020, 12:28 p.m. UTC
skb_mpls_push() and skb_mpls_pop() expect skb->data at mac header. Check
this assumption or we would get wrong mac_header and network_header.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 net/core/skbuff.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

David Miller Aug. 24, 2020, 10:49 p.m. UTC | #1
From: Miaohe Lin <linmiaohe@huawei.com>
Date: Thu, 20 Aug 2020 08:28:22 -0400

> skb_mpls_push() and skb_mpls_pop() expect skb->data at mac header. Check
> this assumption or we would get wrong mac_header and network_header.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Both openvswitch and act_mpls.c seem to adhere to this constraint.

I don't see real value to these extra checks, sorry.
diff mbox series

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index e18184ffa9c3..52d2ad54aa97 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5590,6 +5590,7 @@  static void skb_mod_eth_type(struct sk_buff *skb, struct ethhdr *hdr,
 int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
 		  int mac_len, bool ethernet)
 {
+	int offset = skb->data - skb_mac_header(skb);
 	struct mpls_shim_hdr *lse;
 	int err;
 
@@ -5600,6 +5601,9 @@  int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
 	if (skb->encapsulation)
 		return -EINVAL;
 
+	if (WARN_ONCE(offset, "We got skb with skb->data not at mac header (offset %d)\n", offset))
+		return -EINVAL;
+
 	err = skb_cow_head(skb, MPLS_HLEN);
 	if (unlikely(err))
 		return err;
@@ -5643,11 +5647,15 @@  EXPORT_SYMBOL_GPL(skb_mpls_push);
 int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
 		 bool ethernet)
 {
+	int offset = skb->data - skb_mac_header(skb);
 	int err;
 
 	if (unlikely(!eth_p_mpls(skb->protocol)))
 		return 0;
 
+	if (WARN_ONCE(offset, "We got skb with skb->data not at mac header (offset %d)\n", offset))
+		return -EINVAL;
+
 	err = skb_ensure_writable(skb, mac_len + MPLS_HLEN);
 	if (unlikely(err))
 		return err;