Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5120662rwb; Mon, 31 Jul 2023 19:03:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlEXy7mFO0YGoXsszdWGskvdmhGuUrSF2KPQcbvtLFDuWE6zz/OXtvWwP6afyH5wDm2UwXGi X-Received: by 2002:a17:903:1cb:b0:1b8:9044:9ede with SMTP id e11-20020a17090301cb00b001b890449edemr12405794plh.62.1690855403384; Mon, 31 Jul 2023 19:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690855403; cv=none; d=google.com; s=arc-20160816; b=mVHTWyp/iyjhEoG9CWijs1gg4FSTZlKVCRQ+Cmh+x9V9aojtzfGESt6ckxxMUui+p9 4sUgKFMPah5rzmNGyrYKTmPH+Bn/wWQq88CRWuU5PrNdvNyt7OVqUQ8cop7fnWpju/qA 3ntNaW5+VJFxQAluUhrGYm6Nak2fWG31MTawdua2/TXrYDwsfFeuuDr3Jdy2hZxkQzeW PQ3GS0PAFYThFP2EwJZafDfjk6H++0Djo8yf/nJqgVZ/0T4uefMwIh6SrMo39QwOajUn 3CQUPL36XjPViSg/uolSVqhbpy43y4FSvDjcpeRQ71gn2RXfph1hBckpf8JXitn/wJYa ApcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=Dzwuw30SQ0rWTN9XhrQmHgMtTWFHv0YRETK+fukat0g=; fh=UixJP2upftG+MtyxBAx5Qlqv/BfNGgM+oQBGWCWrTuM=; b=FKZ1cYu/JHR06fRD82Yc8Ia6qkPnJe3+S9OvnAdGgLyWVG51MRdKMmknApgOubCYSS KS98RobMfLcqOiUbzpolAsjgmcR6GV7lxyhLJQ61fEJFrwTvWK1JrsEInx3yRn3m4rq+ rr0WIk2pel++L3c6vueYQmkCDyGfCZLRzjYsrrFMJ7qXDCJn5LbyoQaABVoC58wBGwci tb7HOjSis7D32p3pe5pJHqcjrop+0RsDcWucKK0hUZ1eWY05FJgEdRVyA9suemPuO3Ek B/C6etB97hQ0mWPZTRlhwjsq5cnxrEfiFy/htQHFvmr+qK60kMI+OMLrFd3VLwxBaCoC we8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a170902d4c500b001b9e1d5f8e6si8492850plg.447.2023.07.31.19.03.11; Mon, 31 Jul 2023 19:03:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231805AbjHABdc (ORCPT + 99 others); Mon, 31 Jul 2023 21:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbjHABd3 (ORCPT ); Mon, 31 Jul 2023 21:33:29 -0400 Received: from zg8tmja2lje4os4yms4ymjma.icoremail.net (zg8tmja2lje4os4yms4ymjma.icoremail.net [206.189.21.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 531FA114; Mon, 31 Jul 2023 18:33:25 -0700 (PDT) Received: from localhost.localdomain (unknown [115.200.228.232]) by mail-app2 (Coremail) with SMTP id by_KCgC3vorBYMhkoIHfCg--.63792S4; Tue, 01 Aug 2023 09:32:50 +0800 (CST) From: Lin Ma To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, daniel.machon@microchip.com, petrm@nvidia.com, linma@zju.edu.cn, peter.p.waskiewicz.jr@intel.com, jeffrey.t.kirsher@intel.com, alexander.h.duyck@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Markus.Elfring@web.de, horms@kernel.org Subject: [PATCH net v2] net: dcb: choose correct policy to parse DCB_ATTR_BCN Date: Tue, 1 Aug 2023 09:32:48 +0800 Message-Id: <20230801013248.87240-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgC3vorBYMhkoIHfCg--.63792S4 X-Coremail-Antispam: 1UD129KBjvJXoWxWw1xKw1DWFW5XF43Ar17Awb_yoW5Zw18pa 4vgrykCayUJry3GrWDuFZY9a97Ww1UCr4UJr17WFyIyFW7tFn3K347GFyFgw18tF42vrZ7 ur1Y9343ta1Yq3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvj14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoO J5UUUUU X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The dcbnl_bcn_setcfg uses erroneous policy to parse tb[DCB_ATTR_BCN], which is introduced in commit 859ee3c43812 ("DCB: Add support for DCB BCN"). Please see the comment in below code static int dcbnl_bcn_setcfg(...) { ... ret = nla_parse_nested_deprecated(..., dcbnl_pfc_up_nest, .. ) // !!! dcbnl_pfc_up_nest for attributes // DCB_PFC_UP_ATTR_0 to DCB_PFC_UP_ATTR_ALL in enum dcbnl_pfc_up_attrs ... for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { // !!! DCB_BCN_ATTR_RP_0 to DCB_BCN_ATTR_RP_7 in enum dcbnl_bcn_attrs ... value_byte = nla_get_u8(data[i]); ... } ... for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { // !!! DCB_BCN_ATTR_BCNA_0 to DCB_BCN_ATTR_RI in enum dcbnl_bcn_attrs ... value_int = nla_get_u32(data[i]); ... } ... } That is, the nla_parse_nested_deprecated uses dcbnl_pfc_up_nest attributes to parse nlattr defined in dcbnl_pfc_up_attrs. But the following access code fetch each nlattr as dcbnl_bcn_attrs attributes. By looking up the associated nla_policy for dcbnl_bcn_attrs. We can find the beginning part of these two policies are "same". static const struct nla_policy dcbnl_pfc_up_nest[...] = { [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8}, [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG}, }; static const struct nla_policy dcbnl_bcn_nest[...] = { [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8}, [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG}, // from here is somewhat different [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32}, ... [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG}, }; Therefore, the current code is buggy and this nla_parse_nested_deprecated could overflow the dcbnl_pfc_up_nest and use the adjacent nla_policy to parse attributes from DCB_BCN_ATTR_BCNA_0. Hence use the correct policy dcbnl_bcn_nest to parse the nested tb[DCB_ATTR_BCN] TLV. Fixes: 859ee3c43812 ("DCB: Add support for DCB BCN") Signed-off-by: Lin Ma Reviewed-by: Simon Horman --- V1 -> V2: 1. Change the commit message to imperative mood suggested by Markus. 2. Add Reviewed-by tag from Simon net/dcb/dcbnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c index c0c438128575..2e6b8c8fd2de 100644 --- a/net/dcb/dcbnl.c +++ b/net/dcb/dcbnl.c @@ -980,7 +980,7 @@ static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, return -EOPNOTSUPP; ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX, - tb[DCB_ATTR_BCN], dcbnl_pfc_up_nest, + tb[DCB_ATTR_BCN], dcbnl_bcn_nest, NULL); if (ret) return ret; -- 2.17.1