* [PATCH net] net: validate veth and vxcan peer ifindexes
@ 2023-08-19 1:26 Jakub Kicinski
2023-08-19 3:23 ` Eric Dumazet
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jakub Kicinski @ 2023-08-19 1:26 UTC (permalink / raw)
To: davem
Cc: netdev, edumazet, pabeni, Jakub Kicinski,
syzbot+5ba06978f34abb058571, wg, mkl, idosch, lucien.xin, xemul,
socketcan, linux-can
veth and vxcan need to make sure the ifindexes of the peer
are not negative, core does not validate this.
Using iproute2 with user-space-level checking removed:
Before:
# ./ip link add index 10 type veth peer index -1
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:74:b2:03 brd ff:ff:ff:ff:ff:ff
10: veth1@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 8a:90:ff:57:6d:5d brd ff:ff:ff:ff:ff:ff
-1: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether ae:ed:18:e6:fa:7f brd ff:ff:ff:ff:ff:ff
Now:
$ ./ip link add index 10 type veth peer index -1
Error: ifindex can't be negative.
This problem surfaced in net-next because an explicit WARN()
was added, the root cause is older.
Fixes: e6f8f1a739b6 ("veth: Allow to create peer link with given ifindex")
Fixes: a8f820a380a2 ("can: add Virtual CAN Tunnel driver (vxcan)")
Reported-by: syzbot+5ba06978f34abb058571@syzkaller.appspotmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: wg@grandegger.com
CC: mkl@pengutronix.de
CC: idosch@nvidia.com
CC: lucien.xin@gmail.com
CC: xemul@parallels.com
CC: socketcan@hartkopp.net
CC: linux-can@vger.kernel.org
---
drivers/net/can/vxcan.c | 7 +------
drivers/net/veth.c | 5 +----
include/net/rtnetlink.h | 4 ++--
net/core/rtnetlink.c | 22 ++++++++++++++++++----
4 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c
index 4068d962203d..98c669ad5141 100644
--- a/drivers/net/can/vxcan.c
+++ b/drivers/net/can/vxcan.c
@@ -192,12 +192,7 @@ static int vxcan_newlink(struct net *net, struct net_device *dev,
nla_peer = data[VXCAN_INFO_PEER];
ifmp = nla_data(nla_peer);
- err = rtnl_nla_parse_ifla(peer_tb,
- nla_data(nla_peer) +
- sizeof(struct ifinfomsg),
- nla_len(nla_peer) -
- sizeof(struct ifinfomsg),
- NULL);
+ err = rtnl_nla_parse_ifinfomsg(peer_tb, nla_peer, extack);
if (err < 0)
return err;
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 509e901da41d..ef8eacb596f7 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1861,10 +1861,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
nla_peer = data[VETH_INFO_PEER];
ifmp = nla_data(nla_peer);
- err = rtnl_nla_parse_ifla(peer_tb,
- nla_data(nla_peer) + sizeof(struct ifinfomsg),
- nla_len(nla_peer) - sizeof(struct ifinfomsg),
- NULL);
+ err = rtnl_nla_parse_ifinfomsg(peer_tb, nla_peer, extack);
if (err < 0)
return err;
diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index d9076a7a430c..6506221c5fe3 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -190,8 +190,8 @@ int rtnl_delete_link(struct net_device *dev, u32 portid, const struct nlmsghdr *
int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm,
u32 portid, const struct nlmsghdr *nlh);
-int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
- struct netlink_ext_ack *exterr);
+int rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer,
+ struct netlink_ext_ack *exterr);
struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid);
#define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index aef25aa5cf1d..bcebdeb59163 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2268,13 +2268,27 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
return err;
}
-int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
- struct netlink_ext_ack *exterr)
+int rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer,
+ struct netlink_ext_ack *exterr)
{
- return nla_parse_deprecated(tb, IFLA_MAX, head, len, ifla_policy,
+ const struct ifinfomsg *ifmp;
+ const struct nlattr *attrs;
+ size_t len;
+
+ ifmp = nla_data(nla_peer);
+ attrs = nla_data(nla_peer) + sizeof(struct ifinfomsg);
+ len = nla_len(nla_peer) - sizeof(struct ifinfomsg);
+
+ if (ifmp->ifi_index < 0) {
+ NL_SET_ERR_MSG_ATTR(exterr, nla_peer,
+ "ifindex can't be negative");
+ return -EINVAL;
+ }
+
+ return nla_parse_deprecated(tb, IFLA_MAX, attrs, len, ifla_policy,
exterr);
}
-EXPORT_SYMBOL(rtnl_nla_parse_ifla);
+EXPORT_SYMBOL(rtnl_nla_parse_ifinfomsg);
struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
{
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: validate veth and vxcan peer ifindexes
2023-08-19 1:26 [PATCH net] net: validate veth and vxcan peer ifindexes Jakub Kicinski
@ 2023-08-19 3:23 ` Eric Dumazet
2023-08-20 10:49 ` patchwork-bot+netdevbpf
2023-08-20 16:08 ` Ido Schimmel
2 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2023-08-19 3:23 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, pabeni, syzbot+5ba06978f34abb058571, wg, mkl,
idosch, lucien.xin, xemul, socketcan, linux-can
On Sat, Aug 19, 2023 at 3:26 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> veth and vxcan need to make sure the ifindexes of the peer
> are not negative, core does not validate this.
>
> Using iproute2 with user-space-level checking removed:
>
> Before:
>
> # ./ip link add index 10 type veth peer index -1
> # ip link show
> 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
> link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
> 2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
> link/ether 52:54:00:74:b2:03 brd ff:ff:ff:ff:ff:ff
> 10: veth1@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
> link/ether 8a:90:ff:57:6d:5d brd ff:ff:ff:ff:ff:ff
> -1: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
> link/ether ae:ed:18:e6:fa:7f brd ff:ff:ff:ff:ff:ff
>
> Now:
>
> $ ./ip link add index 10 type veth peer index -1
> Error: ifindex can't be negative.
>
> This problem surfaced in net-next because an explicit WARN()
> was added, the root cause is older.
>
> Fixes: e6f8f1a739b6 ("veth: Allow to create peer link with given ifindex")
> Fixes: a8f820a380a2 ("can: add Virtual CAN Tunnel driver (vxcan)")
> Reported-by: syzbot+5ba06978f34abb058571@syzkaller.appspotmail.com
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
SGTM, I was not sure how to fix this myself ;)
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: validate veth and vxcan peer ifindexes
2023-08-19 1:26 [PATCH net] net: validate veth and vxcan peer ifindexes Jakub Kicinski
2023-08-19 3:23 ` Eric Dumazet
@ 2023-08-20 10:49 ` patchwork-bot+netdevbpf
2023-08-20 16:08 ` Ido Schimmel
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-20 10:49 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, syzbot+5ba06978f34abb058571, wg,
mkl, idosch, lucien.xin, xemul, socketcan, linux-can
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 18 Aug 2023 18:26:02 -0700 you wrote:
> veth and vxcan need to make sure the ifindexes of the peer
> are not negative, core does not validate this.
>
> Using iproute2 with user-space-level checking removed:
>
> Before:
>
> [...]
Here is the summary with links:
- [net] net: validate veth and vxcan peer ifindexes
https://git.kernel.org/netdev/net/c/f534f6581ec0
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] 6+ messages in thread
* Re: [PATCH net] net: validate veth and vxcan peer ifindexes
2023-08-19 1:26 [PATCH net] net: validate veth and vxcan peer ifindexes Jakub Kicinski
2023-08-19 3:23 ` Eric Dumazet
2023-08-20 10:49 ` patchwork-bot+netdevbpf
@ 2023-08-20 16:08 ` Ido Schimmel
2023-08-21 17:48 ` Jakub Kicinski
2 siblings, 1 reply; 6+ messages in thread
From: Ido Schimmel @ 2023-08-20 16:08 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, syzbot+5ba06978f34abb058571, wg,
mkl, idosch, lucien.xin, xemul, socketcan, linux-can
On Fri, Aug 18, 2023 at 06:26:02PM -0700, Jakub Kicinski wrote:
> veth and vxcan need to make sure the ifindexes of the peer
> are not negative, core does not validate this.
>
> Using iproute2 with user-space-level checking removed:
>
> Before:
>
> # ./ip link add index 10 type veth peer index -1
> # ip link show
> 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
> link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
> 2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
> link/ether 52:54:00:74:b2:03 brd ff:ff:ff:ff:ff:ff
> 10: veth1@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
> link/ether 8a:90:ff:57:6d:5d brd ff:ff:ff:ff:ff:ff
> -1: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
> link/ether ae:ed:18:e6:fa:7f brd ff:ff:ff:ff:ff:ff
>
> Now:
>
> $ ./ip link add index 10 type veth peer index -1
> Error: ifindex can't be negative.
>
> This problem surfaced in net-next because an explicit WARN()
> was added, the root cause is older.
>
> Fixes: e6f8f1a739b6 ("veth: Allow to create peer link with given ifindex")
> Fixes: a8f820a380a2 ("can: add Virtual CAN Tunnel driver (vxcan)")
> Reported-by: syzbot+5ba06978f34abb058571@syzkaller.appspotmail.com
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
There is another report here [1] with a reproducer [2]. Even with this
patch, the reproducer can still trigger the warning on net-next. Don't
we also need to reject a negative ifindex in the ancillary header? At
least with the following diff the warning does not trigger anymore:
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 7aba4d63b069..4a2ec33bfb51 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3560,6 +3560,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);
[1] https://syzkaller.appspot.com/text?tag=CrashReport&x=178edad3a80000
[2] https://syzkaller.appspot.com/text?tag=ReproC&x=166ed6bba80000
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: validate veth and vxcan peer ifindexes
2023-08-20 16:08 ` Ido Schimmel
@ 2023-08-21 17:48 ` Jakub Kicinski
2023-08-22 10:39 ` Ido Schimmel
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2023-08-21 17:48 UTC (permalink / raw)
To: Ido Schimmel
Cc: davem, netdev, edumazet, pabeni, syzbot+5ba06978f34abb058571, wg,
mkl, idosch, lucien.xin, xemul, socketcan, linux-can
On Sun, 20 Aug 2023 19:08:13 +0300 Ido Schimmel wrote:
> There is another report here [1] with a reproducer [2]. Even with this
> patch, the reproducer can still trigger the warning on net-next. Don't
> we also need to reject a negative ifindex in the ancillary header? At
> least with the following diff the warning does not trigger anymore:
Yeah, definitely, please go ahead and submit.
Is "ancillary header" used more commonly as a term? in gnel we usually
call this thing "user header" or "fixed header".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: validate veth and vxcan peer ifindexes
2023-08-21 17:48 ` Jakub Kicinski
@ 2023-08-22 10:39 ` Ido Schimmel
0 siblings, 0 replies; 6+ messages in thread
From: Ido Schimmel @ 2023-08-22 10:39 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, syzbot+5ba06978f34abb058571, wg,
mkl, idosch, lucien.xin, xemul, socketcan, linux-can
On Mon, Aug 21, 2023 at 10:48:44AM -0700, Jakub Kicinski wrote:
> On Sun, 20 Aug 2023 19:08:13 +0300 Ido Schimmel wrote:
> > There is another report here [1] with a reproducer [2]. Even with this
> > patch, the reproducer can still trigger the warning on net-next. Don't
> > we also need to reject a negative ifindex in the ancillary header? At
> > least with the following diff the warning does not trigger anymore:
>
> Yeah, definitely, please go ahead and submit.
Sure, will submit tomorrow morning.
> Is "ancillary header" used more commonly as a term? in gnel we usually
> call this thing "user header" or "fixed header".
I honestly don't know. IIRC I saw David using the term a few years ago
and decided to adopt it.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-22 10:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-19 1:26 [PATCH net] net: validate veth and vxcan peer ifindexes Jakub Kicinski
2023-08-19 3:23 ` Eric Dumazet
2023-08-20 10:49 ` patchwork-bot+netdevbpf
2023-08-20 16:08 ` Ido Schimmel
2023-08-21 17:48 ` Jakub Kicinski
2023-08-22 10:39 ` Ido Schimmel
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).