* [PATCH] net: mediatek: add null pointer check for hardware offloading
@ 2025-12-31 22:52 Sebastian Roland Wolf
2026-01-01 16:04 ` Sai Krishna Gajula
2026-01-02 11:20 ` Vadim Fedorenko
0 siblings, 2 replies; 4+ messages in thread
From: Sebastian Roland Wolf @ 2025-12-31 22:52 UTC (permalink / raw)
To: Felix Fietkau, Sean Wang, Lorenzo Bianconi
Cc: Andrew Lunn, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek,
Sebastian Roland Wolf, Sebastian Roland Wolf
From: Sebastian Roland Wolf <srw@root533.premium-rootserver.net>
Add a null pointer check to prevent kernel crashes when hardware
offloading is active on MediaTek devices.
In some edge cases, the ethernet pointer or its associated netdev
element can be NULL. Checking these pointers before access is
mandatory to avoid segmentation faults and kernel oops.
This improves the robustness of the validation check for mtk_eth
ingress devices introduced in commit 73cfd947dbdb ("net: mediatek:
add support for ingress traffic offloading").
Fixes: 73cfd947dbdb ("net: mediatek: add support for ingress traffic offloading")
net: mediatek: Add null pointer check to prevent crashes with active hardware offloading.
Signed-off-by: Sebastian Roland Wolf <Sebastian.Wolf@pace-systems.de>
---
drivers/net/ethernet/mediatek/mtk_ppe_offload.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
index e9bd32741983..6900ac87e1e9 100644
--- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
+++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
@@ -270,7 +270,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
flow_rule_match_meta(rule, &match);
if (mtk_is_netsys_v2_or_greater(eth)) {
idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
- if (idev && idev->netdev_ops == eth->netdev[0]->netdev_ops) {
+ if (idev && eth && eth->netdev[0] &&
+ idev->netdev_ops == eth->netdev[0]->netdev_ops) {
struct mtk_mac *mac = netdev_priv(idev);
if (WARN_ON(mac->ppe_idx >= eth->soc->ppe_num))
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] net: mediatek: add null pointer check for hardware offloading
2025-12-31 22:52 [PATCH] net: mediatek: add null pointer check for hardware offloading Sebastian Roland Wolf
@ 2026-01-01 16:04 ` Sai Krishna Gajula
2026-01-02 11:20 ` Vadim Fedorenko
1 sibling, 0 replies; 4+ messages in thread
From: Sai Krishna Gajula @ 2026-01-01 16:04 UTC (permalink / raw)
To: Sebastian Roland Wolf, Felix Fietkau, Sean Wang, Lorenzo Bianconi
Cc: Andrew Lunn, Matthias Brugger, AngeloGioacchino Del Regno,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, Sebastian Roland Wolf
> -----Original Message-----
> From: Sebastian Roland Wolf <Sebastian.Wolf@pace-systems.de>
> Sent: Thursday, January 1, 2026 4:22 AM
> To: Felix Fietkau <nbd@nbd.name>; Sean Wang
> <sean.wang@mediatek.com>; Lorenzo Bianconi <lorenzo@kernel.org>
> Cc: Andrew Lunn <andrew+netdev@lunn.ch>; Matthias Brugger
> <matthias.bgg@gmail.com>; AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com>; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-
> mediatek@lists.infradead.org; Sebastian Roland Wolf
> <srw@root533.premium-rootserver.net>; Sebastian Roland Wolf
> <Sebastian.Wolf@pace-systems.de>
> Subject: [PATCH] net: mediatek: add null pointer check for
> hardware offloading
>
> From: Sebastian Roland Wolf <srw@ root533. premium-rootserver. net> Add a
> null pointer check to prevent kernel crashes when hardware offloading is
> active on MediaTek devices. In some edge cases, the ethernet pointer or its
> associated netdev
> From: Sebastian Roland Wolf <srw@root533.premium-rootserver.net>
>
> Add a null pointer check to prevent kernel crashes when hardware offloading
> is active on MediaTek devices.
>
> In some edge cases, the ethernet pointer or its associated netdev element
> can be NULL. Checking these pointers before access is mandatory to avoid
> segmentation faults and kernel oops.
>
> This improves the robustness of the validation check for mtk_eth ingress
> devices introduced in commit 73cfd947dbdb ("net: mediatek:
> add support for ingress traffic offloading").
>
> Fixes: 73cfd947dbdb ("net: mediatek: add support for ingress traffic
> offloading")
> net: mediatek: Add null pointer check to prevent crashes with active hardware
> offloading.
>
> Signed-off-by: Sebastian Roland Wolf <Sebastian.Wolf@pace-systems.de>
> ---
> drivers/net/ethernet/mediatek/mtk_ppe_offload.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> index e9bd32741983..6900ac87e1e9 100644
> --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> @@ -270,7 +270,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct
> flow_cls_offload *f,
> flow_rule_match_meta(rule, &match);
> if (mtk_is_netsys_v2_or_greater(eth)) {
> idev = __dev_get_by_index(&init_net, match.key-
> >ingress_ifindex);
> - if (idev && idev->netdev_ops == eth->netdev[0]-
> >netdev_ops) {
> + if (idev && eth && eth->netdev[0] &&
> + idev->netdev_ops == eth->netdev[0]->netdev_ops)
> {
> struct mtk_mac *mac = netdev_priv(idev);
>
> if (WARN_ON(mac->ppe_idx >= eth->soc-
> >ppe_num))
> --
> 2.51.0
>
Reviewed-by: Sai Krishna <saikrishnag@marvell.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: mediatek: add null pointer check for hardware offloading
2025-12-31 22:52 [PATCH] net: mediatek: add null pointer check for hardware offloading Sebastian Roland Wolf
2026-01-01 16:04 ` Sai Krishna Gajula
@ 2026-01-02 11:20 ` Vadim Fedorenko
2026-01-02 13:45 ` Sebastian Wolf
1 sibling, 1 reply; 4+ messages in thread
From: Vadim Fedorenko @ 2026-01-02 11:20 UTC (permalink / raw)
To: Sebastian Roland Wolf, Felix Fietkau, Sean Wang, Lorenzo Bianconi
Cc: Andrew Lunn, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek,
Sebastian Roland Wolf
On 31/12/2025 22:52, Sebastian Roland Wolf wrote:
> From: Sebastian Roland Wolf <srw@root533.premium-rootserver.net>
>
> Add a null pointer check to prevent kernel crashes when hardware
> offloading is active on MediaTek devices.
>
> In some edge cases, the ethernet pointer or its associated netdev
> element can be NULL. Checking these pointers before access is
> mandatory to avoid segmentation faults and kernel oops.
>
> This improves the robustness of the validation check for mtk_eth
> ingress devices introduced in commit 73cfd947dbdb ("net: mediatek:
> add support for ingress traffic offloading").
>
> Fixes: 73cfd947dbdb ("net: mediatek: add support for ingress traffic offloading")
> net: mediatek: Add null pointer check to prevent crashes with active hardware offloading.
>
> Signed-off-by: Sebastian Roland Wolf <Sebastian.Wolf@pace-systems.de>
> ---
> drivers/net/ethernet/mediatek/mtk_ppe_offload.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> index e9bd32741983..6900ac87e1e9 100644
> --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> @@ -270,7 +270,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
> flow_rule_match_meta(rule, &match);
> if (mtk_is_netsys_v2_or_greater(eth)) {
The code dereferences eth here ...
> idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
> - if (idev && idev->netdev_ops == eth->netdev[0]->netdev_ops) {
> + if (idev && eth && eth->netdev[0] &&
... but it is checked a couple of lines after.
Even more, the function starts with providing rhahstable to lookup
cookie. I'm really doubt eth can be NULL.
At the same time lack of eth->netdev[0] looks like a design problem,
because according to the code there might be up to 3 netdev devices
registered for ppe.
I'm not familiar with the code, but it would be better to have a splat
of crash to check what was exactly missing, and drgn can help you find
if there were other netdevs available at the moment of crash.
> + idev->netdev_ops == eth->netdev[0]->netdev_ops) {
> struct mtk_mac *mac = netdev_priv(idev);
>
> if (WARN_ON(mac->ppe_idx >= eth->soc->ppe_num))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: mediatek: add null pointer check for hardware offloading
2026-01-02 11:20 ` Vadim Fedorenko
@ 2026-01-02 13:45 ` Sebastian Wolf
0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Wolf @ 2026-01-02 13:45 UTC (permalink / raw)
To: Felix Fietkau, Sean Wang, Lorenzo Bianconi, Vadim Fedorenko
Cc: Andrew Lunn, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek,
Sebastian Roland Wolf
Hi Vadim,
"Vadim Fedorenko" vadim.fedorenko@linux.dev – 2. Januar 2026 12:20
> On 31/12/2025 22:52, Sebastian Roland Wolf wrote:
> > From: Sebastian Roland Wolf <srw@root533.premium-rootserver.net>
> >
> > Add a null pointer check to prevent kernel crashes when hardware
> > offloading is active on MediaTek devices.
> >
> > In some edge cases, the ethernet pointer or its associated netdev
> > element can be NULL. Checking these pointers before access is
> > mandatory to avoid segmentation faults and kernel oops.
> >
> > This improves the robustness of the validation check for mtk_eth
> > ingress devices introduced in commit 73cfd947dbdb ("net: mediatek:
> > add support for ingress traffic offloading").
> >
> > Fixes: 73cfd947dbdb ("net: mediatek: add support for ingress traffic offloading")
> > net: mediatek: Add null pointer check to prevent crashes with active hardware offloading.
> >
> > Signed-off-by: Sebastian Roland Wolf <Sebastian.Wolf@pace-systems.de>
> > ---
> > drivers/net/ethernet/mediatek/mtk_ppe_offload.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> > index e9bd32741983..6900ac87e1e9 100644
> > --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> > +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> > @@ -270,7 +270,8 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
> > flow_rule_match_meta(rule, &match);
> > if (mtk_is_netsys_v2_or_greater(eth)) {
>
> The code dereferences eth here ...
>
> > idev = __dev_get_by_index(&init_net, match.key->ingress_ifindex);
> > - if (idev && idev->netdev_ops == eth->netdev[0]->netdev_ops) {
> > + if (idev && eth && eth->netdev[0] &&
>
> ... but it is checked a couple of lines after.
>
You are right that 'eth' is already dereferenced above, so checking it here is redundant. I will remove the 'eth' check in a V2 of this patch. (As this is first patch ever I hope I do it right)
> Even more, the function starts with providing rhahstable to lookup
> cookie. I'm really doubt eth can be NULL.
> At the same time lack of eth->netdev[0] looks like a design problem,
> because according to the code there might be up to 3 netdev devices
> registered for ppe.
While it might point to a deeper design issue, the check for 'eth->netdev[0]' is necessary to prevent the immediate kernel oops I am seeing. Forcing this check prevents the crash, which is the lesser evil compared to a complete system failure, even if hardware offloading might not function correctly in that specific state.
>
> I'm not familiar with the code, but it would be better to have a splat
> of crash to check what was exactly missing, and drgn can help you find
> if there were other netdevs available at the moment of crash.
Unfortunately, I am not a regular kernel developer and have no experience with drgn. Furthermore, I am testing this on a production device which limits my ability to perform deep interactive debugging or long-term crash analysis.
>
> > + idev->netdev_ops == eth->netdev[0]->netdev_ops) {
> > struct mtk_mac *mac = netdev_priv(idev);
> >
> > if (WARN_ON(mac->ppe_idx >= eth->soc->ppe_num))
>
>
I will send a V2 shortly, focusing on the 'eth->netdev[0]' check while removing the redundant 'eth' check.
Best regards,
Sebastian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-02 13:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-31 22:52 [PATCH] net: mediatek: add null pointer check for hardware offloading Sebastian Roland Wolf
2026-01-01 16:04 ` Sai Krishna Gajula
2026-01-02 11:20 ` Vadim Fedorenko
2026-01-02 13:45 ` Sebastian Wolf
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).