* [PATCH] ieee802154: nl-mac: validate device pointers before dereference
@ 2026-11-01 9:22 Kalpesh Solanki
2026-11-01 19:43 ` Andrew Lunn
2026-11-02 2:47 ` Kalpesh Solanki
0 siblings, 2 replies; 3+ messages in thread
From: Kalpesh Solanki @ 2026-11-01 9:22 UTC (permalink / raw)
To: alex.aring, stefan, miquel.raynal, davem, edumazet, kuba, pabeni
Cc: horms, linux-wpan, netdev, linux-kernel,
syzbot+9ea34da5ca6100593c90, Kalpesh Solanki, stable
A virtual network device (such as a TUN interface) can have its link
type set to ARPHRD_IEEE802154 via ioctl(tun_fd, TUNSETLINK,
ARPHRD_IEEE802154). However, such devices do not have an IEEE 802.15.4
private context allocated (dev->ieee802154_ptr is NULL) and do not
register MAC operations (dev->ml_priv / ieee802154_mlme_ops(dev) is NULL).
When dumping security keys via IEEE802154_LLSEC_LIST_KEY,
ieee802154_llsec_dump_table() iterates through all net devices and
dereferences data.ops->llsec assuming that any ARPHRD_IEEE802154 device
has valid mlme ops. Because data.ops is NULL, this causes an immediate
null-pointer dereference / General Protection Fault:
Oops: general protection fault, probably for non-canonical address
KASAN: null-ptr-deref in range [0x0000000000000038-0x000000000000003f]
RIP: 0010:ieee802154_llsec_dump_table+0x204/0x5d0
Call Trace:
<TASK>
genl_dumpit+0x125/0x230 net/netlink/genetlink.c:1026
netlink_dump+0x53b/0xd00 net/netlink/af_netlink.c:2351
__netlink_dump_start+0x6d6/0x990 net/netlink/af_netlink.c:2466
Similarly, ieee802154_dump_iface() and ieee802154_nl_get_dev() assume
that ARPHRD_IEEE802154 devices have valid dev->ieee802154_ptr and
ieee802154_mlme_ops(dev) pointers.
Fix this by ensuring dev->ieee802154_ptr and ieee802154_mlme_ops(dev)
are non-NULL before proceeding in ieee802154_nl_get_dev(),
ieee802154_dump_iface(), and ieee802154_llsec_dump_table().
Fixes: 3e9c156e2c21 ("ieee802154: add netlink interfaces for llsec")
Cc: stable@vger.kernel.org
Reported-by: syzbot+9ea34da5ca6100593c90@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9ea34da5ca6100593c90
Tested-by: syzbot+9ea34da5ca6100593c90@syzkaller.appspotmail.com
Signed-off-by: Kalpesh Solanki <skalpesh942@gmail.com>
---
net/ieee802154/nl-mac.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c
index 74ef0a310af..1acde5af4b5 100644
--- a/net/ieee802154/nl-mac.c
+++ b/net/ieee802154/nl-mac.c
@@ -162,7 +162,8 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
if (!dev)
return NULL;
- if (dev->type != ARPHRD_IEEE802154) {
+ if (dev->type != ARPHRD_IEEE802154 || !dev->ieee802154_ptr ||
+ !ieee802154_mlme_ops(dev)) {
dev_put(dev);
return NULL;
}
@@ -437,7 +438,8 @@ int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
idx = 0;
for_each_netdev(net, dev) {
- if (idx < s_idx || dev->type != ARPHRD_IEEE802154)
+ if (idx < s_idx || dev->type != ARPHRD_IEEE802154 ||
+ !dev->ieee802154_ptr || !ieee802154_mlme_ops(dev))
goto cont;
if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
@@ -771,7 +773,8 @@ ieee802154_llsec_dump_table(struct sk_buff *skb, struct netlink_callback *cb,
int rc;
for_each_netdev(net, dev) {
- if (idx < first_dev || dev->type != ARPHRD_IEEE802154)
+ if (idx < first_dev || dev->type != ARPHRD_IEEE802154 ||
+ !dev->ieee802154_ptr || !ieee802154_mlme_ops(dev))
goto skip;
data.ops = ieee802154_mlme_ops(dev);
--
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ieee802154: nl-mac: validate device pointers before dereference
2026-11-01 9:22 [PATCH] ieee802154: nl-mac: validate device pointers before dereference Kalpesh Solanki
@ 2026-11-01 19:43 ` Andrew Lunn
2026-11-02 2:47 ` Kalpesh Solanki
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-11-01 19:43 UTC (permalink / raw)
To: Kalpesh Solanki
Cc: alex.aring, stefan, miquel.raynal, davem, edumazet, kuba, pabeni,
horms, linux-wpan, netdev, linux-kernel,
syzbot+9ea34da5ca6100593c90, stable
On Sun, Nov 01, 2026 at 02:52:19PM +0530, Kalpesh Solanki wrote:
> A virtual network device (such as a TUN interface) can have its link
> type set to ARPHRD_IEEE802154 via ioctl(tun_fd, TUNSETLINK,
> ARPHRD_IEEE802154). However, such devices do not have an IEEE 802.15.4
> private context allocated (dev->ieee802154_ptr is NULL) and do not
> register MAC operations (dev->ml_priv / ieee802154_mlme_ops(dev) is NULL).
> Fix this by ensuring dev->ieee802154_ptr and ieee802154_mlme_ops(dev)
> are non-NULL before proceeding in ieee802154_nl_get_dev(),
> ieee802154_dump_iface(), and ieee802154_llsec_dump_table().
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ieee802154: nl-mac: validate device pointers before dereference
2026-11-01 9:22 [PATCH] ieee802154: nl-mac: validate device pointers before dereference Kalpesh Solanki
2026-11-01 19:43 ` Andrew Lunn
@ 2026-11-02 2:47 ` Kalpesh Solanki
1 sibling, 0 replies; 3+ messages in thread
From: Kalpesh Solanki @ 2026-11-02 2:47 UTC (permalink / raw)
To: andrew
Cc: alex.aring, stefan, miquel.raynal, davem, edumazet, kuba, pabeni,
horms, linux-wpan, netdev, linux-kernel,
syzbot+9ea34da5ca6100593c90, stable, Kalpesh Solanki
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-02 2:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-01 9:22 [PATCH] ieee802154: nl-mac: validate device pointers before dereference Kalpesh Solanki
2026-11-01 19:43 ` Andrew Lunn
2026-11-02 2:47 ` Kalpesh Solanki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®