Skip to content

Commit

Permalink
nl802154: Fix type check in nl802154_new_interface()
Browse files Browse the repository at this point in the history
We got this UBSAN warning:

UBSAN: shift-out-of-bounds in net/ieee802154/nl802154.c:920:44
shift exponent -1 is negative
CPU: 3 PID: 8258 Comm: repro Not tainted 5.13.0+ torvalds#222
Call Trace:
 dump_stack_lvl+0x8d/0xcf
 ubsan_epilogue+0xa/0x4e
 __ubsan_handle_shift_out_of_bounds+0x161/0x182
 nl802154_new_interface+0x3bf/0x3d0
 genl_family_rcv_msg_doit.isra.15+0x12d/0x170
 genl_rcv_msg+0x11a/0x240
 netlink_rcv_skb+0x69/0x160
 genl_rcv+0x24/0x40

NL802154_IFTYPE_UNSPEC is -1, so enum nl802154_iftype type now
is a signed integer, which is assigned by nla_get_u32 in
nl802154_new_interface(), this may cause type is negative and trigger
this warning.

Fixes: 6531868 ("ieee802154: add iftypes capability")
Signed-off-by: YueHaibing <[email protected]>
  • Loading branch information
YueHaibing authored and intel-lab-lkp committed Jul 12, 2021
1 parent e73f0f0 commit 9c12ebe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/ieee802154/nl802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ 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)
return -EINVAL;
if (type != NL802154_IFTYPE_UNSPEC &&
!(rdev->wpan_phy.supported.iftypes & BIT(type)))
return -EINVAL;
}
Expand Down

0 comments on commit 9c12ebe

Please sign in to comment.