Linux-WPAN Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] nl802154: Fix type check in nl802154_new_interface()
@ 2021-07-12 13:44 YueHaibing
  2021-07-13 13:32 ` Alexander Aring
  0 siblings, 1 reply; 2+ messages in thread
From: YueHaibing @ 2021-07-12 13:44 UTC (permalink / raw)
  To: alex.aring, stefan, davem, kuba, marcel
  Cc: linux-wpan, netdev, linux-kernel, YueHaibing

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+ #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: 65318680c97c ("ieee802154: add iftypes capability")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 net/ieee802154/nl802154.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 0cf2374..aab7ed4 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -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;
 	}
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nl802154: Fix type check in nl802154_new_interface()
  2021-07-12 13:44 [PATCH] nl802154: Fix type check in nl802154_new_interface() YueHaibing
@ 2021-07-13 13:32 ` Alexander Aring
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Aring @ 2021-07-13 13:32 UTC (permalink / raw)
  To: YueHaibing
  Cc: Stefan Schmidt, David S. Miller, Jakub Kicinski, Marcel Holtmann,
	linux-wpan - ML, open list:NETWORKING [GENERAL],
	kernel list

Hi,

On Mon, 12 Jul 2021 at 09:49, YueHaibing <yuehaibing@huawei.com> wrote:
>
> 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+ #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.

I think this is not the right fix, the fix is to change the UAPI that
NL802154_IFTYPE_UNSPEC fits into the netlink range of U32. I will
prepare a fix for that, it should still be backwards compatible.

- Alex

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 13:44 [PATCH] nl802154: Fix type check in nl802154_new_interface() YueHaibing
2021-07-13 13:32 ` Alexander Aring

Linux-WPAN Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-wpan/0 linux-wpan/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-wpan linux-wpan/ https://lore.kernel.org/linux-wpan \
		linux-wpan@vger.kernel.org
	public-inbox-index linux-wpan

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-wpan


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git