Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] net: core: Fix possible null-pointer dereference in failover_slave_register()
@ 2021-08-10  9:18 Tuo Li
  2021-08-10 15:04 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Tuo Li @ 2021-08-10  9:18 UTC (permalink / raw)
  To: sridhar.samudrala, davem, kuba
  Cc: netdev, linux-kernel, baijiaju1990, Tuo Li, TOTE Robot

The variable fops is checked in:
  if (fops && fops->slave_pre_register &&
    fops->slave_pre_register(slave_dev, failover_dev))

This indicates that it can be NULL.
However, it is dereferenced when calling netdev_rx_handler_register():
  err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
                    failover_dev);

To fix this possible null-pointer dereference, check fops first, and if 
it is NULL, assign -EINVAL to err.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 net/core/failover.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/core/failover.c b/net/core/failover.c
index b5cd3c727285..113a4dacdf48 100644
--- a/net/core/failover.c
+++ b/net/core/failover.c
@@ -63,8 +63,11 @@ static int failover_slave_register(struct net_device *slave_dev)
 	    fops->slave_pre_register(slave_dev, failover_dev))
 		goto done;
 
-	err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
+	if (fops)
+		err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
 					 failover_dev);
+	else
+		err = -EINVAL;
 	if (err) {
 		netdev_err(slave_dev, "can not register failover rx handler (err = %d)\n",
 			   err);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: core: Fix possible null-pointer dereference in failover_slave_register()
  2021-08-10  9:18 [PATCH] net: core: Fix possible null-pointer dereference in failover_slave_register() Tuo Li
@ 2021-08-10 15:04 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2021-08-10 15:04 UTC (permalink / raw)
  To: Tuo Li
  Cc: sridhar.samudrala, davem, netdev, linux-kernel, baijiaju1990, TOTE Robot

On Tue, 10 Aug 2021 02:18:00 -0700 Tuo Li wrote:
> The variable fops is checked in:
>   if (fops && fops->slave_pre_register &&
>     fops->slave_pre_register(slave_dev, failover_dev))
> 
> This indicates that it can be NULL.
> However, it is dereferenced when calling netdev_rx_handler_register():
>   err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
>                     failover_dev);
> 
> To fix this possible null-pointer dereference, check fops first, and if 
> it is NULL, assign -EINVAL to err.

The other fops checks look like defensive programming. I don't see
anywhere where fops would be cleared, and all callers pass it to
register().

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-10 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10  9:18 [PATCH] net: core: Fix possible null-pointer dereference in failover_slave_register() Tuo Li
2021-08-10 15:04 ` Jakub Kicinski

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).