Re: [PATCH] ieee802154: nl-mac: validate device pointers before dereference

From: Kalpesh Solanki

Date: Sun Nov 01 2026 - 21:48:38 EST


On Mon, Nov 02, 2026 at 01:13:xx +0100, Andrew Lunn wrote:
> Did you consider the other fix? Is there a use case for setting a TUN
> interface to ARPHRD_IEEE802154? If not, maybe return EOPNOTSUPP, or
> EINVAL?
>
> Andrew

Hi Andrew,

Thanks for reviewing and raising this point!

Regarding whether there is a use case for setting a TUN interface to
ARPHRD_IEEE802154:
In real hardware/subsystem usage, virtual 802.15.4 interfaces are typically
handled via mac802154_hwsim or fakelb (which properly allocate wpan_phy and
dev->ieee802154_ptr), rather than raw TUN. However, tun.c explicitly recognizes
ARPHRD_IEEE802154 and ARPHRD_IEEE802154_MONITOR in tun_get_addr_len():

case ARPHRD_IEEE802154:
case ARPHRD_IEEE802154_MONITOR:
return IEEE802154_EXTENDED_ADDR_LEN;

which sets the hardware address length to IEEE802154_EXTENDED_ADDR_LEN on
TUNSETLINK for userspace network stacks/simulators (such as IoT testbeds or
custom TAP-based emulators) that expect 802.15.4 addressing.

Regarding fixing this in drivers/net/tun.c vs net/ieee802154/nl-mac.c:
We considered returning -EOPNOTSUPP / -EINVAL in TUNSETLINK, but chose to
guard nl-mac.c for the following reasons:

1. Subsystem robustness / Defense-in-depth:
ieee802154_llsec_dump_table(), ieee802154_dump_iface(), and
ieee802154_nl_get_dev() assumed that any netdevice in the namespace
with dev->type == ARPHRD_IEEE802154 has valid ieee802154_ptr and
mlme_ops. When that assumption fails, it triggers a NULL dereference
while holding genl_mutex, leaving the mutex permanently locked and
deadlocking generic netlink system-wide for unprivileged users.

Other parts of the ieee802154 subsystem already make this defensive check:
- net/ieee802154/6lowpan/core.c (lowpan_newlink):
if (wdev->type != ARPHRD_IEEE802154 || !wdev->ieee802154_ptr)
- net/ieee802154/socket.c:
if (dev->type == ARPHRD_IEEE802154 && dev->ieee802154_ptr && ...)

Guarding nl-mac.c ensures the IEEE 802.15.4 netlink handlers are safe
regardless of how an ARPHRD_IEEE802154 device was created or modified.

2. Userspace ABI compatibility:
TUNSETLINK has historically permitted arbitrary link types on down
interfaces, and explicitly supports ARPHRD_IEEE802154 address lengths.
Disallowing it in TUNSETLINK might break existing user tools or test
frameworks that use TAP/TUN with this link type.

That said, if the consensus is that TUNSETLINK should reject
ARPHRD_IEEE802154 (or arbitrary link types that lack driver backend support),
I would be more than happy to submit a follow-up patch for tun.c as well.

Do you think we should reject it in tun.c in addition to guarding nl-mac.c,
or do you prefer restricting TUNSETLINK instead?

Thanks,
Kalpesh