* [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct
@ 2025-04-08 14:24 Eric Woudstra
2025-04-08 14:24 ` [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr Eric Woudstra
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Eric Woudstra @ 2025-04-08 14:24 UTC (permalink / raw)
To: Michal Ostrowski, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Pablo Neira Ayuso, Jozsef Kadlecsik,
Simon Horman, Nikolay Aleksandrov
Cc: netdev, netfilter-devel, linux-hardening, Eric Woudstra
Patch to add nf_flow_encap_push(), see patch message.
Added patch to eliminate array of flexible structures warning.
Changed in v11:
- Only push when tuple.out.ifidx == tuple.out.hw_ifidx
- No changes in nft_dev_path_info()
v10 split from patch-set: bridge-fastpath and related improvements v9
Eric Woudstra (2):
net: pppoe: avoid zero-length arrays in struct pppoe_hdr
netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit
direct
drivers/net/ppp/pppoe.c | 2 +-
include/uapi/linux/if_pppox.h | 4 ++
net/netfilter/nf_flow_table_ip.c | 97 +++++++++++++++++++++++++++++++-
3 files changed, 100 insertions(+), 3 deletions(-)
--
2.47.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr
2025-04-08 14:24 [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct Eric Woudstra
@ 2025-04-08 14:24 ` Eric Woudstra
2025-04-09 16:25 ` Kees Cook
2025-04-08 14:24 ` [PATCH v11 nf-next 2/2] netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct Eric Woudstra
2025-04-08 16:02 ` [PATCH v11 nf-next 0/2] " Pablo Neira Ayuso
2 siblings, 1 reply; 6+ messages in thread
From: Eric Woudstra @ 2025-04-08 14:24 UTC (permalink / raw)
To: Michal Ostrowski, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Pablo Neira Ayuso, Jozsef Kadlecsik,
Simon Horman, Nikolay Aleksandrov
Cc: netdev, netfilter-devel, linux-hardening, Eric Woudstra
Jakub Kicinski suggested following patch:
W=1 C=1 GCC build gives us:
net/bridge/netfilter/nf_conntrack_bridge.c: note: in included file (through
../include/linux/if_pppox.h, ../include/uapi/linux/netfilter_bridge.h,
../include/linux/netfilter_bridge.h): include/uapi/linux/if_pppox.h:
153:29: warning: array of flexible structures
It doesn't like that hdr has a zero-length array which overlaps proto.
The kernel code doesn't currently need those arrays.
PPPoE connection is functional after applying this patch.
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
drivers/net/ppp/pppoe.c | 2 +-
include/uapi/linux/if_pppox.h | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
index 68e631718ab0..17946af6a8cf 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -882,7 +882,7 @@ static int pppoe_sendmsg(struct socket *sock, struct msghdr *m,
skb->protocol = cpu_to_be16(ETH_P_PPP_SES);
ph = skb_put(skb, total_len + sizeof(struct pppoe_hdr));
- start = (char *)&ph->tag[0];
+ start = (char *)ph + sizeof(*ph);
error = memcpy_from_msg(start, m, total_len);
if (error < 0) {
diff --git a/include/uapi/linux/if_pppox.h b/include/uapi/linux/if_pppox.h
index 9abd80dcc46f..29b804aa7474 100644
--- a/include/uapi/linux/if_pppox.h
+++ b/include/uapi/linux/if_pppox.h
@@ -122,7 +122,9 @@ struct sockaddr_pppol2tpv3in6 {
struct pppoe_tag {
__be16 tag_type;
__be16 tag_len;
+#ifndef __KERNEL__
char tag_data[];
+#endif
} __attribute__ ((packed));
/* Tag identifiers */
@@ -150,7 +152,9 @@ struct pppoe_hdr {
__u8 code;
__be16 sid;
__be16 length;
+#ifndef __KERNEL__
struct pppoe_tag tag[];
+#endif
} __packed;
/* Length of entire PPPoE + PPP header */
--
2.47.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v11 nf-next 2/2] netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct
2025-04-08 14:24 [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct Eric Woudstra
2025-04-08 14:24 ` [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr Eric Woudstra
@ 2025-04-08 14:24 ` Eric Woudstra
2025-04-08 16:02 ` [PATCH v11 nf-next 0/2] " Pablo Neira Ayuso
2 siblings, 0 replies; 6+ messages in thread
From: Eric Woudstra @ 2025-04-08 14:24 UTC (permalink / raw)
To: Michal Ostrowski, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Pablo Neira Ayuso, Jozsef Kadlecsik,
Simon Horman, Nikolay Aleksandrov
Cc: netdev, netfilter-devel, linux-hardening, Eric Woudstra
Loosely based on wenxu's patches:
"nf_flow_table_offload: offload the vlan/PPPoE encap in the flowtable".
Fixed double vlan and pppoe packets, almost entirely rewriting the patch.
When there is no extra vlan-device or pppoe-device added to the fastpath,
it may still be possible that the other tuple has encaps.
This is the case when there is only a bridge in the forward-fastpath,
without a vlan-device. When the bridge is tagging at ingress and keeping
at egress, the other tuple will have an encap.
It will be also be the case in the future bridge-fastpath.
In these cases it is necessary to push these encaps.
This patch adds nf_flow_encap_push() and alters nf_flow_queue_xmit()
to call it, only when (tuple.out.ifidx == tuple.out.hw_ifidx).
Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
net/netfilter/nf_flow_table_ip.c | 97 +++++++++++++++++++++++++++++++-
1 file changed, 95 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 8cd4cf7ae211..64a12b9668e7 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -306,6 +306,92 @@ static bool nf_flow_skb_encap_protocol(struct sk_buff *skb, __be16 proto,
return false;
}
+static int nf_flow_vlan_inner_push(struct sk_buff *skb, __be16 proto, u16 id)
+{
+ struct vlan_hdr *vhdr;
+
+ if (skb_cow_head(skb, VLAN_HLEN))
+ return -1;
+
+ __skb_push(skb, VLAN_HLEN);
+ skb_reset_network_header(skb);
+
+ vhdr = (struct vlan_hdr *)(skb->data);
+ vhdr->h_vlan_TCI = htons(id);
+ vhdr->h_vlan_encapsulated_proto = skb->protocol;
+ skb->protocol = proto;
+
+ return 0;
+}
+
+static int nf_flow_ppoe_push(struct sk_buff *skb, u16 id)
+{
+ struct ppp_hdr {
+ struct pppoe_hdr hdr;
+ __be16 proto;
+ } *ph;
+ int data_len = skb->len + 2;
+ __be16 proto;
+
+ if (skb_cow_head(skb, PPPOE_SES_HLEN))
+ return -1;
+
+ if (skb->protocol == htons(ETH_P_IP))
+ proto = htons(PPP_IP);
+ else if (skb->protocol == htons(ETH_P_IPV6))
+ proto = htons(PPP_IPV6);
+ else
+ return -1;
+
+ __skb_push(skb, PPPOE_SES_HLEN);
+ skb_reset_network_header(skb);
+
+ ph = (struct ppp_hdr *)(skb->data);
+ ph->hdr.ver = 1;
+ ph->hdr.type = 1;
+ ph->hdr.code = 0;
+ ph->hdr.sid = htons(id);
+ ph->hdr.length = htons(data_len);
+ ph->proto = proto;
+ skb->protocol = htons(ETH_P_PPP_SES);
+
+ return 0;
+}
+
+static int nf_flow_encap_push(struct sk_buff *skb,
+ struct flow_offload_tuple_rhash *tuplehash,
+ unsigned short *type)
+{
+ int i = 0, ret = 0;
+
+ if (!tuplehash->tuple.encap_num)
+ return 0;
+
+ if (tuplehash->tuple.encap[i].proto == htons(ETH_P_8021Q) ||
+ tuplehash->tuple.encap[i].proto == htons(ETH_P_8021AD)) {
+ __vlan_hwaccel_put_tag(skb, tuplehash->tuple.encap[i].proto,
+ tuplehash->tuple.encap[i].id);
+ i++;
+ if (i >= tuplehash->tuple.encap_num)
+ return 0;
+ }
+
+ switch (tuplehash->tuple.encap[i].proto) {
+ case htons(ETH_P_8021Q):
+ *type = ETH_P_8021Q;
+ ret = nf_flow_vlan_inner_push(skb,
+ tuplehash->tuple.encap[i].proto,
+ tuplehash->tuple.encap[i].id);
+ break;
+ case htons(ETH_P_PPP_SES):
+ *type = ETH_P_PPP_SES;
+ ret = nf_flow_ppoe_push(skb,
+ tuplehash->tuple.encap[i].id);
+ break;
+ }
+ return ret;
+}
+
static void nf_flow_encap_pop(struct sk_buff *skb,
struct flow_offload_tuple_rhash *tuplehash)
{
@@ -335,6 +421,7 @@ static void nf_flow_encap_pop(struct sk_buff *skb,
static unsigned int nf_flow_queue_xmit(struct net *net, struct sk_buff *skb,
const struct flow_offload_tuple_rhash *tuplehash,
+ struct flow_offload_tuple_rhash *other_tuplehash,
unsigned short type)
{
struct net_device *outdev;
@@ -343,6 +430,10 @@ static unsigned int nf_flow_queue_xmit(struct net *net, struct sk_buff *skb,
if (!outdev)
return NF_DROP;
+ if (tuplehash->tuple.out.ifidx == tuplehash->tuple.out.hw_ifidx &&
+ (nf_flow_encap_push(skb, other_tuplehash, &type) < 0))
+ return NF_DROP;
+
skb->dev = outdev;
dev_hard_header(skb, skb->dev, type, tuplehash->tuple.out.h_dest,
tuplehash->tuple.out.h_source, skb->len);
@@ -462,7 +553,8 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
ret = NF_STOLEN;
break;
case FLOW_OFFLOAD_XMIT_DIRECT:
- ret = nf_flow_queue_xmit(state->net, skb, tuplehash, ETH_P_IP);
+ ret = nf_flow_queue_xmit(state->net, skb, tuplehash,
+ &flow->tuplehash[!dir], ETH_P_IP);
if (ret == NF_DROP)
flow_offload_teardown(flow);
break;
@@ -757,7 +849,8 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
ret = NF_STOLEN;
break;
case FLOW_OFFLOAD_XMIT_DIRECT:
- ret = nf_flow_queue_xmit(state->net, skb, tuplehash, ETH_P_IPV6);
+ ret = nf_flow_queue_xmit(state->net, skb, tuplehash,
+ &flow->tuplehash[!dir], ETH_P_IPV6);
if (ret == NF_DROP)
flow_offload_teardown(flow);
break;
--
2.47.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct
2025-04-08 14:24 [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct Eric Woudstra
2025-04-08 14:24 ` [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr Eric Woudstra
2025-04-08 14:24 ` [PATCH v11 nf-next 2/2] netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct Eric Woudstra
@ 2025-04-08 16:02 ` Pablo Neira Ayuso
2025-04-08 18:19 ` Eric Woudstra
2 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2025-04-08 16:02 UTC (permalink / raw)
To: Eric Woudstra
Cc: Michal Ostrowski, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Jozsef Kadlecsik, Simon Horman,
Nikolay Aleksandrov, netdev, netfilter-devel, linux-hardening
Hi,
Please, one series at a time. You pick a good target to start with.
I already provided a few suggestions on where to start from.
Thanks.
On Tue, Apr 08, 2025 at 04:24:23PM +0200, Eric Woudstra wrote:
> Patch to add nf_flow_encap_push(), see patch message.
>
> Added patch to eliminate array of flexible structures warning.
>
> Changed in v11:
> - Only push when tuple.out.ifidx == tuple.out.hw_ifidx
> - No changes in nft_dev_path_info()
>
> v10 split from patch-set: bridge-fastpath and related improvements v9
>
> Eric Woudstra (2):
> net: pppoe: avoid zero-length arrays in struct pppoe_hdr
> netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit
> direct
>
> drivers/net/ppp/pppoe.c | 2 +-
> include/uapi/linux/if_pppox.h | 4 ++
> net/netfilter/nf_flow_table_ip.c | 97 +++++++++++++++++++++++++++++++-
> 3 files changed, 100 insertions(+), 3 deletions(-)
>
> --
> 2.47.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct
2025-04-08 16:02 ` [PATCH v11 nf-next 0/2] " Pablo Neira Ayuso
@ 2025-04-08 18:19 ` Eric Woudstra
0 siblings, 0 replies; 6+ messages in thread
From: Eric Woudstra @ 2025-04-08 18:19 UTC (permalink / raw)
To: Pablo Neira Ayuso
Cc: Michal Ostrowski, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Jozsef Kadlecsik, Simon Horman,
Nikolay Aleksandrov, netdev, netfilter-devel, linux-hardening
On 4/8/25 6:02 PM, Pablo Neira Ayuso wrote:
> Hi,
>
> Please, one series at a time. You pick a good target to start with.
>
> I already provided a few suggestions on where to start from.
>
Ok, I view the patch-set 'conntrack: bridge: add double vlan, pppoe and
pppoe-in-q' more as an added bonus to the bridge-fastpath. It is quite
separate from the rest. I would consider this patch-set as low priority.
May I suggest we focus on patch-sets:
'Add nf_flow_encap_push() for xmit direct'
and
'netfilter: fastpath fixes'
After these issues are addressed, only then it makes sense to add
patch-set: 'netfilter: Add bridge-fastpath'.
Thanks
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr
2025-04-08 14:24 ` [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr Eric Woudstra
@ 2025-04-09 16:25 ` Kees Cook
0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2025-04-09 16:25 UTC (permalink / raw)
To: Eric Woudstra
Cc: Michal Ostrowski, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Pablo Neira Ayuso, Jozsef Kadlecsik,
Simon Horman, Nikolay Aleksandrov, netdev, netfilter-devel,
linux-hardening
On Tue, Apr 08, 2025 at 04:24:24PM +0200, Eric Woudstra wrote:
> Jakub Kicinski suggested following patch:
>
> W=1 C=1 GCC build gives us:
>
> net/bridge/netfilter/nf_conntrack_bridge.c: note: in included file (through
> ../include/linux/if_pppox.h, ../include/uapi/linux/netfilter_bridge.h,
> ../include/linux/netfilter_bridge.h): include/uapi/linux/if_pppox.h:
> 153:29: warning: array of flexible structures
>
> It doesn't like that hdr has a zero-length array which overlaps proto.
> The kernel code doesn't currently need those arrays.
>
> PPPoE connection is functional after applying this patch.
>
> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
> Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
Reviewed-by: Kees Cook <kees@kernel.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-09 16:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 14:24 [PATCH v11 nf-next 0/2] Add nf_flow_encap_push() for xmit direct Eric Woudstra
2025-04-08 14:24 ` [PATCH v11 nf-next 1/2] net: pppoe: avoid zero-length arrays in struct pppoe_hdr Eric Woudstra
2025-04-09 16:25 ` Kees Cook
2025-04-08 14:24 ` [PATCH v11 nf-next 2/2] netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct Eric Woudstra
2025-04-08 16:02 ` [PATCH v11 nf-next 0/2] " Pablo Neira Ayuso
2025-04-08 18:19 ` Eric Woudstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).