net: ieee802154: fix shift-out-of-bound in nl802154_new_interface
Subsystems (3)
PATCH v2 1/1 net: ieee802154: fix shift-out-of-bound in nl802154_new_interface
In nl802154_new_interface, if type retrieved from info->attr is NL802154_IFTYPE_UNSPEC(-1), i.e., less than NL802154_IFTYPE_MAX, it will trigger a shift-out-of-bound bug in BIT(type) [1].
Fix this by adding a condition to check if the variable type is larger than NL802154_IFTYPE_UNSPEC(-1).
--- net/ieee802154/nl802154.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ieee802154/nl802154.c +1 -1
@@ -915,7 +915,7 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)if (info->attrs[NL802154_ATTR_IFTYPE ]) { type =nla_get_u32 (info->attrs[NL802154_ATTR_IFTYPE ]); -if (type >NL802154_IFTYPE_MAX || +if (type <=NL802154_IFTYPE_UNSPEC || type >NL802154_IFTYPE_MAX || !(rdev->wpan_phy.supported.iftypes &BIT (type)))return -EINVAL ; }
Signature · 1 line
2.25.1
Alexander Aring
maintainerHi,
Quoted 8 lines · Dongliang Mu
In
nl802154_new_interface, if type retrieved frominfo->attrisNL802154_IFTYPE_UNSPEC(-1), i.e., less thanNL802154_IFTYPE_MAX, it will trigger a shift-out-of-bound bug in BIT(type) [1].Fix this by adding a condition to check if the variable type is larger than
NL802154_IFTYPE_UNSPEC(-1).
Thanks.
I just sent another patch to fix this issue. The real problem here is that the enum type doesn't fit into the u32 netlink range as I mentioned some months ago. [0] Sorry for the delayed fix.
- Alex
Quoted 13 lines · Alexander Aring
Hi,
Quoted 8 lines · Dongliang Mu
In
nl802154_new_interface, if type retrieved frominfo->attrisNL802154_IFTYPE_UNSPEC(-1), i.e., less thanNL802154_IFTYPE_MAX, it will trigger a shift-out-of-bound bug in BIT(type) [1].Fix this by adding a condition to check if the variable type is larger than
NL802154_IFTYPE_UNSPEC(-1).
Quoted 5 lines
Thanks.
I just sent another patch to fix this issue. The real problem here is that the enum type doesn't fit into the u32 netlink range as I mentioned some months ago. [0] Sorry for the delayed fix.
It's fine. This fix hits the core of the underlying bug.