tun: disallow setting IEEE 802.15.4 and 6LoWPAN link types via TUNSETLINK
Subsystems (4)
PATCH v4 1/1 tun: disallow setting IEEE 802.15.4 and 6LoWPAN link types via TUNSETLINK
A userspace application can set the link type of a TUN/TAP interface to ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR, or ARPHRD_6LOWPAN via ioctl(fd, TUNSETLINK, arg) because tun_get_addr_len() explicitly recognized these types.
However, TUN devices cannot function as genuine IEEE 802.15.4 or 6LoWPAN interfaces:
1. They lack wpan_phy, channels, PAN IDs, and MLME operations, and tun never initializes dev->ieee802154_ptr or dev->ml_priv. When an unprivileged user creates a TUN interface in a user+net namespace, changes its link type to ARPHRD_IEEE802154, and issues a netlink dump request (such as IEEE802154_LLSEC_LIST_KEY), ieee802154_llsec_dump_table() unconditionally dereferences dev->ieee802154_ptr / ieee802154_mlme_ops(dev), triggering a supervisor null-pointer dereference / general protection fault. Similar dereferences occur across net/ieee802154/nl-phy.c (ieee802154_del_iface) and net/ieee802154/socket.c.
2. Similarly, the 6LoWPAN subsystem assumes via lowpan_dev(dev) that netdev_priv(dev) is struct lowpan_dev. On a TUN device, netdev_priv(dev) is struct tun_struct. On netdev events (such as NETDEV_DOWN in net/6lowpan/core.c:lowpan_device_event), it clears bits in lowpan_dev(dev)->ctx.table flags, which corrupts private memory inside tun_struct.
Rather than scattering checks across subsystems, fix the issue at the
source: disallow setting ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR, and ARPHRD_6LOWPAN via TUNSETLINK by returning -EINVAL. Cast arg to unsigned short in the comparison to prevent upper-bit truncation bypasses (e.g. arg = ARPHRD_IEEE802154 | 0x10000).
--- drivers/net/tun.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/tun.c +4 -0
@@ -3362,6 +3362,10 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,netif_info (tun, drv, tun->dev,"Linktype set failed because interface is up\n" ); ret = -EBUSY ; + }else if ((unsigned short )arg ==ARPHRD_IEEE802154 || + (unsigned short )arg ==ARPHRD_IEEE802154_MONITOR || + (unsigned short )arg ==ARPHRD_6LOWPAN ) { + ret = -EINVAL ; }else { ret =call_netdevice_notifiers (NETDEV_PRE_TYPE_CHANGE , tun->dev);
Signature · 1 line
2.53.0
Quoted 32 lines · Kalpesh Solanki
A userspace application can set the link type of a TUN/TAP interface to
ARPHRD_IEEE802154,ARPHRD_IEEE802154_MONITOR, orARPHRD_6LOWPANviaioctl(fd, TUNSETLINK, arg)becausetun_get_addr_len()explicitly recognized these types.However, TUN devices cannot function as genuine IEEE 802.15.4 or 6LoWPAN interfaces:
1. They lack
wpan_phy, channels, PAN IDs, and MLME operations, and tun never initializesdev->ieee802154_ptrordev->ml_priv. When an unprivileged user creates a TUN interface in a user+net namespace, changes its link type toARPHRD_IEEE802154, and issues a netlink dump request (such asIEEE802154_LLSEC_LIST_KEY),ieee802154_llsec_dump_table()unconditionally dereferencesdev->ieee802154_ptr/ieee802154_mlme_ops(dev), triggering a supervisor null-pointer dereference / general protection fault. Similar dereferences occur acrossnet/ieee802154/nl-phy.c(ieee802154_del_iface) andnet/ieee802154/socket.c.2. Similarly, the 6LoWPAN subsystem assumes via
lowpan_dev(dev)thatnetdev_priv(dev)is structlowpan_dev. On a TUN device,netdev_priv(dev)is structtun_struct. On netdev events (such asNETDEV_DOWNin net/6lowpan/core.c:lowpan_device_event), it clears bits in lowpan_dev(dev)->ctx.table flags, which corrupts private memory insidetun_struct.Rather than scattering checks across subsystems, fix the issue at the
source: disallow settingARPHRD_IEEE802154,ARPHRD_IEEE802154_MONITOR, andARPHRD_6LOWPANvia TUNSETLINK by returning-EINVAL. Cast arg to unsigned short in the comparison to prevent upper-bit truncation bypasses (e.g. arg =ARPHRD_IEEE802154|0x10000).
Quoted 4 lines
Fixes ff4cc3ac93e1 ("[TUNTAP]: Allow setting the linktype of the tap device from userspace")Reported-by [email protected]Signed-off-by Kalpesh Solanki <[email protected]>
This may affect more protocols, and sashiko may surface that. That can always be a separate follow-up.
Quoted 22 lines
--- drivers/net/tun.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/tun.c +4
-0@@ -3362,6 +3362,10 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,netif_info (tun, drv, tun->dev,"Linktype set failed because interface is up\n" ); ret = -EBUSY ; + }else if ((unsigned short )arg ==ARPHRD_IEEE802154 || + (unsigned short )arg ==ARPHRD_IEEE802154_MONITOR || + (unsigned short )arg ==ARPHRD_6LOWPAN ) { + ret = -EINVAL ; }else { ret =call_netdevice_notifiers (NETDEV_PRE_TYPE_CHANGE , tun->dev);Signature · 1 line
2.53.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 9 Nov 2026 14:00:37 +0530 you wrote:
A userspace application can set the link type of a TUN/TAP interface to
ARPHRD_IEEE802154,ARPHRD_IEEE802154_MONITOR, orARPHRD_6LOWPANviaioctl(fd, TUNSETLINK, arg)becausetun_get_addr_len()explicitly recognized these types.However, TUN devices cannot function as genuine IEEE 802.15.4 or 6LoWPAN interfaces:
[...]
Here is the summary with links:
- [net,v4] tun: disallow setting IEEE 802.15.4 and 6LoWPAN link types via TUNSETLINK
https://git.kernel.org/netdev/net/c/968f2b94a596
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html