Skip to contentSkip to conversation

Question about possible CMD misuse in devlink_nl_port_new_doit()

net/devlink Chenyuan Yang 2 participants 3 messages Mar 17, 2024 – Mar 18, 2024

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

Dear Devlink Developers,

We are curious whether the function devlink_nl_port_new_doit() might have a incorrect command value DEVLINK_CMD_NEW, which should be DEVLINK_CMD_PORT_NEW.

The function is https://elixir.bootlin.com/linux/v6.8/source/net/devlink/port.c#L844
and the relevant code is

```
int devlink_nl_port_new_doit(struct sk_buff *skb, struct genl_info *info)
{
	...
	err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
				   info->snd_portid, info->snd_seq, 0, NULL);
	if (WARN_ON_ONCE(err))
		goto err_out_msg_free;
	...
}
```

In devlink_nl_port_fill, all other places use DEVLINK_CMD_PORT_NEW as the command value. However, in devlink_nl_port_new_doit, it uses DEVLINK_CMD_NEW. This might be a misuse, also according to https://lore.kernel.org/netdev/[email protected]/T/.

Based on our understanding, a possible fix would be

```
-  err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
+  err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_PORT_NEW,
```

Please kindly correct us if we missed any key information. Looking forward to your response!

Best,
Chenyuan

#1 lore raw
Quoted 26 lines · Sun, Mar 17, 2024 at 03:57:19AM CET, [email protected] wrote:

Dear Devlink Developers,

We are curious whether the function devlink_nl_port_new_doit() might have a incorrect command value DEVLINK_CMD_NEW, which should be DEVLINK_CMD_PORT_NEW.

The function is https://elixir.bootlin.com/linux/v6.8/source/net/devlink/port.c#L844
and the relevant code is

```
int devlink_nl_port_new_doit(struct sk_buff *skb, struct genl_info *info)
{
	...
	err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
				   info->snd_portid, info->snd_seq, 0, NULL);
	if (WARN_ON_ONCE(err))
		goto err_out_msg_free;
	...
}
```

In devlink_nl_port_fill, all other places use DEVLINK_CMD_PORT_NEW as the command value. However, in devlink_nl_port_new_doit, it uses DEVLINK_CMD_NEW. This might be a misuse, also according to https://lore.kernel.org/netdev/[email protected]/T/.

Based on our understanding, a possible fix would be ```

(quoted diff) +1 -1
-  err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
+  err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_PORT_NEW,

```

Quoted 1 line

Please kindly correct us if we missed any key information. Looking forward to your response!

You are correct, this is a bug. Thanks for report! Here's the fix:
https://lore.kernel.org/netdev/[email protected]/

#2 lore raw

Thank you so much for your prompt reply and fix!

Best,
Chenyuan

Quoted 35 lines · Jiri Pirko
Quoted 26 lines · Sun, Mar 17, 2024 at 03:57:19AM CET, [email protected] wrote:

Dear Devlink Developers,

We are curious whether the function devlink_nl_port_new_doit() might have a incorrect command value DEVLINK_CMD_NEW, which should be DEVLINK_CMD_PORT_NEW.

The function is https://elixir.bootlin.com/linux/v6.8/source/net/devlink/port.c#L844
and the relevant code is

```
int devlink_nl_port_new_doit(struct sk_buff *skb, struct genl_info *info)
{
      ...
      err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
                                 info->snd_portid, info->snd_seq, 0, NULL);
      if (WARN_ON_ONCE(err))
              goto err_out_msg_free;
      ...
}
```

In devlink_nl_port_fill, all other places use DEVLINK_CMD_PORT_NEW as the command value. However, in devlink_nl_port_new_doit, it uses DEVLINK_CMD_NEW. This might be a misuse, also according to https://lore.kernel.org/netdev/[email protected]/T/.

Based on our understanding, a possible fix would be ```

(quoted diff) +1 -1
-  err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
+  err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_PORT_NEW,

```

Quoted 1 line

Please kindly correct us if we missed any key information. Looking forward to your response!

You are correct, this is a bug. Thanks for report! Here's the fix:
https://lore.kernel.org/netdev/[email protected]/