Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2235190iof; Wed, 8 Jun 2022 00:02:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnRUIcuFH92XyYOwOPsN+x5khGwNW0+PL4x0zoj1RVqmFfk0s9hE1mjsWZIxFzZfc/1p2Z X-Received: by 2002:a17:902:b692:b0:14c:935b:2b03 with SMTP id c18-20020a170902b69200b0014c935b2b03mr32664261pls.81.1654671777750; Wed, 08 Jun 2022 00:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654671777; cv=none; d=google.com; s=arc-20160816; b=FLPEGRNNE3DxMQJA6UziCNeNUokO6BUiU9wsqHJErf1/g/qw0dIZiiR+dzqkKOVH50 gX0zgEl2Eikz/KrhTZgixVvDeIgPjoHxYC+YEggjFEv4AeNHWiBd1rPbMZ3umYnO/xlO aZktg12F3jPGvJ9aLzWnlsJ/C4qa+3xFG8cPxawvxwmXk1m1tcPdlJpzhYNVvSI5HddS Wf7bWJZdlhqhunc6SXtzJFuWnDB0bho7nYtNdswIVu8GC1WhY9uWu5m+U0xq/BIdMNJZ +eHNi3h24fnS7DHCTw3Iho0WTKA5IGptSOTB6IuOGlWqWltR0C4QB0MBJfSNVhI1HUJ+ Rq5A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=v/w/sJcW3An5/+QDEErYvkawE+1soYfQ+lDGqh3NyJ0=; b=l18PJsFQ5bYSGtGyzF4kN9WbXtXFWK/a4FGJWq5TNWZVcB2gIyqr8276/0JLFLKeVV jRfPPKuqmKumuhGnC+udHHXl5/7GdabFLYmC5wbH0r8Tbf4d2rv1zhabv++QRShQ4BuW QdFUxHY012NpqcW4yzpnEChJyAg7KJRD9CfZq3UvITfkumeh9fR1bmM/X+RWKbUxaBJe 6M/SyrNzqs9BbsARfHIlkhvnn+taP+KquZfrlenLvQTtuBmC0s7eZYf1alzTQx820JMn LWPlxIFLjbp7MtaRLy/oBvgG70iGwpKhPiTNaWfWA7yZ6uM1g5wLHBfll2BVduJ1BK8T ltEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="I/4IzPnM"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w69-20020a638248000000b003fe34775ab6si1473624pgd.286.2022.06.08.00.02.43; Wed, 08 Jun 2022 00:02:57 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="I/4IzPnM"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381326AbiFGVnJ (ORCPT + 99 others); Tue, 7 Jun 2022 17:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378817AbiFGUwe (ORCPT ); Tue, 7 Jun 2022 16:52:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EDBD1057B; Tue, 7 Jun 2022 11:43:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EDCDD6169F; Tue, 7 Jun 2022 18:43:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DF70C385A2; Tue, 7 Jun 2022 18:43:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627389; bh=p6AyCMNuodEwCOkW6r5sEFSQXrSzPjcthGFZPDEb/Xg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I/4IzPnM6QEd5U6THkPyc7/RE/G9iXLH1rbx/pmOunImiLe2aD5yQOoJtAIdqDe5L lpEYh7/CedW5NUIG+pehfXqQDjRZypIO42lIUaqG5MXFJMiMMPHdmrNR0Z/fAirkPL U5frNQ1mRnXcBwi56x+hr4k3h1y5DCHIpWQejeho= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaomeng Tong , Joerg Roedel Subject: [PATCH 5.17 721/772] iommu/msm: Fix an incorrect NULL check on list iterator Date: Tue, 7 Jun 2022 19:05:13 +0200 Message-Id: <20220607165010.287116485@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Xiaomeng Tong commit 8b9ad480bd1dd25f4ff4854af5685fa334a2f57a upstream. The bug is here: if (!iommu || iommu->dev->of_node != spec->np) { The list iterator value 'iommu' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found (in fact, it will point to a invalid structure object containing HEAD). To fix the bug, use a new value 'iter' as the list iterator, while use the old value 'iommu' as a dedicated variable to point to the found one, and remove the unneeded check for 'iommu->dev->of_node != spec->np' outside the loop. Cc: stable@vger.kernel.org Fixes: f78ebca8ff3d6 ("iommu/msm: Add support for generic master bindings") Signed-off-by: Xiaomeng Tong Link: https://lore.kernel.org/r/20220501132823.12714-1-xiam0nd.tong@gmail.com Signed-off-by: Joerg Roedel Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/msm_iommu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -615,16 +615,19 @@ static void insert_iommu_master(struct d static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *spec) { - struct msm_iommu_dev *iommu; + struct msm_iommu_dev *iommu = NULL, *iter; unsigned long flags; int ret = 0; spin_lock_irqsave(&msm_iommu_lock, flags); - list_for_each_entry(iommu, &qcom_iommu_devices, dev_node) - if (iommu->dev->of_node == spec->np) + list_for_each_entry(iter, &qcom_iommu_devices, dev_node) { + if (iter->dev->of_node == spec->np) { + iommu = iter; break; + } + } - if (!iommu || iommu->dev->of_node != spec->np) { + if (!iommu) { ret = -ENODEV; goto fail; }