netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net-next] genetlink: add explicit ordering break check for split ops
@ 2023-07-20 11:13 Jiri Pirko
  2023-07-21  2:32 ` Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jiri Pirko @ 2023-07-20 11:13 UTC (permalink / raw)
  To: netdev; +Cc: kuba, pabeni, davem, edumazet, jacob.e.keller

From: Jiri Pirko <jiri@nvidia.com>

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.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 net/netlink/genetlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index a157247a1e45..6bd2ce51271f 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -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


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

* Re: [patch net-next] genetlink: add explicit ordering break check for split ops
  2023-07-20 11:13 [patch net-next] genetlink: add explicit ordering break check for split ops Jiri Pirko
@ 2023-07-21  2:32 ` Jakub Kicinski
  2023-07-21 16:45 ` Keller, Jacob E
  2023-07-22  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2023-07-21  2:32 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, pabeni, davem, edumazet, jacob.e.keller

On Thu, 20 Jul 2023 13:13:54 +0200 Jiri Pirko wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> 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.
> 
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>

Reviewed-by: Jakub Kicinski <kuba@kernel.org>

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

* RE: [patch net-next] genetlink: add explicit ordering break check for split ops
  2023-07-20 11:13 [patch net-next] genetlink: add explicit ordering break check for split ops Jiri Pirko
  2023-07-21  2:32 ` Jakub Kicinski
@ 2023-07-21 16:45 ` Keller, Jacob E
  2023-07-22  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Keller, Jacob E @ 2023-07-21 16:45 UTC (permalink / raw)
  To: Jiri Pirko, netdev@vger.kernel.org
  Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net,
	edumazet@google.com



> -----Original Message-----
> From: Jiri Pirko <jiri@resnulli.us>
> Sent: Thursday, July 20, 2023 4:14 AM
> To: netdev@vger.kernel.org
> Cc: kuba@kernel.org; pabeni@redhat.com; davem@davemloft.net;
> edumazet@google.com; Keller, Jacob E <jacob.e.keller@intel.com>
> Subject: [patch net-next] genetlink: add explicit ordering break check for split ops
> 
> From: Jiri Pirko <jiri@nvidia.com>
> 
> 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.
> 
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>


Good fix.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

> ---
>  net/netlink/genetlink.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
> index a157247a1e45..6bd2ce51271f 100644
> --- a/net/netlink/genetlink.c
> +++ b/net/netlink/genetlink.c
> @@ -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


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

* Re: [patch net-next] genetlink: add explicit ordering break check for split ops
  2023-07-20 11:13 [patch net-next] genetlink: add explicit ordering break check for split ops Jiri Pirko
  2023-07-21  2:32 ` Jakub Kicinski
  2023-07-21 16:45 ` Keller, Jacob E
@ 2023-07-22  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-22  2:10 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, kuba, pabeni, davem, edumazet, jacob.e.keller

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 20 Jul 2023 13:13:54 +0200 you wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-07-22  2:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 11:13 [patch net-next] genetlink: add explicit ordering break check for split ops Jiri Pirko
2023-07-21  2:32 ` Jakub Kicinski
2023-07-21 16:45 ` Keller, Jacob E
2023-07-22  2:10 ` patchwork-bot+netdevbpf

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