netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK
@ 2023-08-23  6:43 Ido Schimmel
  2023-08-24  2:06 ` Jakub Kicinski
  2023-08-24  8:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ido Schimmel @ 2023-08-23  6:43 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, pabeni, edumazet, razor, jiri, mlxsw, Ido Schimmel

Negative ifindexes are illegal, but the kernel does not validate the
ifindex in the ancillary header of RTM_NEWLINK messages, resulting in
the kernel generating a warning [1] when such an ifindex is specified.

Fix by rejecting negative ifindexes.

[1]
WARNING: CPU: 0 PID: 5031 at net/core/dev.c:9593 dev_index_reserve+0x1a2/0x1c0 net/core/dev.c:9593
[...]
Call Trace:
 <TASK>
 register_netdevice+0x69a/0x1490 net/core/dev.c:10081
 br_dev_newlink+0x27/0x110 net/bridge/br_netlink.c:1552
 rtnl_newlink_create net/core/rtnetlink.c:3471 [inline]
 __rtnl_newlink+0x115e/0x18c0 net/core/rtnetlink.c:3688
 rtnl_newlink+0x67/0xa0 net/core/rtnetlink.c:3701
 rtnetlink_rcv_msg+0x439/0xd30 net/core/rtnetlink.c:6427
 netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2545
 netlink_unicast_kernel net/netlink/af_netlink.c:1342 [inline]
 netlink_unicast+0x536/0x810 net/netlink/af_netlink.c:1368
 netlink_sendmsg+0x93c/0xe40 net/netlink/af_netlink.c:1910
 sock_sendmsg_nosec net/socket.c:728 [inline]
 sock_sendmsg+0xd9/0x180 net/socket.c:751
 ____sys_sendmsg+0x6ac/0x940 net/socket.c:2538
 ___sys_sendmsg+0x135/0x1d0 net/socket.c:2592
 __sys_sendmsg+0x117/0x1e0 net/socket.c:2621
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Fixes: 38f7b870d4a6 ("[RTNETLINK]: Link creation API")
Reported-by: syzbot+5ba06978f34abb058571@syzkaller.appspotmail.com
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 net/core/rtnetlink.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index bcebdeb59163..00c94d9622b4 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3561,6 +3561,9 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (ifm->ifi_index > 0) {
 		link_specified = true;
 		dev = __dev_get_by_index(net, ifm->ifi_index);
+	} else if (ifm->ifi_index < 0) {
+		NL_SET_ERR_MSG(extack, "ifindex can't be negative");
+		return -EINVAL;
 	} else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME]) {
 		link_specified = true;
 		dev = rtnl_dev_get(net, tb);
-- 
2.40.1


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

* Re: [PATCH net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK
  2023-08-23  6:43 [PATCH net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK Ido Schimmel
@ 2023-08-24  2:06 ` Jakub Kicinski
  2023-08-24  8:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2023-08-24  2:06 UTC (permalink / raw)
  To: Ido Schimmel; +Cc: netdev, davem, pabeni, edumazet, razor, jiri, mlxsw

On Wed, 23 Aug 2023 09:43:48 +0300 Ido Schimmel wrote:
> Negative ifindexes are illegal, but the kernel does not validate the
> ifindex in the ancillary header of RTM_NEWLINK messages, resulting in
> the kernel generating a warning [1] when such an ifindex is specified.

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

Thanks!

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

* Re: [PATCH net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK
  2023-08-23  6:43 [PATCH net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK Ido Schimmel
  2023-08-24  2:06 ` Jakub Kicinski
@ 2023-08-24  8:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-24  8:00 UTC (permalink / raw)
  To: Ido Schimmel; +Cc: netdev, davem, kuba, pabeni, edumazet, razor, jiri, mlxsw

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Wed, 23 Aug 2023 09:43:48 +0300 you wrote:
> Negative ifindexes are illegal, but the kernel does not validate the
> ifindex in the ancillary header of RTM_NEWLINK messages, resulting in
> the kernel generating a warning [1] when such an ifindex is specified.
> 
> Fix by rejecting negative ifindexes.
> 
> [1]
> WARNING: CPU: 0 PID: 5031 at net/core/dev.c:9593 dev_index_reserve+0x1a2/0x1c0 net/core/dev.c:9593
> [...]
> Call Trace:
>  <TASK>
>  register_netdevice+0x69a/0x1490 net/core/dev.c:10081
>  br_dev_newlink+0x27/0x110 net/bridge/br_netlink.c:1552
>  rtnl_newlink_create net/core/rtnetlink.c:3471 [inline]
>  __rtnl_newlink+0x115e/0x18c0 net/core/rtnetlink.c:3688
>  rtnl_newlink+0x67/0xa0 net/core/rtnetlink.c:3701
>  rtnetlink_rcv_msg+0x439/0xd30 net/core/rtnetlink.c:6427
>  netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2545
>  netlink_unicast_kernel net/netlink/af_netlink.c:1342 [inline]
>  netlink_unicast+0x536/0x810 net/netlink/af_netlink.c:1368
>  netlink_sendmsg+0x93c/0xe40 net/netlink/af_netlink.c:1910
>  sock_sendmsg_nosec net/socket.c:728 [inline]
>  sock_sendmsg+0xd9/0x180 net/socket.c:751
>  ____sys_sendmsg+0x6ac/0x940 net/socket.c:2538
>  ___sys_sendmsg+0x135/0x1d0 net/socket.c:2592
>  __sys_sendmsg+0x117/0x1e0 net/socket.c:2621
>  do_syscall_x64 arch/x86/entry/common.c:50 [inline]
>  do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
>  entry_SYSCALL_64_after_hwframe+0x63/0xcd
> 
> [...]

Here is the summary with links:
  - [net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK
    https://git.kernel.org/netdev/net/c/30188bd7838c

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] 3+ messages in thread

end of thread, other threads:[~2023-08-24  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-23  6:43 [PATCH net] rtnetlink: Reject negative ifindexes in RTM_NEWLINK Ido Schimmel
2023-08-24  2:06 ` Jakub Kicinski
2023-08-24  8:00 ` 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).