From patchwork Mon Jul 12 13:44:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 12371241 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFFE1C07E9C for ; Mon, 12 Jul 2021 13:49:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B11E161003 for ; Mon, 12 Jul 2021 13:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234776AbhGLNw1 (ORCPT ); Mon, 12 Jul 2021 09:52:27 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:14070 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbhGLNw0 (ORCPT ); Mon, 12 Jul 2021 09:52:26 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GNlRH37M7zYrMm; Mon, 12 Jul 2021 21:46:19 +0800 (CST) Received: from dggema769-chm.china.huawei.com (10.1.198.211) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 12 Jul 2021 21:49:35 +0800 Received: from localhost (10.174.179.215) by dggema769-chm.china.huawei.com (10.1.198.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 12 Jul 2021 21:49:34 +0800 From: YueHaibing To: , , , , CC: , , , YueHaibing Subject: [PATCH] nl802154: Fix type check in nl802154_new_interface() Date: Mon, 12 Jul 2021 21:44:30 +0800 Message-ID: <20210712134430.19372-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.179.215] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggema769-chm.china.huawei.com (10.1.198.211) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- 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; }