Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2302222iof; Wed, 8 Jun 2022 01:55:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYUc9hQGhuAhqcEoVPAW01oIbTGx+1RZ0R3KyNlZQzjGNK/DNfo+4DneBBhBCmKriZc6We X-Received: by 2002:a05:6a00:4211:b0:51c:45e:532b with SMTP id cd17-20020a056a00421100b0051c045e532bmr18317421pfb.10.1654678548118; Wed, 08 Jun 2022 01:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654678548; cv=none; d=google.com; s=arc-20160816; b=S7m/doxWZB/E3DAM7VeaiO4whcEPZAcID++bQk+ezImU/h5syfBLZCRPL+5tv+riE7 WE7krEGmNdSTjPvO0Qzazb3qI+CZiB84Gsa64EeAMGfCwBJ1tGbarkqKvdN142KKT4BF 25Fu/4URLG4kFi4tyZRTMaBsGLIbD55rRxaaLzExPEGSdg/WGs2wNkNyjVIp6HMpoSa4 fZiJFf3zWMDAHyGJQX34wDRh+oR3Qp3fn6OXY/PQFbxzrX3fUS7eYcH+vO8VbPhA23Xg Ux8WD2wjg2+nUhvVkwCr7J2ezDSz/UL0DN7FB8w9B3T6fiDTSDr6hLdsZ/G4kxCcLjGo 0hVg== 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=3EC7ZaHbTXh1i70ZVI7kbyfjGC7RxmvoLeLm0tNmICU=; b=zkzdv+I8L83cal/mhF0wZ78c4jjj11PcIorPhSTRsfdA582S+NuIdIO310no99ERFD f7bkEnbsrENIhmlEdZ627S837fe+2q43qXwastmUyIYOEZaaVy5tx6P/jlDJFafVpleK IbMXUVWw2toV2O+PZlBqiQoANAxy4zGLvVlonoRhuFI2QXv5HnwMweyI7VrdZZ18CeYG AbuhIYpjL+bmjs/wljnmA7E+6XfVNuZAmm9SLAtxdNQlEvjz/Tht6S7qRbYEX+VN9zg+ 9Fih+UgfwhWPBJo/LXnRFin/lcRIdASoICCH9swuIeL61EN42VRCiQqqk3T6rCCukj51 HZgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jWcwJSjk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p6-20020a17090a284600b001ea454282d8si1030643pjf.66.2022.06.08.01.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:55:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jWcwJSjk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C8203AC1CE; Wed, 8 Jun 2022 01:18:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiFHDST (ORCPT + 99 others); Tue, 7 Jun 2022 23:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345151AbiFHDOX (ORCPT ); Tue, 7 Jun 2022 23:14:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079FA272370; Tue, 7 Jun 2022 12:23:34 -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 ams.source.kernel.org (Postfix) with ESMTPS id 57069B823CA; Tue, 7 Jun 2022 19:23:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C59B8C36B00; Tue, 7 Jun 2022 19:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629811; bh=wICu+zwIpk9cOz0cgVef/aClc+PUiwlFhp12DqvOPWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWcwJSjkD/FwRDx6Ly8pB3O4hjwc8/dOQPzpg0Q6RipmiqDtj41RxB56iTMUtVIvo QX0Ti87+rEJa9Gu1v8+LGW0SpnPLpMVbyWALbyVUz9af3McyBqvaJOQ3EttfAsZ8RP Pqch06YCUB3jAwyvmExHE/dSbJWJmIPTfIaNc+ZY= 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.18 825/879] iommu/msm: Fix an incorrect NULL check on list iterator Date: Tue, 7 Jun 2022 19:05:43 +0200 Message-Id: <20220607165026.801495263@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 @@ -610,16 +610,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; }