Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3913401rwo; Mon, 24 Jul 2023 20:00:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlFlOQkeyLTZx5dZUoHBIP/TZfekPL1OPUpZGTqWBP75AkfZUIoeIO+spxks/OJFwbssI/1X X-Received: by 2002:a17:906:15d:b0:991:b834:af83 with SMTP id 29-20020a170906015d00b00991b834af83mr9170611ejh.59.1690254012304; Mon, 24 Jul 2023 20:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690254012; cv=none; d=google.com; s=arc-20160816; b=csvvHjBLsM27hq66xhG+AViKcrBJSTAzTriA7M3uhNnnzvrOX5pqUx1Ygl6OgmanLh LGK1jNhDmFJBEPIl9F6+qCRDYl5qryEHZYmR442vwl9mA+JEfybuxT71KH4aXxYUSc+y R6KNoPyU5tOspdtypkti+yH0bzewJdeJp0nUPr+676uUGl14jbLduFFoUz7gXHOq8MpN be4LBmTzbzcc9KmK2CnQhFf7hKdjsHTu90iFw0oWgnFso5wKJij4NKHKoEeDYassfTAd k+OvT2p2OduU6q4nmpiDkeJDs5GlSZ9xRQyrEZvwmMy4fvBh+sCO2ygRxtmHHZyB6MUZ Q75Q== 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:cc:to:from; bh=h2JqW8gaMgoDk6pLzvj1/76yjGJkS5GBac86RP129iM=; fh=XQXdSh59u5ScYgrU5KnHUq3gxLTn/NwWPN8Ii/6Gl6A=; b=zoRn8yo9mIsAdncwz2TLfQIqxrPuCsBuq0Cjwuv4ima48xuoiuetad1pOC0J1sxEqT gOXzYFR9uyq9NnNlBw2z4BPeCKkZ/CmGdExJU6azg2PHWDpwaUEjdAVeXH0kbI+YKAL7 1nFb+YRlMy381D7uMki4JoxvZEh3BERtflF4DfS9EHKh8VqfVHBM7CfgVaPQ9mb00OXH L4+2M3ivCDx7KlMVxG7jgqjNrMCm32Z4G5xJ02XXS2XLayUZ5nUP0kBWAA5UhiRsbo5N ald048FVPvBM27AkBgMa22GJwkS53KhO3DIII2eizIFRYqP9jPA3Y/w5i6OVCMaX5CZq rWfg== 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 v21-20020a170906565500b00997d315d050si7353361ejr.84.2023.07.24.19.59.46; Mon, 24 Jul 2023 20:00:12 -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 S230190AbjGYCpC (ORCPT + 99 others); Mon, 24 Jul 2023 22:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230459AbjGYCo6 (ORCPT ); Mon, 24 Jul 2023 22:44:58 -0400 Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.237.72.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6254019AF; Mon, 24 Jul 2023 19:44:30 -0700 (PDT) Received: from localhost.localdomain (unknown [125.119.240.231]) by mail-app2 (Coremail) with SMTP id by_KCgDHuMCaNr9k_HqCCg--.1652S4; Tue, 25 Jul 2023 10:42:35 +0800 (CST) From: Lin Ma To: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, amritha.nambiar@intel.com, jeffrey.t.kirsher@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Lin Ma Subject: [PATCH v3] net/sched: mqprio: Add length check for TCA_MQPRIO_{MAX/MIN}_RATE64 Date: Tue, 25 Jul 2023 10:42:27 +0800 Message-Id: <20230725024227.426561-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgDHuMCaNr9k_HqCCg--.1652S4 X-Coremail-Antispam: 1UD129KBjvJXoW7ZrWfXr1UKr4kAw1xKr1rWFg_yoW8Zr1fpF ykXryxtFWDGrn7J393Cws7ZFZY9wsrAF42gFy5Zw18Arn8W34ag348Wry29r17Ar4rGws3 Jr1qya47urn0vFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUb XdbUUUUUU== X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,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 nla_for_each_nested parsing in function mqprio_parse_nlattr() does not check the length of the nested attribute. This can lead to an out-of-attribute read and allow a malformed nlattr (e.g., length 0) to be viewed as 8 byte integer and passed to priv->max_rate/min_rate. This patch adds the check based on nla_len() when check the nla_type(), which ensures that the length of these two attribute must equals sizeof(u64). Fixes: 4e8b86c06269 ("mqprio: Introduce new hardware offload mode and shaper in mqprio") Reviewed-by: Victor Nogueira Signed-off-by: Lin Ma --- V1 -> V2: do check with != rather than < as suggested seperate the check and give clearer error message V2 -> V3: add Reviewed-by tag from Victor, resend with correct CC list net/sched/sch_mqprio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c index ab69ff7577fc..f1d141a6d0aa 100644 --- a/net/sched/sch_mqprio.c +++ b/net/sched/sch_mqprio.c @@ -290,6 +290,13 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, "Attribute type expected to be TCA_MQPRIO_MIN_RATE64"); return -EINVAL; } + + if (nla_len(attr) != sizeof(u64)) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "Attribute TCA_MQPRIO_MIN_RATE64 expected to have 8 bytes length"); + return -EINVAL; + } + if (i >= qopt->num_tc) break; priv->min_rate[i] = nla_get_u64(attr); @@ -312,6 +319,13 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, "Attribute type expected to be TCA_MQPRIO_MAX_RATE64"); return -EINVAL; } + + if (nla_len(attr) != sizeof(u64)) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "Attribute TCA_MQPRIO_MAX_RATE64 expected to have 8 bytes length"); + return -EINVAL; + } + if (i >= qopt->num_tc) break; priv->max_rate[i] = nla_get_u64(attr); -- 2.17.1