netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: 802: enforce underlying device type for GARP and MRP
@ 2025-02-12 11:32 Oscar Maes
  2025-02-12 12:36 ` Greg KH
  2025-02-12 14:29 ` Ido Schimmel
  0 siblings, 2 replies; 5+ messages in thread
From: Oscar Maes @ 2025-02-12 11:32 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, horms, viro, jiri, linux-kernel,
	security, Oscar Maes, syzbot

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)
+		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


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

end of thread, other threads:[~2025-02-25 19:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 11:32 [PATCH net] net: 802: enforce underlying device type for GARP and MRP Oscar Maes
2025-02-12 12:36 ` Greg KH
2025-02-12 14:29 ` Ido Schimmel
2025-02-25 14:11   ` Oscar Maes
2025-02-25 19: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).