Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp1821588rwo; Sun, 23 Jul 2023 01:02:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlFIyIMDwUNWI6xMAB8CVpbZke5IiL6OJcotQhnpzX4YLPH8rWnUBhMC0awAFKfuxVnfa05Z X-Received: by 2002:a92:cb11:0:b0:348:8b32:976e with SMTP id s17-20020a92cb11000000b003488b32976emr4299233ilo.2.1690099371776; Sun, 23 Jul 2023 01:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690099371; cv=none; d=google.com; s=arc-20160816; b=XiHZEtP1IrLZs42xntEfy0LoXDYkP2HxgVB2uTP9qILjOXpg9VjxE5pY320q6Gs41k 92xIzs+7JmOfey4nxtANOaIlGB8AtIBFucZelYAkeG2G8+xKB7S6aC2ibYUOfE0AxH4m HRKIwzx6IBrjSVmLqr2rqBLtiQuaFKPIaT0dKFNWnjEazPgf7EqHbQ2+vYrA6XeVaGzL a00vTBjDSiVirHSnhCiQxfzTw+6g0UJtLlTveM+GefLvlTXViViA3b7ftnkNTB8gw8Ev 8b/sPZQJsKjBCW5gVfitv+jtV81UTIYu7onp55U27AkUJS5q+KM6iYlRRGaQULCDfZAV gBjw== 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=ArhAwS5Pftpcoe8vLiTn7LqKhODX4RM0E8qHGNJZ4Hs=; fh=NJzMN4GVIfLdYHzurVEQeo1huJPBRJb0+2OqHXkr4V4=; b=odCs9Sa7hBMKmgAviJgHf4l6ro5ZDUFYccDoOZnrGpZJHTQ8bcDr2xPdt87NXfeSQy YyVgn9tmXoVaOJb2Pgls+0T4kmtyMeyRmdY89VTWz3V6hvjY+B/q6lRnH1rWN79qUODs YPVi4qdG7wLHrd5xPTaMdYK2DdsF/fVvAnideDj5btI9xDCsQKh/b6Va8qnaVoFvBRkX JRfytwPkAmkfEw6JxkECMF0P6/Ozqzy4g/3aZGArrT4RQW518YQ9SNR5KbrZZm+DpHjU enQFRIb1+OUzFzJ4Sa2M1eXcsQfeFMaV5zU5jNBJWHt0HNb/wAKWVjryQs4E59X61GNV sP2Q== 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 s5-20020a170902ea0500b001b8ae34f1b7si7059253plg.631.2023.07.23.01.02.39; Sun, 23 Jul 2023 01:02:51 -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 S229595AbjGWHpV (ORCPT + 99 others); Sun, 23 Jul 2023 03:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjGWHpU (ORCPT ); Sun, 23 Jul 2023 03:45:20 -0400 X-Greylist: delayed 230 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 23 Jul 2023 00:45:17 PDT Received: from zg8tmtu5ljg5lje1ms4xmtka.icoremail.net (zg8tmtu5ljg5lje1ms4xmtka.icoremail.net [159.89.151.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE4DD19B3 for ; Sun, 23 Jul 2023 00:45:17 -0700 (PDT) Received: from localhost.localdomain (unknown [36.24.99.225]) by mail-app3 (Coremail) with SMTP id cC_KCgD3_g6B2rxkkDN_Cw--.46290S4; Sun, 23 Jul 2023 15:45:05 +0800 (CST) From: Lin Ma To: jgg@ziepe.ca, leon@kernel.org, markzhang@nvidia.com, michaelgur@nvidia.com, ohartoov@nvidia.com, chenzhongjin@huawei.com, yuancan@huawei.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Lin Ma Subject: [PATCH v1] RDMA/nldev: Add length check for IFLA_BOND_ARP_IP_TARGET parsing Date: Sun, 23 Jul 2023 15:45:04 +0800 Message-Id: <20230723074504.3706691-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cC_KCgD3_g6B2rxkkDN_Cw--.46290S4 X-Coremail-Antispam: 1UD129KBjvJXoWxJr1Dtr45WrW8WF48ur1UAwb_yoW8JFW3pF W0qFy7KF47JF13Ga1Dta1kWFWa93W7ZFyagFWDt343urn8Xw1S9345CFyYvFWDArWkA3W2 vF15Z34j9FZ2qr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvC14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc2xSY4AK67AK6r4xMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r 1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CE b7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0x vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAI cVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kf nxnUUI43ZEXa7VU10tC7UUUUU== X-CM-SenderInfo: qtrwiiyqvtljo62m3hxhgxhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 nldev_stat_set_counter_dynamic_doit() does not check the length of the attribute. This can lead to an out-of-attribute read and allow a malformed nlattr (e.g., length 0) to be viewed as a 4 byte integer. This patch adds the check based on nla_len() just as other code does, see how bond_changelink (drivers/net/bonding/bond_netlink.c) parses IFLA_BOND_NS_IP6_TARGET. Fixes: 3c3c1f141639 ("RDMA/nldev: Allow optional-counter status configuration through RDMA netlink") Signed-off-by: Lin Ma --- drivers/infiniband/core/nldev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c index d5d3e4f0de77..74635c23b371 100644 --- a/drivers/infiniband/core/nldev.c +++ b/drivers/infiniband/core/nldev.c @@ -1989,6 +1989,11 @@ static int nldev_stat_set_counter_dynamic_doit(struct nlattr *tb[], nla_for_each_nested(entry_attr, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS], rem) { + if (nla_len(entry_attr) < sizeof(index)) { + ret = -EINVAL; + goto out; + } + index = nla_get_u32(entry_attr); if ((index >= stats->num_counters) || !(stats->descs[index].flags & IB_STAT_FLAG_OPTIONAL)) { -- 2.17.1