diff mbox series

[net] net: 802: enforce underlying device type for GARP and MRP

Message ID 20250212113218.9859-1-oscmaes92@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] net: 802: enforce underlying device type for GARP and MRP | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 34 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-12--18-00 (tests: 888)

Commit Message

Oscar Maes Feb. 12, 2025, 11:32 a.m. UTC
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.

Fixes: 22bedad3ce11 ("net: convert multicast list to list_head")
Reported-by: syzbot <syzbot+91161fe81857b396c8a0@syzkaller.appspotmail.com>
Closes: https://lore.kernel.org/netdev/000000000000ca9a81061a01ec20@google.com/
Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
---
 net/802/garp.c | 5 +++++
 net/802/mrp.c  | 5 +++++
 2 files changed, 10 insertions(+)

Comments

Greg Kroah-Hartman Feb. 12, 2025, 12:36 p.m. UTC | #1
On Wed, Feb 12, 2025 at 12:32:18PM +0100, Oscar Maes wrote:
> 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.
> 
> Fixes: 22bedad3ce11 ("net: convert multicast list to list_head")
> Reported-by: syzbot <syzbot+91161fe81857b396c8a0@syzkaller.appspotmail.com>
> Closes: https://lore.kernel.org/netdev/000000000000ca9a81061a01ec20@google.com/
> Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
> ---
>  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
Ido Schimmel Feb. 12, 2025, 2:29 p.m. UTC | #2
On Wed, Feb 12, 2025 at 12:32:18PM +0100, Oscar Maes wrote:
> 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.
> 
> Fixes: 22bedad3ce11 ("net: convert multicast list to list_head")
> Reported-by: syzbot <syzbot+91161fe81857b396c8a0@syzkaller.appspotmail.com>
> Closes: https://lore.kernel.org/netdev/000000000000ca9a81061a01ec20@google.com/
> Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
> ---
>  net/802/garp.c | 5 +++++
>  net/802/mrp.c  | 5 +++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/net/802/garp.c b/net/802/garp.c
> index 27f0ab146..2f383ee73 100644
> --- a/net/802/garp.c
> +++ b/net/802/garp.c
> @@ -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)

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.

> +		goto err1;
> +
>  	if (!rtnl_dereference(dev->garp_port)) {
>  		err = garp_init_port(dev);
>  		if (err < 0)
> diff --git a/net/802/mrp.c b/net/802/mrp.c
> index e0c96d0da..1efee0b39 100644
> --- a/net/802/mrp.c
> +++ b/net/802/mrp.c
> @@ -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)
> -- 
> 2.39.5
> 
>
diff mbox series

Patch

diff --git a/net/802/garp.c b/net/802/garp.c
index 27f0ab146..2f383ee73 100644
--- a/net/802/garp.c
+++ b/net/802/garp.c
@@ -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)
diff --git a/net/802/mrp.c b/net/802/mrp.c
index e0c96d0da..1efee0b39 100644
--- a/net/802/mrp.c
+++ b/net/802/mrp.c
@@ -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)