[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250127201408.14869-1-asharji1828@gmail.com>
Date: Tue, 28 Jan 2025 00:14:08 +0400
From: Abdullah <asharji1828@...il.com>
To: syzkaller-bugs@...glegroups.com
Cc: netdev@...r.kernel.org,
skhan@...uxfoundation.org,
Abdullah <asharji1828@...il.com>
Subject: [PATCH] net/smc: Fix traversal in __pnet_find_base_ndev
This patch improves the robustness of the function __pnet_find_base_ndev
by:
1. Adding input validation for a NULL `ndev` pointer.
2. Ensuring the function exits gracefully if `netdev_lower_get_next`
returns NULL during traversal.
3. Clarifying the function’s purpose with proper documentation.
4. Removing the redundant `lower = lower->next` statement, which caused
traversal to skip levels or go beyond the logic intended, potentially
leading to invalid memory access.
The function now safely traverses the adjacency list of a network
device to find the lowest-level (base) device in the hierarchy.
Signed-off-by: Abdullah AlSharji <asharji1828@...il.com>
---
net/smc/smc_pnet.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index 716808f374a8..8adcf6a97d30 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -920,6 +920,18 @@ void smc_pnet_exit(void)
static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)
{
+ /**
+ * __pnet_find_base_ndev - Find the base network device in a hierarchy.
+ * ndev: Pointer to the starting network device.
+ *
+ * This function traverses the adjacency list of a network device,
+ * to find the lowest-level (base) network device in the hierarchy.
+ *
+ */
+
+ if (!ndev)
+ return NULL;
+
int i, nest_lvl;
ASSERT_RTNL();
@@ -929,9 +941,9 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)
if (list_empty(lower))
break;
- lower = lower->next;
ndev = netdev_lower_get_next(ndev, &lower);
}
+
return ndev;
}
--
2.43.0
Powered by blists - more mailing lists