From patchwork Tue Mar 14 13:44:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 69640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1780573wrd; Tue, 14 Mar 2023 07:09:22 -0700 (PDT) X-Google-Smtp-Source: AK7set/qYY6FVTGJKlfM/rW/nfztGoBb8vPFVIhNxRSfcqWX73ZNQPBcy63zSO0ONRslzUqhVwhy X-Received: by 2002:a05:6e02:c66:b0:315:498b:4165 with SMTP id f6-20020a056e020c6600b00315498b4165mr2007420ilj.32.1678802962543; Tue, 14 Mar 2023 07:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678802962; cv=none; d=google.com; s=arc-20160816; b=tvhKqtffgUxHqah9V7jsbdVd/39W/rdMDDAagOFFo7iHE4dEETN9N8zKX93t/onope nAA9cRfKW12P8PHRh6lIDiV5MO2pngEIy989b7xQ5hiRJ548dBi7G5qqpstIOm7Zncna NijEu1jQJtDMJScq94i49YeSLsvtsoL8V+Pdtv621nNQPdFLdG4Gbkja1BUASmigytil LJ8bZ+7Dzz9n/tMZiwxDg5wFvrMfMfL23g46ER6xUYCsfke/uhqIRm/FyzlGUU1pREC9 2tjsN8yt5Dv19bpqjSQk2nxP3RJBYWGmMCvVawXasnu+FkUPuyHQkmEdXmZCE7YA7OaX mgbA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Hz4+k7h4zCOH1B7KIziNGf5Xkq5I6RBB6aGSTXkJzyU=; b=mKEFddT7AGQksuSLl1qyqfqRTWbqowNzkD2cCERdFThJnZzK4JW4iCnl27rVOdCzwt STLJE6AxO0l9Wgrrnh64U6r06JGw8Lrs86BmoU/ri7n2TqSGQtZ3TTdThFG0Nf+d3KP6 hVyHgxO4nxXeDxHiLtQMSiWOVsX6xZoiSEo8rQZZZfLIi0ANzHSEqGHPrppzoCHgHINC kkKViGYjd1wOO/7qrNNx2dcdaxGRWQeLZJYF9OTOeNa6nBtMW/4Dc7glep8LPSyoEmVk rJoKS83W+sCYq7Wb588QgXXYyVrytQVpFhWTBX2cMUJZNfjzdeN+Ff+01E+UlrOaP7zB GKRg== 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 t14-20020a922c0e000000b0031799f1b52bsi2330103ile.164.2023.03.14.07.09.05; Tue, 14 Mar 2023 07:09:22 -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 S231260AbjCNNtH (ORCPT + 99 others); Tue, 14 Mar 2023 09:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbjCNNsc (ORCPT ); Tue, 14 Mar 2023 09:48:32 -0400 Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FEFD9F061; Tue, 14 Mar 2023 06:45:31 -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; Tue, 14 Mar 2023 16:45:25 +0300 Received: from localhost (10.0.253.157) 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; Tue, 14 Mar 2023 16:45:25 +0300 From: Nikita Zhandarovich To: , Greg Kroah-Hartman CC: Nikita Zhandarovich , Mustafa Ismail , Shiraz Saleem , "Jason Gunthorpe" , Leon Romanovsky , , , Subject: [PATCH 5.4/5.10 1/1] RDMA/i40iw: Fix potential NULL-ptr-dereference Date: Tue, 14 Mar 2023 06:44:56 -0700 Message-ID: <20230314134456.3557-2-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314134456.3557-1-n.zhandarovich@fintech.ru> References: <20230314134456.3557-1-n.zhandarovich@fintech.ru> MIME-Version: 1.0 X-Originating-IP: [10.0.253.157] 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 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?1760352495331050482?= X-GMAIL-MSGID: =?utf-8?q?1760352495331050482?= From: Nikita Zhandarovich commit 5d9745cead1f121974322b94ceadfb4d1e67960e upstream. in_dev_get() can return NULL which will cause a failure once idev is dereferenced in in_dev_for_each_ifa_rtnl(). This patch adds a check for NULL value in idev beforehand. Found by Linux Verification Center (linuxtesting.org) with SVACE. Changes made to the original patch during backporting: Apply patch to drivers/infiniband/hw/i40iw/i40iw_cm.c instead of drivers/infiniband/hw/irdma/cm.c due to the fact that kernel versions 5.10 and below use i40iw driver, not irdma. Fixes: f27b4746f378 ("i40iw: add connection management code") Signed-off-by: Nikita Zhandarovich Link: https://lore.kernel.org/r/20230126185230.62464-1-n.zhandarovich@fintech.ru --- drivers/infiniband/hw/i40iw/i40iw_cm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c b/drivers/infiniband/hw/i40iw/i40iw_cm.c index 3053c345a5a3..e1236ac502f2 100644 --- a/drivers/infiniband/hw/i40iw/i40iw_cm.c +++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c @@ -1776,6 +1776,8 @@ static enum i40iw_status_code i40iw_add_mqh_4( const struct in_ifaddr *ifa; idev = in_dev_get(dev); + if (!idev) + continue; in_dev_for_each_ifa_rtnl(ifa, idev) { i40iw_debug(&iwdev->sc_dev,