Skip to contentSkip to conversation

netlink: Fix off-by-one error in netlink_proto_init()

PATCH In review Markus Elfring 2 participants 3 messages Nov 3, 2024 – Nov 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netlink: Fix off-by-one error in netlink_proto_init()

From: Markus Elfring <[email protected]>
Date: Sun, 3 Nov 2024 14:01:26 +0100

Hash tables should be properly destroyed after a rhashtable_init() call failed in this function implementation.
The corresponding exception handling was incomplete because of a questionable condition check.
Thus use the comparison operator “>=” instead for the affected while loop.

This issue was transformed by using the Coccinelle software.

Fixes e341694e3eb5 ("netlink: Convert netlink_lookup() to use RCU protected hash table")
---
 net/netlink/af_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netlink/af_netlink.c +1 -1
index 0a9287fadb47..9601b85dda95 100644
@@ -2936,7 +2936,7 @@ static int __init netlink_proto_init(void)
 	for (i = 0; i < MAX_LINKS; i++) {
 		if (rhashtable_init(&nl_table[i].hash,
 				    &netlink_rhashtable_params) < 0) {
-			while (--i > 0)
+			while (--i >= 0)
 				rhashtable_destroy(&nl_table[i].hash);
 			kfree(nl_table);
 			goto panic;

--
2.47.0

#1 lore raw

From: Markus Elfring <[email protected]>
Date: Sun, 3 Nov 2024 14:15:18 +0100

Quoted 8 lines

From: Markus Elfring <[email protected]>
Date: Sun, 3 Nov 2024 14:01:26 +0100

Hash tables should be properly destroyed after a rhashtable_init() call failed in this function implementation.
The corresponding exception handling was incomplete because of a questionable condition check.
Thus use the comparison operator “>=” instead for the affected while loop.

This patch is already applied to net-next.
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=bc74d329ceba

#2 lore raw

…

Quoted 4 lines
Quoted 1 line

Thus use the comparison operator “>=” instead for the affected while loop.

This patch is already applied to net-next.
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=bc74d329ceba

Thanks for your reminder on the commit bc74d329ceba23f998ead4f716266da5afe319f7 ("netlink: Remove the dead code in netlink_proto_init()") from 2024-10-31 for another contribution by Jinjie Ruan (also according to your suggestion).

See also:
https://lore.kernel.org/linux-kernel/[email protected]/
https://lore.kernel.org/linux-kernel/[email protected]/

Regards,
Markus