TUNSETLINK allows a TUN device to change its link-layer type to
ARPHRD_IEEE802154 without initializing ieee802154_ptr. lowpan_newlink()
checks only the device type before dereferencing the pointer, so an
RTM_NEWLINK request can trigger a NULL pointer dereference.

Reject devices without ieee802154_ptr along with devices of the wrong type.

Fixes: 51e0e5d8124e ("ieee802154: 6lowpan: remove multiple lowpan per wpan 
support")
Cc: [email protected]
Reported-by: Vega <[email protected]>
Signed-off-by: Zhiling Zou <[email protected]>
---
 net/ieee802154/6lowpan/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
index 018929563c6bc..6a8d6852cb930 100644
--- a/net/ieee802154/6lowpan/core.c
+++ b/net/ieee802154/6lowpan/core.c
@@ -150,7 +150,7 @@ static int lowpan_newlink(struct net_device *ldev,
        wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
        if (!wdev)
                return -ENODEV;
-       if (wdev->type != ARPHRD_IEEE802154) {
+       if (wdev->type != ARPHRD_IEEE802154 || !wdev->ieee802154_ptr) {
                dev_put(wdev);
                return -EINVAL;
        }
-- 
2.43.0


Reply via email to