Skip to content

Commit 09bccf5

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: airoha: Validate egress gdm port in airoha_ppe_foe_entry_prepare()
Dev pointer in airoha_ppe_foe_entry_prepare routine is not strictly a device allocated by airoha_eth driver since it is an egress device and the flowtable can contain even wlan, pppoe or vlan devices. E.g: flowtable ft { hook ingress priority filter devices = { eth1, lan1, lan2, lan3, lan4, wlan0 } flags offload ^ | "not allocated by airoha_eth" -- } In this case airoha_get_dsa_port() will just return the original device pointer and we can't assume netdev priv pointer points to an airoha_gdm_port struct. Fix the issue validating egress gdm port in airoha_ppe_foe_entry_prepare routine before accessing net_device priv pointer. Fixes: 00a7678 ("net: airoha: Introduce flowtable offload support") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250401-airoha-validate-egress-gdm-port-v4-1-c7315d33ce10@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a58d882 commit 09bccf5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

drivers/net/ethernet/airoha/airoha_eth.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,19 @@ static void airoha_metadata_dst_free(struct airoha_gdm_port *port)
24542454
}
24552455
}
24562456

2457+
bool airoha_is_valid_gdm_port(struct airoha_eth *eth,
2458+
struct airoha_gdm_port *port)
2459+
{
2460+
int i;
2461+
2462+
for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
2463+
if (eth->ports[i] == port)
2464+
return true;
2465+
}
2466+
2467+
return false;
2468+
}
2469+
24572470
static int airoha_alloc_gdm_port(struct airoha_eth *eth,
24582471
struct device_node *np, int index)
24592472
{

drivers/net/ethernet/airoha/airoha_eth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ u32 airoha_rmw(void __iomem *base, u32 offset, u32 mask, u32 val);
532532
#define airoha_qdma_clear(qdma, offset, val) \
533533
airoha_rmw((qdma)->regs, (offset), (val), 0)
534534

535+
bool airoha_is_valid_gdm_port(struct airoha_eth *eth,
536+
struct airoha_gdm_port *port);
537+
535538
void airoha_ppe_check_skb(struct airoha_ppe *ppe, u16 hash);
536539
int airoha_ppe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
537540
void *cb_priv);

drivers/net/ethernet/airoha/airoha_ppe.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ static int airoha_get_dsa_port(struct net_device **dev)
197197
#endif
198198
}
199199

200-
static int airoha_ppe_foe_entry_prepare(struct airoha_foe_entry *hwe,
200+
static int airoha_ppe_foe_entry_prepare(struct airoha_eth *eth,
201+
struct airoha_foe_entry *hwe,
201202
struct net_device *dev, int type,
202203
struct airoha_flow_data *data,
203204
int l4proto)
@@ -225,6 +226,9 @@ static int airoha_ppe_foe_entry_prepare(struct airoha_foe_entry *hwe,
225226
struct airoha_gdm_port *port = netdev_priv(dev);
226227
u8 pse_port;
227228

229+
if (!airoha_is_valid_gdm_port(eth, port))
230+
return -EINVAL;
231+
228232
if (dsa_port >= 0)
229233
pse_port = port->id == 4 ? FE_PSE_PORT_GDM4 : port->id;
230234
else
@@ -633,7 +637,7 @@ static int airoha_ppe_flow_offload_replace(struct airoha_gdm_port *port,
633637
!is_valid_ether_addr(data.eth.h_dest))
634638
return -EINVAL;
635639

636-
err = airoha_ppe_foe_entry_prepare(&hwe, odev, offload_type,
640+
err = airoha_ppe_foe_entry_prepare(eth, &hwe, odev, offload_type,
637641
&data, l4proto);
638642
if (err)
639643
return err;

0 commit comments

Comments
 (0)