From patchwork Mon Apr 17 12:07:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 84198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2089882vqo; Mon, 17 Apr 2023 05:33:42 -0700 (PDT) X-Google-Smtp-Source: AKy350ZCJnqXChWLUc5Sxz8zspSWdlPtDDxvbsIugPSoGmoC6qCVzlbcDAmQqqNf5MrkweT2eVjs X-Received: by 2002:a05:6a20:a884:b0:cc:a5d4:c334 with SMTP id ca4-20020a056a20a88400b000cca5d4c334mr14328383pzb.10.1681734822552; Mon, 17 Apr 2023 05:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681734822; cv=none; d=google.com; s=arc-20160816; b=MutKWpYUyBLr2UEmJIiXbOROWZI0GFqFFY0JgcEHZa8YdmYzLS6v08c8AeXJwVG8v0 pRrnx8H10URvBBKFk8dZXh0kwYWyHpvvokWxab1nDU1Ay2Gj4GQW6zeHubEewIOcSqt6 py/V92QSvExnHCm1KIlTNfgHm/U3b+YZcLbY1wMlmDUcukOq47XunIkm3c1DuWXbVFxF 51TsRk0F4VWIX5XriVRxgfnnoNShxdpAORjadcZDTSZ66WQi1jmXa0gX2zHYd7L3eXWh fhCuvxxZNL6vH/pSQpB/q5wcg4qQxzjIE0CYhdN23qiQY2u+oeF2ZV6p9iCmk8Esda0F qzkQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a63ee46000000b0050f55427e3dsi11886685pgk.701.2023.04.17.05.33.28; Mon, 17 Apr 2023 05:33:42 -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 S229662AbjDQMKB (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763426773272659975?= X-GMAIL-MSGID: =?utf-8?q?1763426773272659975?= 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 Reviewed-by: Ido Schimmel --- 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)); }