c6ddbde692ff1b755e9d94f575e202df5fa18a4d
[openwrt/staging/blocktrron.git] /
1 From 09bccf56db36501ccb1935d921dc24451e9f57dd Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Tue, 1 Apr 2025 11:42:30 +0200
4 Subject: [PATCH] net: airoha: Validate egress gdm port in
5 airoha_ppe_foe_entry_prepare()
6
7 Dev pointer in airoha_ppe_foe_entry_prepare routine is not strictly
8 a device allocated by airoha_eth driver since it is an egress device
9 and the flowtable can contain even wlan, pppoe or vlan devices. E.g:
10
11 flowtable ft {
12 hook ingress priority filter
13 devices = { eth1, lan1, lan2, lan3, lan4, wlan0 }
14 flags offload ^
15 |
16 "not allocated by airoha_eth" --
17 }
18
19 In this case airoha_get_dsa_port() will just return the original device
20 pointer and we can't assume netdev priv pointer points to an
21 airoha_gdm_port struct.
22 Fix the issue validating egress gdm port in airoha_ppe_foe_entry_prepare
23 routine before accessing net_device priv pointer.
24
25 Fixes: 00a7678310fe ("net: airoha: Introduce flowtable offload support")
26 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
27 Reviewed-by: Simon Horman <horms@kernel.org>
28 Link: https://patch.msgid.link/20250401-airoha-validate-egress-gdm-port-v4-1-c7315d33ce10@kernel.org
29 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
30 ---
31 drivers/net/ethernet/airoha/airoha_eth.c | 13 +++++++++++++
32 drivers/net/ethernet/airoha/airoha_eth.h | 3 +++
33 drivers/net/ethernet/airoha/airoha_ppe.c | 8 ++++++--
34 3 files changed, 22 insertions(+), 2 deletions(-)
35
36 --- a/drivers/net/ethernet/airoha/airoha_eth.c
37 +++ b/drivers/net/ethernet/airoha/airoha_eth.c
38 @@ -2452,6 +2452,19 @@ static void airoha_metadata_dst_free(str
39 }
40 }
41
42 +bool airoha_is_valid_gdm_port(struct airoha_eth *eth,
43 + struct airoha_gdm_port *port)
44 +{
45 + int i;
46 +
47 + for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
48 + if (eth->ports[i] == port)
49 + return true;
50 + }
51 +
52 + return false;
53 +}
54 +
55 static int airoha_alloc_gdm_port(struct airoha_eth *eth,
56 struct device_node *np, int index)
57 {
58 --- a/drivers/net/ethernet/airoha/airoha_eth.h
59 +++ b/drivers/net/ethernet/airoha/airoha_eth.h
60 @@ -532,6 +532,9 @@ u32 airoha_rmw(void __iomem *base, u32 o
61 #define airoha_qdma_clear(qdma, offset, val) \
62 airoha_rmw((qdma)->regs, (offset), (val), 0)
63
64 +bool airoha_is_valid_gdm_port(struct airoha_eth *eth,
65 + struct airoha_gdm_port *port);
66 +
67 void airoha_ppe_check_skb(struct airoha_ppe *ppe, u16 hash);
68 int airoha_ppe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
69 void *cb_priv);
70 --- a/drivers/net/ethernet/airoha/airoha_ppe.c
71 +++ b/drivers/net/ethernet/airoha/airoha_ppe.c
72 @@ -197,7 +197,8 @@ static int airoha_get_dsa_port(struct ne
73 #endif
74 }
75
76 -static int airoha_ppe_foe_entry_prepare(struct airoha_foe_entry *hwe,
77 +static int airoha_ppe_foe_entry_prepare(struct airoha_eth *eth,
78 + struct airoha_foe_entry *hwe,
79 struct net_device *dev, int type,
80 struct airoha_flow_data *data,
81 int l4proto)
82 @@ -225,6 +226,9 @@ static int airoha_ppe_foe_entry_prepare(
83 struct airoha_gdm_port *port = netdev_priv(dev);
84 u8 pse_port;
85
86 + if (!airoha_is_valid_gdm_port(eth, port))
87 + return -EINVAL;
88 +
89 if (dsa_port >= 0)
90 pse_port = port->id == 4 ? FE_PSE_PORT_GDM4 : port->id;
91 else
92 @@ -633,7 +637,7 @@ static int airoha_ppe_flow_offload_repla
93 !is_valid_ether_addr(data.eth.h_dest))
94 return -EINVAL;
95
96 - err = airoha_ppe_foe_entry_prepare(&hwe, odev, offload_type,
97 + err = airoha_ppe_foe_entry_prepare(eth, &hwe, odev, offload_type,
98 &data, l4proto);
99 if (err)
100 return err;