Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3888619rwe; Mon, 17 Apr 2023 05:13:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZM017XsXgqj2NFYujmCKATACQNOUoYI58v/IpeI+nqfYiv/eVD8ODTSXdTToKKLl8BQOEx X-Received: by 2002:a05:6a20:4982:b0:e8:fe82:5843 with SMTP id fs2-20020a056a20498200b000e8fe825843mr13665261pzb.45.1681733589538; Mon, 17 Apr 2023 05:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681733589; cv=none; d=google.com; s=arc-20160816; b=X9gQHDuXfpawUf6ZY0GWRNjqiue0lsdUsSwb2JBwWRz4WgmunGR8dOq/gnYCpzolWx ktCLkQbTc6KzC1JelAHYvcx4GiZE58hqNypFlsFAeX8kDQIrrK7e0qJnQh81nh0n3zoI /mPqxd9GhWHKF1o/Q36WDauGGicBVGsmryw5mQ9yMBfzBNW5mXvzqI2lSFAu06ljB5EE 2PVo9GTMEgqEuz3+FzqBxzNiTGyCt/uLGzjO8A/wqF0itbvcmkKNYXDqLOsTOmtfm7gX fdI2vUPfRueTwT9D6m5F2V57p3cfwj+nLWXuHK+KckpY6L9H6srYHLvboxRCpDv3P6nU sPog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=XTcEPgk0fcbx2lPnCzGjBs+D6036/KLeg1o98Gtz+Hk=; b=0CP04c/+iURlNlSusT4hAw7dNWOYpHK4H/u6JpUvD/jfzeo2DGZQ6HCyTEHNyXlTGB JiFKIkteTW8sSIuHopJZiE2hXK8h5UwEjfnnLvya7/NBbKuTvJYq4XH62TVgAm5NpRQF aq3XGbJeHvPVAFkXEzK2BWXJVE4mxzbqfsWSitln82Cei4ENb+r7SuvMMzsK2xUVQsSS XtvF2Ze+V1By9NAhucbLWq1ufXNMMPbPta36qupoCVtlh0+lDf1aHhDLPnhC+Hu8fUt0 llFs/zqbk+HtEQ9YzZmyxyDvbxOz0ZW2duN5T94gW1CmB8TFHnUMA0O9K2VyL8bsExm8 5aMQ== 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 k5-20020a632405000000b005141567ee1bsi11898968pgk.195.2023.04.17.05.12.58; Mon, 17 Apr 2023 05:13:09 -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 S230382AbjDQMKB (ORCPT + 99 others); Mon, 17 Apr 2023 08:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbjDQMJw (ORCPT ); Mon, 17 Apr 2023 08:09:52 -0400 Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A84046B2; Mon, 17 Apr 2023 05:09:28 -0700 (PDT) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.169) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 17 Apr 2023 15:07:23 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 17 Apr 2023 15:07:22 +0300 From: Nikita Zhandarovich To: CC: Nikita Zhandarovich , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , , , , "Natalia Petrova" Subject: [PATCH net] mlxfw: fix null-ptr-deref in mlxfw_mfa2_tlv_next() Date: Mon, 17 Apr 2023 05:07:18 -0700 Message-ID: <20230417120718.52325-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) 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 Function mlxfw_mfa2_tlv_multi_get() returns NULL if 'tlv' in question does not pass checks in mlxfw_mfa2_tlv_payload_get(). This behaviour may lead to NULL pointer dereference in 'multi->total_len'. Fix this issue by testing mlxfw_mfa2_tlv_multi_get()'s return value against NULL. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Fixes: 410ed13cae39 ("Add the mlxfw module for Mellanox firmware flash process") Co-developed-by: Natalia Petrova Signed-off-by: Nikita Zhandarovich --- drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c index 017d68f1e123..972c571b4158 100644 --- a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c +++ b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c @@ -31,6 +31,8 @@ mlxfw_mfa2_tlv_next(const struct mlxfw_mfa2_file *mfa2_file, if (tlv->type == MLXFW_MFA2_TLV_MULTI_PART) { multi = mlxfw_mfa2_tlv_multi_get(mfa2_file, tlv); + if (!multi) + return NULL; tlv_len = NLA_ALIGN(tlv_len + be16_to_cpu(multi->total_len)); }