Skip to contentSkip to conversation

6lowpan: fix netdev_priv() type confusion in lowpan_event()

PATCH In review Roman Gushchin 4 participants 6 messages Nov 6 – Nov 13

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 6lowpan: fix netdev_priv() type confusion in lowpan_event()

lowpan_event() assumes any netdevice with dev->type == ARPHRD_6LOWPAN has a struct lowpan_dev in netdev_priv(dev). However, non-6LoWPAN devices can also have ARPHRD_6LOWPAN, e.g. a TUN device via TUNSETLINK or a bonding device inheriting dev->type from its lower device.

Bringing such a device up or down causes lowpan_event() to read and overwrite unrelated netdev_priv() memory. Since unprivileged users can create TUN and bonding devices in a user and network namespace, they can corrupt struct bonding and trigger a slab use-after-free.

Also check dev->ndisc_ops == &lowpan_ndisc_ops, which is set only by lowpan_register_netdevice() on genuine 6LoWPAN devices.

Fixes 5609c185f24d ("6lowpan: iphc: add support for stateful compression")
Fixes 2ad3ed59198c ("6lowpan: add 802.15.4 short addr slaac")
---
 net/6lowpan/6lowpan_i.h | 13 ++++++++++---
 net/6lowpan/core.c      |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)
net/6lowpan/6lowpan_i.h +10 -3
index 01853cec0209..07f11d4dde6e 100644
@@ -2,19 +2,26 @@
 #ifndef __6LOWPAN_I_H
 #define __6LOWPAN_I_H
 
+#include <linux/if_arp.h>
 #include <linux/netdevice.h>
 
 #include <net/6lowpan.h>
 
-/* caller need to be sure it's dev->type is ARPHRD_6LOWPAN */
+extern const struct ndisc_ops lowpan_ndisc_ops;
+
+static inline bool lowpan_is_dev(const struct net_device *dev)
+{
+	return dev->type == ARPHRD_6LOWPAN &&
+	       dev->ndisc_ops == &lowpan_ndisc_ops;
+}
+
+/* caller must ensure lowpan_is_dev(dev) is true */
 static inline bool lowpan_is_ll(const struct net_device *dev,
 				enum lowpan_lltypes lltype)
 {
 	return lowpan_dev(dev)->lltype == lltype;
 }
 
-extern const struct ndisc_ops lowpan_ndisc_ops;
-
 int addrconf_ifid_802154_6lowpan(u8 *eui, struct net_device *dev);
 
 #ifdef CONFIG_6LOWPAN_DEBUGFS
net/6lowpan/core.c +1 -1
index 850d4a185f55..748103d37e31 100644
@@ -113,7 +113,7 @@ static int lowpan_event(struct notifier_block *unused,
 	struct in6_addr addr;
 	int i;
 
-	if (dev->type != ARPHRD_6LOWPAN)
+	if (!lowpan_is_dev(dev))
 		return NOTIFY_DONE;
 
 	idev = __in6_dev_get(dev);
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

#2 lore raw
Quoted 9 lines · [email protected] writes:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Quoted 8 lines

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

I've a reproducer which I don't want to post publicly but can share privately.

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Roman Gushchin
Quoted 14 lines · Roman Gushchin

lowpan_event() assumes any netdevice with dev->type == ARPHRD_6LOWPAN has a struct lowpan_dev in netdev_priv(dev). However, non-6LoWPAN devices can also have ARPHRD_6LOWPAN, e.g. a TUN device via TUNSETLINK or a bonding device inheriting dev->type from its lower device.

Bringing such a device up or down causes lowpan_event() to read and overwrite unrelated netdev_priv() memory. Since unprivileged users can create TUN and bonding devices in a user and network namespace, they can corrupt struct bonding and trigger a slab use-after-free.

Also check dev->ndisc_ops == &lowpan_ndisc_ops, which is set only by lowpan_register_netdevice() on genuine 6LoWPAN devices.

Quoted 6 lines
Fixes 5609c185f24d ("6lowpan: iphc: add support for stateful compression")
Fixes 2ad3ed59198c ("6lowpan: add 802.15.4 short addr slaac")

nit: Signed-off-by should come last, after Fixes:/Reported-by:/Closes:.

The fix itself looks right to me: lowpan_register_netdevice() is the only place setting dev->ndisc_ops to &lowpan_ndisc_ops, and bond_setup_by_slave() does not copy ndisc_ops, so this is a reliable discriminator.

Thanks.

#4 lore raw
Quoted 24 lines · Eric Dumazet
Quoted 14 lines · Roman Gushchin

lowpan_event() assumes any netdevice with dev->type == ARPHRD_6LOWPAN has a struct lowpan_dev in netdev_priv(dev). However, non-6LoWPAN devices can also have ARPHRD_6LOWPAN, e.g. a TUN device via TUNSETLINK or a bonding device inheriting dev->type from its lower device.

Bringing such a device up or down causes lowpan_event() to read and overwrite unrelated netdev_priv() memory. Since unprivileged users can create TUN and bonding devices in a user and network namespace, they can corrupt struct bonding and trigger a slab use-after-free.

Also check dev->ndisc_ops == &lowpan_ndisc_ops, which is set only by lowpan_register_netdevice() on genuine 6LoWPAN devices.

Quoted 6 lines
Fixes 5609c185f24d ("6lowpan: iphc: add support for stateful compression")
Fixes 2ad3ed59198c ("6lowpan: add 802.15.4 short addr slaac")

nit: Signed-off-by should come last, after Fixes:/Reported-by:/Closes:.

Quoted 7 lines

The fix itself looks right to me: lowpan_register_netdevice() is the only place setting dev->ndisc_ops to &lowpan_ndisc_ops, and bond_setup_by_slave() does not copy ndisc_ops, so this is a reliable discriminator.

Thanks.

Thank you for review!

Should I re-spin it with the correct tags order?

Thanks

#5 lore raw
In reply to Roman Gushchin

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1204595/

---Test result---

Test Summary:

CheckPatch                    PASS      3.26 seconds
VerifyFixes                   PASS      0.13 seconds
VerifySignedoff               PASS      0.90 seconds
GitLint                       PASS      0.34 seconds
SubjectPrefix                 FAIL      0.18 seconds
BuildKernel                   PASS      31.03 seconds
CheckAllWarning               PASS      35.02 seconds
CheckSparse                   PASS      39.77 seconds
BuildKernel32                 PASS      31.26 seconds
CheckKernelLLVM               PASS      35.89 seconds
TestRunnerSetup               PASS      748.50 seconds
TestRunner_l2cap-tester       PASS      12.85 seconds
TestRunner_iso-tester         PASS      11.04 seconds
TestRunner_bnep-tester        PASS      4.13 seconds
TestRunner_mgmt-tester        PASS      89.48 seconds
TestRunner_rfcomm-tester      PASS      8.33 seconds
TestRunner_sco-tester         PASS      5.80 seconds
TestRunner_ioctl-tester       PASS      4.76 seconds
TestRunner_mesh-tester        PASS      5.59 seconds
TestRunner_smp-tester         PASS      4.44 seconds
TestRunner_userchan-tester    PASS      3.30 seconds
TestRunner_6lowpan-tester     PASS      4.55 seconds
IncrementalBuild              PASS      28.41 seconds

Details
##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix Output:
"Bluetooth: " prefix is not specified in the subject

https://github.com/bluez/bluetooth-next/pull/1083

---
Regards,
Linux Bluetooth