Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp440088iog; Mon, 13 Jun 2022 06:03:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqCtN/8pZeS4ows6azkpPocdBoqmAnanKNYXJ0LlZ+KZ/Gm2l3CQGB5kSZ+CioKSICZBlp X-Received: by 2002:a17:906:f293:b0:718:82e3:226b with SMTP id gu19-20020a170906f29300b0071882e3226bmr5018582ejb.676.1655125435978; Mon, 13 Jun 2022 06:03:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125435; cv=none; d=google.com; s=arc-20160816; b=tQPGV4hzFSKrnwheWCEOZZ2dE/7Fsq0nhI5bvJticUNiz66ZjDyjLkGLo1cujpk8YB gEWRClNndeov4GzOWYvH4mZLeTyNOAc1nid6vzlbnsuHD4V1l7cIz+rnn0Hp0KiFokp6 K5dCyLaOz5pZvLbBTjeKcGnHbb3sGqNPW9DYOLvam0EVAwZdPgrhf0MbazHgi5uJAzg1 wvZeAg29c9kUKMaoIOZBo1yD+AT1YuFnYxAPXmVSKsobKnnIW97Fz1N84G10fJzgOG1M Yt6JbIGO2GT/qFAx5ZKZAakqFcIKVjTwTutKHueuHPk6q0zUu199mYqnEyYaDZvuel1L n5lw== 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=bKVlFoLWJVpWg0zcx6aMOp1tZbmS036LML7d29E76F8=; b=EN1u5uF/hlWilu1qC5fxbfkNtQQDuhMFdnCWjRoiTFI2ZKdAhfa8O7DElluHxRyHgX Qx1XtVJjnPXhH9JU5gU3tDQjn7RI2grxx0mVzVwX1Zj2odeu3no+ReM36DXYebbB/SZL iqYg+PGx5U1gR0z9S/KyBqgpHXEOnBJ1BWBSjwSxTSfoWA/MKc5MuvYeovOhNMSIvcTN wtBRjRqNiJeTJR0/7IEgGescUhCWm3hUIaCqdSNhLhHisVuGyiIm7gaJ7GxXonApIa4a bsu7YnWZmq7xI+rvZPD0Nc3FJSSmk+l1rQyIQjdyEQsuy3Kw8zAzCbQ20I9NsBf7UmlB EwGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sbMHPaLO; 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 u19-20020aa7d993000000b0042ab868c6fesi8260450eds.74.2022.06.13.06.03.30; Mon, 13 Jun 2022 06:03:55 -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=sbMHPaLO; 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 S1349017AbiFMK4r (ORCPT + 99 others); Mon, 13 Jun 2022 06:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349410AbiFMKyU (ORCPT ); Mon, 13 Jun 2022 06:54:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D821248FC; Mon, 13 Jun 2022 03:28:06 -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 723D7B80E95; Mon, 13 Jun 2022 10:28:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C597CC3411C; Mon, 13 Jun 2022 10:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116083; bh=TzLegqWaKtcXylWJBZtdaGnyCgqrSdPcY8fQTn74aqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sbMHPaLOEf4YgaO9ULIuRSmX423IOwCNpOesHNQmCM3Z5NFz9JLwz+0eLF3SuRAGc PYSwj3hVDcIFc+gJoo8uc9pXTJArQFV9qdTQA2LuzQm4gDC2J3wXUk8YnQfe2pG5GG ef5gFsNnv+eCLm/94tVr83sG58l9GqsncUf3qoqk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaomeng Tong , Joerg Roedel Subject: [PATCH 4.14 125/218] iommu/msm: Fix an incorrect NULL check on list iterator Date: Mon, 13 Jun 2022 12:09:43 +0200 Message-Id: <20220613094924.364599889@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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 @@ -638,16 +638,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; }