* [PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register()
@ 2026-02-26 7:57 Zeeshan Ahmad
2026-02-26 8:02 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Zeeshan Ahmad @ 2026-02-26 7:57 UTC (permalink / raw)
To: Sridhar Samudrala, David S . Miller, Jakub Kicinski, Paolo Abeni,
Eric Dumazet
Cc: netdev, kernel-janitors, linux-kernel, Simon Horman,
Zeeshan Ahmad
Smatch warns that 'fops' is dereferenced at line 69 without a NULL check.
While other callbacks in this function properly check 'fops', the
rx_handler registration does not.
If failover_get_bymac() returns a valid failover_dev but a NULL fops,
the kernel will encounter a NULL pointer dereference when registering
the rx_handler.
Following the pattern of other failover callers, add a WARN_ON_ONCE()
to catch this misconfiguration. Abort the registration if fops is
missing to prevent an inconsistent state where a slave is logically
linked to a master but lacks a functional data path hook.
Fixes: 30c8bd5aa8b2 ("net: Introduce generic failover module")
Signed-off-by: Zeeshan Ahmad <zeeshanahmad022019@gmail.com>
---
v2:
- Target 'net' tree as this is a bug fix.
- Change logic from an early return (v1) to WARN_ON_ONCE() and abort
registration to prevent inconsistent state, as discussed with
Simon Horman.
- Update commit message with detailed impact analysis.
net/core/failover.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/core/failover.c b/net/core/failover.c
index 2a140b3ea669..1702bb1feca1 100644
--- a/net/core/failover.c
+++ b/net/core/failover.c
@@ -63,6 +63,9 @@ static int failover_slave_register(struct net_device *slave_dev)
fops->slave_pre_register(slave_dev, failover_dev))
goto done;
+ if (WARN_ON_ONCE(!fops))
+ goto done;
+
err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
failover_dev);
if (err) {
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register()
2026-02-26 7:57 [PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register() Zeeshan Ahmad
@ 2026-02-26 8:02 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-02-26 8:02 UTC (permalink / raw)
To: Zeeshan Ahmad
Cc: Sridhar Samudrala, David S . Miller, Jakub Kicinski, Paolo Abeni,
Eric Dumazet, netdev, kernel-janitors, linux-kernel, Simon Horman
On Thu, Feb 26, 2026 at 12:57:37PM +0500, Zeeshan Ahmad wrote:
> Smatch warns that 'fops' is dereferenced at line 69 without a NULL check.
> While other callbacks in this function properly check 'fops', the
> rx_handler registration does not.
>
> If failover_get_bymac() returns a valid failover_dev but a NULL fops,
> the kernel will encounter a NULL pointer dereference when registering
> the rx_handler.
>
> Following the pattern of other failover callers, add a WARN_ON_ONCE()
> to catch this misconfiguration. Abort the registration if fops is
> missing to prevent an inconsistent state where a slave is logically
> linked to a master but lacks a functional data path hook.
>
> Fixes: 30c8bd5aa8b2 ("net: Introduce generic failover module")
> Signed-off-by: Zeeshan Ahmad <zeeshanahmad022019@gmail.com>
> ---
> v2:
> - Target 'net' tree as this is a bug fix.
> - Change logic from an early return (v1) to WARN_ON_ONCE() and abort
> registration to prevent inconsistent state, as discussed with
> Simon Horman.
> - Update commit message with detailed impact analysis.
>
> net/core/failover.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/core/failover.c b/net/core/failover.c
> index 2a140b3ea669..1702bb1feca1 100644
> --- a/net/core/failover.c
> +++ b/net/core/failover.c
> @@ -63,6 +63,9 @@ static int failover_slave_register(struct net_device *slave_dev)
> fops->slave_pre_register(slave_dev, failover_dev))
^^^^^^^^^^^^^^^^^^^^^^^^^
> goto done;
>
> + if (WARN_ON_ONCE(!fops))
> + goto done;
Move the NULL check in front of the fops->slave_pre_register() stuff and
delete the other later NULL checks.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-26 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26 7:57 [PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register() Zeeshan Ahmad
2026-02-26 8:02 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox