Skip to contentSkip to conversation

genetlink: add explicit ordering break check for split ops

PATCH Applied Jiri Pirko 4 participants 4 messages Jul 20, 2023 – Jul 22, 2023

Subsystems (2)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 genetlink: add explicit ordering break check for split ops

From: Jiri Pirko <[email protected]>

Currently, if cmd in the split ops array is of lower value than the previous one, genl_validate_ops() continues to do the checks as if the values are equal. This may result in non-obvious WARN_ON() hit in these check.

Instead, check the incorrect ordering explicitly and put a WARN_ON() in case it is broken.

---
 net/netlink/genetlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/netlink/genetlink.c +5 -1
index a157247a1e45..6bd2ce51271f 100644
@@ -593,8 +593,12 @@ static int genl_validate_ops(const struct genl_family *family)
 			return -EINVAL;
 
 		/* Check sort order */
-		if (a->cmd < b->cmd)
+		if (a->cmd < b->cmd) {
 			continue;
+		} else if (a->cmd > b->cmd) {
+			WARN_ON(1);
+			return -EINVAL;
+		}
 
 		if (a->internal_flags != b->internal_flags ||
 		    ((a->flags ^ b->flags) & ~(GENL_CMD_CAP_DO |
Signature · 1 line
2.41.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Thu, 20 Jul 2023 13:13:54 +0200 Jiri Pirko wrote:

From: Jiri Pirko <[email protected]>

Currently, if cmd in the split ops array is of lower value than the previous one, genl_validate_ops() continues to do the checks as if the values are equal. This may result in non-obvious WARN_ON() hit in these check.

Instead, check the incorrect ordering explicitly and put a WARN_ON() in case it is broken.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jiri Pirko
Quoted 17 lines

-----Original Message-----
From: Jiri Pirko <[email protected]>
Sent: Thursday, July 20, 2023 4:14 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>
Subject: [patch net-next] genetlink: add explicit ordering break check for split ops

From: Jiri Pirko <[email protected]>

Currently, if cmd in the split ops array is of lower value than the previous one, genl_validate_ops() continues to do the checks as if the values are equal. This may result in non-obvious WARN_ON() hit in these check.

Quoted 4 lines

Instead, check the incorrect ordering explicitly and put a WARN_ON() in case it is broken.

Good fix.

Quoted 25 lines
---
 net/netlink/genetlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/netlink/genetlink.c +5 -1
index a157247a1e45..6bd2ce51271f 100644
@@ -593,8 +593,12 @@ static int genl_validate_ops(const struct genl_family
 *family)
 			return -EINVAL;
 
 		/* Check sort order */
-		if (a->cmd < b->cmd)
+		if (a->cmd < b->cmd) {
 			continue;
+		} else if (a->cmd > b->cmd) {
+			WARN_ON(1);
+			return -EINVAL;
+		}
 
 		if (a->internal_flags != b->internal_flags ||

((a->flags ^ b->flags) & ~(GENL_CMD_CAP_DO |
--
2.41.0

#3 lore raw
In reply to Jiri Pirko
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 20 Jul 2023 13:13:54 +0200 you wrote:

From: Jiri Pirko <[email protected]>

Currently, if cmd in the split ops array is of lower value than the previous one, genl_validate_ops() continues to do the checks as if the values are equal. This may result in non-obvious WARN_ON() hit in these check.

[...]

Here is the summary with links:
- [net-next] genetlink: add explicit ordering break check for split ops

    https://git.kernel.org/netdev/net-next/c/5766946ea511

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html