linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: YueHaibing <yuehaibing@huawei.com>
To: <alex.aring@gmail.com>, <stefan@datenfreihafen.org>,
	<davem@davemloft.net>, <kuba@kernel.org>, <marcel@holtmann.org>
Cc: <linux-wpan@vger.kernel.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	YueHaibing <yuehaibing@huawei.com>
Subject: [PATCH] nl802154: Fix type check in nl802154_new_interface()
Date: Mon, 12 Jul 2021 21:44:30 +0800	[thread overview]
Message-ID: <20210712134430.19372-1-yuehaibing@huawei.com> (raw)

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


             reply	other threads:[~2021-07-12 13:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 13:44 YueHaibing [this message]
2021-07-13 13:32 ` [PATCH] nl802154: Fix type check in nl802154_new_interface() Alexander Aring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210712134430.19372-1-yuehaibing@huawei.com \
    --to=yuehaibing@huawei.com \
    --cc=alex.aring@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=stefan@datenfreihafen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).