net: 802: enforce underlying device type for GARP and MRP
Subsystems (2)
PATCH 1/1 net: 802: enforce underlying device type for GARP and MRP
When creating a VLAN device, we initialize GARP (garp_init_applicant) and MRP (mrp_init_applicant) for the underlying device.
As part of the initialization process, we add the multicast address of each applicant to the underlying device, by calling dev_mc_add.
__dev_mc_add uses dev->addr_len to determine the length of the new multicast address.
This causes an out-of-bounds read if dev->addr_len is greater than 6, since the multicast addresses provided by GARP and MRP are only 6 bytes long.
This behaviour can be reproduced using the following commands:
ip tunnel add gretest mode ip6gre local ::1 remote ::2 dev lo ip l set up dev gretest
ip link add link gretest name vlantest type vlan id 100
Then, the following command will display the address of garp_pdu_rcv:
ip maddr show | grep 01:80:c2:00:00:21
Fix this by enforcing the type and address length of the underlying device during GARP and MRP initialization.
--- net/802/garp.c | 5 +++++ net/802/mrp.c | 5 +++++ 2 files changed, 10 insertions(+)
net/802/garp.c +5 -0
@@ -9,6 +9,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/llc.h> #include <linux/slab.h>
@@ -574,6 +575,10 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl)ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN ) + goto err1; +if (!rtnl_dereference (dev->garp_port)) { err =garp_init_port (dev);if (err <0 )
net/802/mrp.c +5 -0
@@ -12,6 +12,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <linux/module.h>
@@ -859,6 +860,10 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN ) + goto err1; +if (!rtnl_dereference (dev->mrp_port)) { err =mrp_init_port (dev);if (err <0 )
Signature · 1 line
2.39.5
Quoted 26 lines · Oscar Maes
When creating a VLAN device, we initialize GARP (
garp_init_applicant) and MRP (mrp_init_applicant) for the underlying device.As part of the initialization process, we add the multicast address of each applicant to the underlying device, by calling
dev_mc_add.
__dev_mc_addusesdev->addr_lento determine the length of the new multicast address.This causes an out-of-bounds read if
dev->addr_lenis greater than 6, since the multicast addresses provided by GARP and MRP are only 6 bytes long.This behaviour can be reproduced using the following commands:
ip tunnel add gretest mode ip6gre local ::1 remote ::2 dev lo ip l set up dev gretest
ip link add link gretest name vlantest type vlan id 100Then, the following command will display the address of
garp_pdu_rcv:ip maddr show | grep 01:80:c2:00:00:21
Fix this by enforcing the type and address length of the underlying device during GARP and MRP initialization.
Quoted 9 lines
Fixes 22bedad3ce11 ("net: convert multicast list to list_head")Reported-by syzbot <[email protected]>Signed-off-by Oscar Maes <[email protected]>--- net/802/garp.c | 5 +++++ net/802/mrp.c | 5 +++++ 2 files changed, 10 insertions(+)
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
Quoted 48 lines · Oscar Maes
When creating a VLAN device, we initialize GARP (
garp_init_applicant) and MRP (mrp_init_applicant) for the underlying device.As part of the initialization process, we add the multicast address of each applicant to the underlying device, by calling
dev_mc_add.
__dev_mc_addusesdev->addr_lento determine the length of the new multicast address.This causes an out-of-bounds read if
dev->addr_lenis greater than 6, since the multicast addresses provided by GARP and MRP are only 6 bytes long.This behaviour can be reproduced using the following commands:
ip tunnel add gretest mode ip6gre local ::1 remote ::2 dev lo ip l set up dev gretest
ip link add link gretest name vlantest type vlan id 100Then, the following command will display the address of
garp_pdu_rcv:ip maddr show | grep 01:80:c2:00:00:21
Fix this by enforcing the type and address length of the underlying device during GARP and MRP initialization.
Fixes 22bedad3ce11 ("net: convert multicast list to list_head")Reported-by syzbot <[email protected]>Signed-off-by Oscar Maes <[email protected]>--- net/802/garp.c | 5 +++++ net/802/mrp.c | 5 +++++ 2 files changed, 10 insertions(+)net/802/garp.c +1
-0@@ -9,6 +9,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/llc.h> #include <linux/slab.h>
net/802/garp.c int garp_init_applicant(struct net_device *dev, struct garp_application *appl) · line 579
Quoted 5 lines
net/802/garp.c +2
-0@@ -574,6 +575,10 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl)ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN )
Checking for 'ARPHRD_ETHER' is not enough? Other virtual devices such as macsec, macvlan and ipvlan only look at 'dev->type' AFAICT.
Also, how about moving this to vlan_check_real_dev()? It's common to both the IOCTL and netlink paths.
Quoted 32 lines
net/802/garp.c +2
-0+ goto err1; +if (!rtnl_dereference (dev->garp_port)) { err =garp_init_port (dev);if (err <0 )net/802/mrp.c +5
-0@@ -12,6 +12,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <linux/module.h> @@ -859,6 +860,10 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN ) + goto err1; +if (!rtnl_dereference (dev->mrp_port)) { err =mrp_init_port (dev);if (err <0 )Signature · 1 line
2.39.5
Quoted 50 lines · Ido Schimmel
Quoted 49 lines · Oscar Maes
When creating a VLAN device, we initialize GARP (
garp_init_applicant) and MRP (mrp_init_applicant) for the underlying device.As part of the initialization process, we add the multicast address of each applicant to the underlying device, by calling
dev_mc_add.
__dev_mc_addusesdev->addr_lento determine the length of the new multicast address.This causes an out-of-bounds read if
dev->addr_lenis greater than 6, since the multicast addresses provided by GARP and MRP are only 6 bytes long.This behaviour can be reproduced using the following commands:
ip tunnel add gretest mode ip6gre local ::1 remote ::2 dev lo ip l set up dev gretest
ip link add link gretest name vlantest type vlan id 100Then, the following command will display the address of
garp_pdu_rcv:ip maddr show | grep 01:80:c2:00:00:21
Fix this by enforcing the type and address length of the underlying device during GARP and MRP initialization.
Fixes 22bedad3ce11 ("net: convert multicast list to list_head")Reported-by syzbot <[email protected]>Signed-off-by Oscar Maes <[email protected]>--- net/802/garp.c | 5 +++++ net/802/mrp.c | 5 +++++ 2 files changed, 10 insertions(+)net/802/garp.c +1
-0@@ -9,6 +9,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/llc.h> #include <linux/slab.h> @@ -574,6 +575,10 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl)
Quoted 7 lines
net/802/garp.c int garp_init_applicant(struct net_device *dev, struct garp_application *appl) · line 579
Quoted 4 lines
net/802/garp.c +2
-0ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN )Checking for '
ARPHRD_ETHER' is not enough? Other virtual devices such as macsec, macvlan and ipvlan only look at 'dev->type' AFAICT.
Agreed, I will change this.
Quoted 3 lines
Also, how about moving this to
vlan_check_real_dev()? It's common to both the IOCTL and netlink paths.
{garp,mrp}_init_applicant assume that the address length is 6-bytes, when they call dev_mc_add with a 6-byte buffer.
I think that the ARPHRD check should be right before calling dev_mc_add.
Currently, GARP is only used by VLAN, which means your suggestion would technically work, but this assumption might be violated by future protocol implementations like GMRP, which could potentially resurface this bug.
Quoted 33 lines
Quoted 33 lines
net/802/garp.c +2
-0+ goto err1; +if (!rtnl_dereference (dev->garp_port)) { err =garp_init_port (dev);if (err <0 )net/802/mrp.c +5
-0@@ -12,6 +12,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <linux/module.h> @@ -859,6 +860,10 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN ) + goto err1; +if (!rtnl_dereference (dev->mrp_port)) { err =mrp_init_port (dev);if (err <0 )Signature · 1 line
2.39.5
Quoted 65 lines · Oscar Maes
Quoted 50 lines · Ido Schimmel
Quoted 49 lines · Oscar Maes
When creating a VLAN device, we initialize GARP (
garp_init_applicant) and MRP (mrp_init_applicant) for the underlying device.As part of the initialization process, we add the multicast address of each applicant to the underlying device, by calling
dev_mc_add.
__dev_mc_addusesdev->addr_lento determine the length of the new multicast address.This causes an out-of-bounds read if
dev->addr_lenis greater than 6, since the multicast addresses provided by GARP and MRP are only 6 bytes long.This behaviour can be reproduced using the following commands:
ip tunnel add gretest mode ip6gre local ::1 remote ::2 dev lo ip l set up dev gretest
ip link add link gretest name vlantest type vlan id 100Then, the following command will display the address of
garp_pdu_rcv:ip maddr show | grep 01:80:c2:00:00:21
Fix this by enforcing the type and address length of the underlying device during GARP and MRP initialization.
Fixes 22bedad3ce11 ("net: convert multicast list to list_head")Reported-by syzbot <[email protected]>Signed-off-by Oscar Maes <[email protected]>--- net/802/garp.c | 5 +++++ net/802/mrp.c | 5 +++++ 2 files changed, 10 insertions(+)net/802/garp.c +1
-0@@ -9,6 +9,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/llc.h> #include <linux/slab.h> @@ -574,6 +575,10 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl)Quoted 7 lines
net/802/garp.c int garp_init_applicant(struct net_device *dev, struct garp_application *appl) · line 579
Quoted 4 lines
net/802/garp.c +2
-0ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN )Checking for '
ARPHRD_ETHER' is not enough? Other virtual devices such as macsec, macvlan and ipvlan only look at 'dev->type' AFAICT.Agreed, I will change this.
Quoted 3 lines
Also, how about moving this to
vlan_check_real_dev()? It's common to both the IOCTL and netlink paths.
Quoted 7 lines
{garp,mrp}_init_applicant assume that the address length is 6-bytes, when they call
dev_mc_addwith a 6-byte buffer.
I think that the ARPHRD check should be right before callingdev_mc_add.Currently, GARP is only used by VLAN, which means your suggestion would technically work, but this assumption might be violated by future protocol implementations like GMRP, which could potentially resurface this bug.
I disagree. The problem is in the caller (the VLAN driver). It should explicitly check for the error condition (real device not being Ethernet) and bail out as soon as possible (in vlan_check_real_dev()) with an appropriate error message. It should not rely on the first function where this error condition happened to explode to do the verification, especially when this function can be compiled out (e.g., CONFIG_VLAN_8021Q_GVRP=n).
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
net/802/garp.c +2
-0+ goto err1; +if (!rtnl_dereference (dev->garp_port)) { err =garp_init_port (dev);if (err <0 )net/802/mrp.c +5
-0@@ -12,6 +12,7 @@#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <linux/module.h> @@ -859,6 +860,10 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)ASSERT_RTNL (); + err = -EINVAL ; +if (dev->type !=ARPHRD_ETHER || dev->addr_len !=ETH_ALEN ) + goto err1; +if (!rtnl_dereference (dev->mrp_port)) { err =mrp_init_port (dev);if (err <0 )Signature · 1 line
2.39.5