lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240711070828.2741351-2-boris.sukholitko@broadcom.com>
Date: Thu, 11 Jul 2024 10:08:27 +0300
From: Boris Sukholitko <boris.sukholitko@...adcom.com>
To: netdev@...r.kernel.org,
	Alexei Starovoitov <ast@...nel.org>,
	Daniel Borkmann <daniel@...earbox.net>,
	Andrii Nakryiko <andrii@...nel.org>,
	Martin KaFai Lau <martin.lau@...ux.dev>,
	Eduard Zingerman <eddyz87@...il.com>,
	Song Liu <song@...nel.org>,
	Yonghong Song <yonghong.song@...ux.dev>,
	John Fastabend <john.fastabend@...il.com>,
	KP Singh <kpsingh@...nel.org>,
	Stanislav Fomichev <sdf@...ichev.me>,
	Hao Luo <haoluo@...gle.com>,
	Jiri Olsa <jolsa@...nel.org>,
	"David S . Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	Pravin B Shelar <pshelar@....org>,
	Jamal Hadi Salim <jhs@...atatu.com>,
	Cong Wang <xiyou.wangcong@...il.com>,
	Jiri Pirko <jiri@...nulli.us>,
	Willem de Bruijn <willemb@...gle.com>,
	Simon Horman <horms@...nel.org>,
	Florian Westphal <fw@...len.de>,
	Mina Almasry <almasrymina@...gle.com>,
	Abhishek Chauhan <quic_abchauha@...cinc.com>,
	David Howells <dhowells@...hat.com>,
	Alexander Lobakin <aleksander.lobakin@...el.com>,
	Pavel Begunkov <asml.silence@...il.com>,
	Lorenzo Bianconi <lorenzo@...nel.org>,
	Thomas Weißschuh <linux@...ssschuh.net>
Cc: Ilya Lifshits <ilya.lifshits@...adcom.com>
Subject: [PATCH net-next 1/2] skb: skb_vlan_push gets VLAN_HLEN as an argument

In case of vlan tagged packet, skb_vlan_push flushes current vlan header
into skb packet buffer. It also advances skb->mac_len by VLAN_HLEN
amount.

Some of the callers of skb_vlan_push (e.g. net/sched/act_vlan.c)
may want to reset skb network header by themselves.

To allow this we pass VLAN_HLEN as an argument to skb_vlan_push.

Signed-off-by: Boris Sukholitko <boris.sukholitko@...adcom.com>
---
 include/linux/skbuff.h    | 2 +-
 net/core/filter.c         | 2 +-
 net/core/skbuff.c         | 4 ++--
 net/openvswitch/actions.c | 3 ++-
 net/sched/act_vlan.c      | 3 ++-
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 9c29bdd5596d..e13f44fe33df 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -4046,7 +4046,7 @@ int skb_ensure_writable(struct sk_buff *skb, unsigned int write_len);
 int skb_ensure_writable_head_tail(struct sk_buff *skb, struct net_device *dev);
 int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci);
 int skb_vlan_pop(struct sk_buff *skb);
-int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
+int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci, u16 hlen);
 int skb_eth_pop(struct sk_buff *skb);
 int skb_eth_push(struct sk_buff *skb, const unsigned char *dst,
 		 const unsigned char *src);
diff --git a/net/core/filter.c b/net/core/filter.c
index d767880c276d..bb14574422b5 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3187,7 +3187,7 @@ BPF_CALL_3(bpf_skb_vlan_push, struct sk_buff *, skb, __be16, vlan_proto,
 		vlan_proto = htons(ETH_P_8021Q);
 
 	bpf_push_mac_rcsum(skb);
-	ret = skb_vlan_push(skb, vlan_proto, vlan_tci);
+	ret = skb_vlan_push(skb, vlan_proto, vlan_tci, VLAN_HLEN);
 	bpf_pull_mac_rcsum(skb);
 
 	bpf_compute_data_pointers(skb);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 83f8cd8aa2d1..9c69c9bff55c 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -6223,7 +6223,7 @@ EXPORT_SYMBOL(skb_vlan_pop);
 /* Push a vlan tag either into hwaccel or into payload (if hwaccel tag present).
  * Expects skb->data at mac header.
  */
-int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
+int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci, u16 hlen)
 {
 	if (skb_vlan_tag_present(skb)) {
 		int offset = skb->data - skb_mac_header(skb);
@@ -6241,7 +6241,7 @@ int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
 			return err;
 
 		skb->protocol = skb->vlan_proto;
-		skb->mac_len += VLAN_HLEN;
+		skb->mac_len += hlen;
 
 		skb_postpush_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN);
 	}
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 101f9a23792c..34909aca3526 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -244,7 +244,8 @@ static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
 		key->eth.vlan.tpid = vlan->vlan_tpid;
 	}
 	return skb_vlan_push(skb, vlan->vlan_tpid,
-			     ntohs(vlan->vlan_tci) & ~VLAN_CFI_MASK);
+			     ntohs(vlan->vlan_tci) & ~VLAN_CFI_MASK,
+			     VLAN_HLEN);
 }
 
 /* 'src' is already properly masked. */
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 22f4b1e8ade9..f60cf7062572 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -50,7 +50,8 @@ TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb,
 		break;
 	case TCA_VLAN_ACT_PUSH:
 		err = skb_vlan_push(skb, p->tcfv_push_proto, p->tcfv_push_vid |
-				    (p->tcfv_push_prio << VLAN_PRIO_SHIFT));
+				    (p->tcfv_push_prio << VLAN_PRIO_SHIFT),
+				    VLAN_HLEN);
 		if (err)
 			goto drop;
 		break;
-- 
2.42.0


Download attachment "smime.p7s" of type "application/pkcs7-signature" (4221 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ