* [PATCH net-next v2] genetlink: fix single op policy dump when do is present
@ 2022-11-09 18:32 Jakub Kicinski
2022-11-09 20:05 ` Keller, Jacob E
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2022-11-09 18:32 UTC (permalink / raw)
To: davem
Cc: netdev, edumazet, pabeni, Jakub Kicinski, Jonathan Lemon,
jacob.e.keller, leon
Jonathan reports crashes when running net-next in Meta's fleet.
Stats collection uses ethtool -I which does a per-op policy dump
to check if stats are supported. We don't initialize the dumpit
information if doit succeeds due to evaluation short-circuiting.
The crash may look like this:
BUG: kernel NULL pointer dereference, address: 0000000000000cc0
RIP: 0010:netlink_policy_dump_add_policy+0x174/0x2a0
ctrl_dumppolicy_start+0x19f/0x2f0
genl_start+0xe7/0x140
Or we may trigger a warning:
WARNING: CPU: 1 PID: 785 at net/netlink/policy.c:87 netlink_policy_dump_get_policy_idx+0x79/0x80
RIP: 0010:netlink_policy_dump_get_policy_idx+0x79/0x80
ctrl_dumppolicy_put_op+0x214/0x360
depending on what garbage we pick up from the stack.
Reported-by: Jonathan Lemon <bsd@meta.com>
Fixes: 26588edbef60 ("genetlink: support split policies in ctrl_dumppolicy_put_op()")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: jacob.e.keller@intel.com
CC: leon@kernel.org
v2:
- add a helper instead of doing magic sums
- improve title
v1: https://lore.kernel.org/all/20221108204041.330172-1-kuba@kernel.org/
---
net/netlink/genetlink.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 9b7dfc45dd67..600993c80050 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -282,6 +282,7 @@ genl_cmd_full_to_split(struct genl_split_ops *op,
return 0;
}
+/* Must make sure that op is initialized to 0 on failure */
static int
genl_get_cmd(u32 cmd, u8 flags, const struct genl_family *family,
struct genl_split_ops *op)
@@ -302,6 +303,21 @@ genl_get_cmd(u32 cmd, u8 flags, const struct genl_family *family,
return err;
}
+/* For policy dumping only, get ops of both do and dump.
+ * Fail if both are missing, genl_get_cmd() will zero-init in case of failure.
+ */
+static int
+genl_get_cmd_both(u32 cmd, const struct genl_family *family,
+ struct genl_split_ops *doit, struct genl_split_ops *dumpit)
+{
+ int err1, err2;
+
+ err1 = genl_get_cmd(cmd, GENL_CMD_CAP_DO, family, doit);
+ err2 = genl_get_cmd(cmd, GENL_CMD_CAP_DUMP, family, dumpit);
+
+ return err1 && err2 ? -ENOENT : 0;
+}
+
static bool
genl_op_iter_init(const struct genl_family *family, struct genl_op_iter *iter)
{
@@ -1406,10 +1422,10 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
ctx->single_op = true;
ctx->op = nla_get_u32(tb[CTRL_ATTR_OP]);
- if (genl_get_cmd(ctx->op, GENL_CMD_CAP_DO, rt, &doit) &&
- genl_get_cmd(ctx->op, GENL_CMD_CAP_DUMP, rt, &dump)) {
+ err = genl_get_cmd_both(ctx->op, rt, &doit, &dump);
+ if (err) {
NL_SET_BAD_ATTR(cb->extack, tb[CTRL_ATTR_OP]);
- return -ENOENT;
+ return err;
}
if (doit.policy) {
@@ -1551,13 +1567,9 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
if (ctx->single_op) {
struct genl_split_ops doit, dumpit;
- if (genl_get_cmd(ctx->op, GENL_CMD_CAP_DO,
- ctx->rt, &doit) &&
- genl_get_cmd(ctx->op, GENL_CMD_CAP_DUMP,
- ctx->rt, &dumpit)) {
- WARN_ON(1);
+ if (WARN_ON(genl_get_cmd_both(ctx->op, ctx->rt,
+ &doit, &dumpit)))
return -ENOENT;
- }
if (ctrl_dumppolicy_put_op(skb, cb, &doit, &dumpit))
return skb->len;
--
2.38.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH net-next v2] genetlink: fix single op policy dump when do is present
2022-11-09 18:32 [PATCH net-next v2] genetlink: fix single op policy dump when do is present Jakub Kicinski
@ 2022-11-09 20:05 ` Keller, Jacob E
2022-11-10 9:36 ` Leon Romanovsky
2022-11-10 22:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Keller, Jacob E @ 2022-11-09 20:05 UTC (permalink / raw)
To: Jakub Kicinski, davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
Jonathan Lemon, leon@kernel.org
> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Wednesday, November 9, 2022 10:33 AM
> To: davem@davemloft.net
> Cc: netdev@vger.kernel.org; edumazet@google.com; pabeni@redhat.com;
> Jakub Kicinski <kuba@kernel.org>; Jonathan Lemon <bsd@meta.com>; Keller,
> Jacob E <jacob.e.keller@intel.com>; leon@kernel.org
> Subject: [PATCH net-next v2] genetlink: fix single op policy dump when do is
> present
>
> Jonathan reports crashes when running net-next in Meta's fleet.
> Stats collection uses ethtool -I which does a per-op policy dump
> to check if stats are supported. We don't initialize the dumpit
> information if doit succeeds due to evaluation short-circuiting.
>
> The crash may look like this:
>
> BUG: kernel NULL pointer dereference, address: 0000000000000cc0
> RIP: 0010:netlink_policy_dump_add_policy+0x174/0x2a0
> ctrl_dumppolicy_start+0x19f/0x2f0
> genl_start+0xe7/0x140
>
> Or we may trigger a warning:
>
> WARNING: CPU: 1 PID: 785 at net/netlink/policy.c:87
> netlink_policy_dump_get_policy_idx+0x79/0x80
> RIP: 0010:netlink_policy_dump_get_policy_idx+0x79/0x80
> ctrl_dumppolicy_put_op+0x214/0x360
>
> depending on what garbage we pick up from the stack.
>
Thanks!
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
> Reported-by: Jonathan Lemon <bsd@meta.com>
> Fixes: 26588edbef60 ("genetlink: support split policies in
> ctrl_dumppolicy_put_op()")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: jacob.e.keller@intel.com
> CC: leon@kernel.org
>
> v2:
> - add a helper instead of doing magic sums
> - improve title
> v1: https://lore.kernel.org/all/20221108204041.330172-1-kuba@kernel.org/
> ---
> net/netlink/genetlink.c | 30 +++++++++++++++++++++---------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
> index 9b7dfc45dd67..600993c80050 100644
> --- a/net/netlink/genetlink.c
> +++ b/net/netlink/genetlink.c
> @@ -282,6 +282,7 @@ genl_cmd_full_to_split(struct genl_split_ops *op,
> return 0;
> }
>
> +/* Must make sure that op is initialized to 0 on failure */
> static int
> genl_get_cmd(u32 cmd, u8 flags, const struct genl_family *family,
> struct genl_split_ops *op)
> @@ -302,6 +303,21 @@ genl_get_cmd(u32 cmd, u8 flags, const struct
> genl_family *family,
> return err;
> }
>
> +/* For policy dumping only, get ops of both do and dump.
> + * Fail if both are missing, genl_get_cmd() will zero-init in case of failure.
> + */
> +static int
> +genl_get_cmd_both(u32 cmd, const struct genl_family *family,
> + struct genl_split_ops *doit, struct genl_split_ops *dumpit)
> +{
> + int err1, err2;
> +
> + err1 = genl_get_cmd(cmd, GENL_CMD_CAP_DO, family, doit);
> + err2 = genl_get_cmd(cmd, GENL_CMD_CAP_DUMP, family, dumpit);
> +
> + return err1 && err2 ? -ENOENT : 0;
> +}
> +
> static bool
> genl_op_iter_init(const struct genl_family *family, struct genl_op_iter *iter)
> {
> @@ -1406,10 +1422,10 @@ static int ctrl_dumppolicy_start(struct
> netlink_callback *cb)
> ctx->single_op = true;
> ctx->op = nla_get_u32(tb[CTRL_ATTR_OP]);
>
> - if (genl_get_cmd(ctx->op, GENL_CMD_CAP_DO, rt, &doit) &&
> - genl_get_cmd(ctx->op, GENL_CMD_CAP_DUMP, rt, &dump)) {
> + err = genl_get_cmd_both(ctx->op, rt, &doit, &dump);
> + if (err) {
> NL_SET_BAD_ATTR(cb->extack, tb[CTRL_ATTR_OP]);
> - return -ENOENT;
> + return err;
> }
>
> if (doit.policy) {
> @@ -1551,13 +1567,9 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct
> netlink_callback *cb)
> if (ctx->single_op) {
> struct genl_split_ops doit, dumpit;
>
> - if (genl_get_cmd(ctx->op, GENL_CMD_CAP_DO,
> - ctx->rt, &doit) &&
> - genl_get_cmd(ctx->op, GENL_CMD_CAP_DUMP,
> - ctx->rt, &dumpit)) {
> - WARN_ON(1);
> + if (WARN_ON(genl_get_cmd_both(ctx->op, ctx->rt,
> + &doit, &dumpit)))
> return -ENOENT;
> - }
>
> if (ctrl_dumppolicy_put_op(skb, cb, &doit, &dumpit))
> return skb->len;
> --
> 2.38.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] genetlink: fix single op policy dump when do is present
2022-11-09 18:32 [PATCH net-next v2] genetlink: fix single op policy dump when do is present Jakub Kicinski
2022-11-09 20:05 ` Keller, Jacob E
@ 2022-11-10 9:36 ` Leon Romanovsky
2022-11-10 22:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2022-11-10 9:36 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, Jonathan Lemon, jacob.e.keller
On Wed, Nov 09, 2022 at 10:32:54AM -0800, Jakub Kicinski wrote:
> Jonathan reports crashes when running net-next in Meta's fleet.
> Stats collection uses ethtool -I which does a per-op policy dump
> to check if stats are supported. We don't initialize the dumpit
> information if doit succeeds due to evaluation short-circuiting.
>
> The crash may look like this:
>
> BUG: kernel NULL pointer dereference, address: 0000000000000cc0
> RIP: 0010:netlink_policy_dump_add_policy+0x174/0x2a0
> ctrl_dumppolicy_start+0x19f/0x2f0
> genl_start+0xe7/0x140
>
> Or we may trigger a warning:
>
> WARNING: CPU: 1 PID: 785 at net/netlink/policy.c:87 netlink_policy_dump_get_policy_idx+0x79/0x80
> RIP: 0010:netlink_policy_dump_get_policy_idx+0x79/0x80
> ctrl_dumppolicy_put_op+0x214/0x360
>
> depending on what garbage we pick up from the stack.
>
> Reported-by: Jonathan Lemon <bsd@meta.com>
> Fixes: 26588edbef60 ("genetlink: support split policies in ctrl_dumppolicy_put_op()")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: jacob.e.keller@intel.com
> CC: leon@kernel.org
>
> v2:
> - add a helper instead of doing magic sums
> - improve title
> v1: https://lore.kernel.org/all/20221108204041.330172-1-kuba@kernel.org/
> ---
> net/netlink/genetlink.c | 30 +++++++++++++++++++++---------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
Thanks,
Tested-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] genetlink: fix single op policy dump when do is present
2022-11-09 18:32 [PATCH net-next v2] genetlink: fix single op policy dump when do is present Jakub Kicinski
2022-11-09 20:05 ` Keller, Jacob E
2022-11-10 9:36 ` Leon Romanovsky
@ 2022-11-10 22:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-10 22:10 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, bsd, jacob.e.keller, leon
Hello:
This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 9 Nov 2022 10:32:54 -0800 you wrote:
> Jonathan reports crashes when running net-next in Meta's fleet.
> Stats collection uses ethtool -I which does a per-op policy dump
> to check if stats are supported. We don't initialize the dumpit
> information if doit succeeds due to evaluation short-circuiting.
>
> The crash may look like this:
>
> [...]
Here is the summary with links:
- [net-next,v2] genetlink: fix single op policy dump when do is present
https://git.kernel.org/netdev/net-next/c/c1b05105573b
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-10 22:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 18:32 [PATCH net-next v2] genetlink: fix single op policy dump when do is present Jakub Kicinski
2022-11-09 20:05 ` Keller, Jacob E
2022-11-10 9:36 ` Leon Romanovsky
2022-11-10 22: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).