All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] genetlink: correctly begin the iteration over policies
@ 2022-11-08 20:41 Jakub Kicinski
  2022-11-08 20:43 ` Jakub Kicinski
  2022-11-09 20:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Jakub Kicinski @ 2022-11-08 20:41 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, pabeni, Jakub Kicinski, jacob.e.keller

The return value from genl_op_iter_init() only tells us if
there are any policies but to begin the iteration (and therefore
load the first entry) we need to call genl_op_iter_next().
Note that it's safe to call genl_op_iter_next() on a family
with no ops, it will just return false.

This may lead to various crashes, a warning in
netlink_policy_dump_get_policy_idx() when policy is not found
or.. no problem at all if the kmalloc'ed memory happens to be
zeroed.

Fixes: b502b3185cd6 ("genetlink: use iterator in the op to policy map dumping")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: jacob.e.keller@intel.com

Why KASAN doesn't catch the use of uninit memory here is a mystery :S
---
 net/netlink/genetlink.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 362a61179036..9b7dfc45dd67 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1437,7 +1437,9 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
 	ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL);
 	if (!ctx->op_iter)
 		return -ENOMEM;
-	ctx->dump_map = genl_op_iter_init(rt, ctx->op_iter);
+
+	genl_op_iter_init(rt, ctx->op_iter);
+	ctx->dump_map = genl_op_iter_next(ctx->op_iter);
 
 	for (genl_op_iter_init(rt, &i); genl_op_iter_next(&i); ) {
 		if (i.doit.policy) {
-- 
2.38.1


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

* Re: [PATCH net-next] genetlink: correctly begin the iteration over policies
  2022-11-08 20:41 [PATCH net-next] genetlink: correctly begin the iteration over policies Jakub Kicinski
@ 2022-11-08 20:43 ` Jakub Kicinski
  2022-11-08 20:52   ` Keller, Jacob E
  2022-11-09 20:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2022-11-08 20:43 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, pabeni, jacob.e.keller

On Tue,  8 Nov 2022 12:41:28 -0800 Jakub Kicinski wrote:
> Why KASAN doesn't catch the use of uninit memory here is a mystery :S

Ah, because it's not KMSAN.

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

* RE: [PATCH net-next] genetlink: correctly begin the iteration over policies
  2022-11-08 20:43 ` Jakub Kicinski
@ 2022-11-08 20:52   ` Keller, Jacob E
  0 siblings, 0 replies; 4+ messages in thread
From: Keller, Jacob E @ 2022-11-08 20:52 UTC (permalink / raw)
  To: Jakub Kicinski, davem; +Cc: netdev, edumazet, pabeni

> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Tuesday, November 8, 2022 12:44 PM
> To: davem@davemloft.net
> Cc: netdev@vger.kernel.org; edumazet@google.com; pabeni@redhat.com;
> Keller, Jacob E <jacob.e.keller@intel.com>
> Subject: Re: [PATCH net-next] genetlink: correctly begin the iteration over policies
> 
> On Tue,  8 Nov 2022 12:41:28 -0800 Jakub Kicinski wrote:
> > Why KASAN doesn't catch the use of uninit memory here is a mystery :S
> 
> Ah, because it's not KMSAN.

Yea, because KASAN mainly focuses on use-after-free and allocated buffer overruns, while KMSAN focuses on uninitialized memory. It looks like KMSAN isn't yet upstream.

Thanks,
Jake

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

* Re: [PATCH net-next] genetlink: correctly begin the iteration over policies
  2022-11-08 20:41 [PATCH net-next] genetlink: correctly begin the iteration over policies Jakub Kicinski
  2022-11-08 20:43 ` Jakub Kicinski
@ 2022-11-09 20:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-09 20:10 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, jacob.e.keller

Hello:

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

On Tue,  8 Nov 2022 12:41:28 -0800 you wrote:
> The return value from genl_op_iter_init() only tells us if
> there are any policies but to begin the iteration (and therefore
> load the first entry) we need to call genl_op_iter_next().
> Note that it's safe to call genl_op_iter_next() on a family
> with no ops, it will just return false.
> 
> This may lead to various crashes, a warning in
> netlink_policy_dump_get_policy_idx() when policy is not found
> or.. no problem at all if the kmalloc'ed memory happens to be
> zeroed.
> 
> [...]

Here is the summary with links:
  - [net-next] genetlink: correctly begin the iteration over policies
    https://git.kernel.org/netdev/net-next/c/154ba79c9f16

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:[~2022-11-09 20:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 20:41 [PATCH net-next] genetlink: correctly begin the iteration over policies Jakub Kicinski
2022-11-08 20:43 ` Jakub Kicinski
2022-11-08 20:52   ` Keller, Jacob E
2022-11-09 20:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.