diff mbox series

net/smc: Fix traversal in __pnet_find_base_ndev

Message ID 20250127201408.14869-1-asharji1828@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net/smc: Fix traversal in __pnet_find_base_ndev | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 11 maintainers not CCed: jaka@linux.ibm.com wenjia@linux.ibm.com linux-s390@vger.kernel.org guwen@linux.alibaba.com edumazet@google.com horms@kernel.org kuba@kernel.org alibuda@linux.alibaba.com linux-rdma@vger.kernel.org pabeni@redhat.com tonylu@linux.alibaba.com
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch fail ERROR: code indent should use tabs where possible ERROR: trailing whitespace WARNING: From:/Signed-off-by: email name mismatch: 'From: Abdullah <asharji1828@gmail.com>' != 'Signed-off-by: Abdullah AlSharji <asharji1828@gmail.com>' WARNING: please, no spaces at the start of a line WARNING: suspect code indent for conditional statements (8, 8)
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Abdullah Jan. 27, 2025, 8:14 p.m. UTC
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@gmail.com>
---
 net/smc/smc_pnet.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;
 }