[PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register()

Zeeshan Ahmad posted 1 patch 1 month, 2 weeks ago
There is a newer version of this series
net/core/failover.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register()
Posted by Zeeshan Ahmad 1 month, 2 weeks ago
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
Re: [PATCH net v2] net: core: failover: fix NULL pointer dereference in failover_slave_register()
Posted by Dan Carpenter 1 month, 2 weeks ago
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