Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2585590rwo; Sun, 23 Jul 2023 19:41:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlEfjBEtc6p0XNXY/XPswWNCVT75IeVyPUhdlgHYv9JNoLIB9NDWqJNFvcWho65qYwNCV0gi X-Received: by 2002:a17:907:7f13:b0:98e:738c:6d39 with SMTP id qf19-20020a1709077f1300b0098e738c6d39mr14118927ejc.36.1690166508024; Sun, 23 Jul 2023 19:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690166508; cv=none; d=google.com; s=arc-20160816; b=d+z6Vrv1l6f9Jf+bOMPjnCW6qYNXDsk17Mj/ru3eF4NmrsHvqDp1Ba7+HmjWbxH6KW 0tifbtzixhYcyqxDlNZZYeYTDFeqNM0utbwHe1vziGP4Hh1m/E6wfL+P1/SvCMoZuXkA hhTX45Nc62dmzPlBUdweA7OvajyEYRVstm7Lr6O3fRaeII5+9jJl3MjlAdTXjacKltgm 89SVwA803RNkc4FXdOL2z5LC8flv1BeTGdbcfvkQdf7+qFeBwP3L9eoTM/U0vhmGxSHc E+VcrJCvbLVbz7HReoT+JwgWn3GJts0ePJuQth8y/wXycHZScgHHW3CMDTQ0rNMCcSM3 RAkA== 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=CGChArUp9e3YZjQA64tmB/R9YpQUS1LLCn29iKojH+Y=; fh=9fIMXUWIIPByQg1CyMsg3pjzz3KuHDuP0y2yn3Ep7h0=; b=vdHfT05OmNNsYcx3nuNJZhSDvCp0avW6KYsZvSs16/13UaX1aizffMGXBLDQ4oUdqV hCBibetBw9l79/1nrnrzHpwiGqAiShHCJ75f7DdslG4jodd9M1Jn4ITVx549jj5C658H 92Za2T9l4pgFVAUO9HEqDUjQP8ynPdAxRwCjYuC7VxserBtXvXJD0l2l0idGzwRtT3Rh 4xxUOkoRCry2bKzqSc980UX5ziL5+Tp1QxXY/RZiPBcHe5qU+LExcQzGkZ4DLzAxQZ82 HeAjpydVwAByygV6uOuEHLGMwuLrtgdZArqmpXQ5P8P66IbqfY3M1K7VREbAt9pY6zjR 42rA== 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 lz27-20020a170906fb1b00b0099364d9f0ebsi5951454ejb.559.2023.07.23.19.41.23; Sun, 23 Jul 2023 19:41:47 -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 S231801AbjGXCG0 (ORCPT + 99 others); Sun, 23 Jul 2023 22:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231742AbjGXCGN (ORCPT ); Sun, 23 Jul 2023 22:06:13 -0400 Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 129A97290; Sun, 23 Jul 2023 18:59:43 -0700 (PDT) Received: from localhost.localdomain (unknown [183.128.129.228]) by mail-app2 (Coremail) with SMTP id by_KCgBXPxrz171kq+dwCg--.54437S4; Mon, 24 Jul 2023 09:46:28 +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, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Lin Ma Subject: [PATCH v2] net/sched: mqprio: Add length check for TCA_MQPRIO_{MAX/MIN}_RATE64 Date: Mon, 24 Jul 2023 09:46:25 +0800 Message-Id: <20230724014625.4087030-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgBXPxrz171kq+dwCg--.54437S4 X-Coremail-Antispam: 1UD129KBjvJXoW7ZrWfXr1UKr4kWw4UCFWkXrb_yoW8Cr15pF ykJryxtFWDCFn7J393Cws7ZFZY9wsrCF42gFy5Zw4rArn8Wa4aga48WFW29r13Jr4rGws3 Jr1qya47urn0vFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26rxl 6s0DM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxa n2IY04v7MxkIecxEwVAFwVWkMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7VUbLiSPUUUUU== X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,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") Signed-off-by: Lin Ma --- V1 -> V2: do check with != rather than < as suggested seperate the check and give clearer error message 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