Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3295705pxk; Mon, 21 Sep 2020 09:57:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbQ3haj9SDS6zoDohJDbpLlJboW6HXa0f1FrNVHP5Zwqtcwu4HnIqy7fJsEBAGU370vFGJ X-Received: by 2002:a17:906:d7a2:: with SMTP id pk2mr360113ejb.149.1600707430655; Mon, 21 Sep 2020 09:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707430; cv=none; d=google.com; s=arc-20160816; b=xF8fHDExNEBrNcYAJFlkt4tSx+zFcOQAv7aMnnSvuL2lt2bkRW5aAubIJie/meIG9v +LpWJcxjTxl6jBxqCf4gqMi3suZbOMwK7U1xZMA2BughdksKsnVV4ejiwPWjClvQ9R25 5YGuJuTyvgvq6hvuo1saCjNBxozcsmkLwvN3nuMFoWu3YUEf9RLMelUHQHzKhax9iF7m zVAits89BgciChZp/4qA6B3oEY3XUSnd65KQKS2WI2IBy14tKhjvvId3wDI3M3pYJOqo eA/eGNQJnrPdsuJ7K7KPQgZezZn0nIW7W5Rd9lQPl+/zhIXckaF0rP3Pkz78rUGk4+7a M4Vw== 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=IoVJVkRz412+bOgmgcDP+WE1FJ+RuqoijDO/0H+ASbw=; b=X8qAPtf+isD7i8xfebkqa27dRfcvNLLOMJH60sBjsSn1ZEhl2zck8XH5FpIWjUbe/j V8EnC/BQLRUj0rUNWc/IBsPyOrA1tlQ8gsmLb3acrI6RXwVaaRJNQpRLKbg5kj8TMLTs k2/6QJ3Pfwiy7UxB3O+wAR5evenbsOlc3JP8ZaqEB376rZXps2GnaL/DlsCgD5SPw61/ MEfLUll/fQeaeD7UF91YruJlMJ1EPWzRRDhLBt7InQLeIoBBW0zjOAuonFNEGGYpKf5F /EW0hCuqaElc8B2IpBEJrAjZvpbpsE19n+VkRHXwzIg73llOO7VvCbarrBa3O5NsdYBg nlTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UKlDa5QM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w23si8535990eju.558.2020.09.21.09.56.46; Mon, 21 Sep 2020 09:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UKlDa5QM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729870AbgIUQzo (ORCPT + 99 others); Mon, 21 Sep 2020 12:55:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:51590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbgIUQpe (ORCPT ); Mon, 21 Sep 2020 12:45:34 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 078E7206B2; Mon, 21 Sep 2020 16:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706733; bh=YsJqGuQHBEUaF1qm14Gss1YdcyjLDX2tF6KDxKMGKjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UKlDa5QM8DU7f2sm6jMrEXuqopt5WVjW2DsylR0RF+pDRlwv6KY07PkSJuF7fp6Ss 642xrgDOBvFK1nXYyLpXkco8N2AyLyHI80acKF8jrND/LLoeBuXq5QenKVTLQzewud /+KvplWxd5zbf71na0hXeZbVW3XioT3LWjzPv2/M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Joao Martins , Suravee Suthikulpanit , Joerg Roedel , Sasha Levin Subject: [PATCH 5.8 073/118] iommu/amd: Fix potential @entry null deref Date: Mon, 21 Sep 2020 18:28:05 +0200 Message-Id: <20200921162039.724027857@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joao Martins [ Upstream commit 14c4acc5ed22c21f9821103be7c48efdf9763584 ] After commit 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE"), smatch warns: drivers/iommu/amd/iommu.c:3870 amd_iommu_deactivate_guest_mode() warn: variable dereferenced before check 'entry' (see line 3867) Fix this by moving the @valid assignment to after @entry has been checked for NULL. Fixes: 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE") Reported-by: Dan Carpenter Signed-off-by: Joao Martins Reviewed-by: Suravee Suthikulpanit Cc: Suravee Suthikulpanit Link: https://lore.kernel.org/r/20200910171621.12879-1-joao.m.martins@oracle.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd/iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 37c74c842f3a3..48fe272da6e9c 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -3855,12 +3855,14 @@ int amd_iommu_deactivate_guest_mode(void *data) struct amd_ir_data *ir_data = (struct amd_ir_data *)data; struct irte_ga *entry = (struct irte_ga *) ir_data->entry; struct irq_cfg *cfg = ir_data->cfg; - u64 valid = entry->lo.fields_remap.valid; + u64 valid; if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) || !entry || !entry->lo.fields_vapic.guest_mode) return 0; + valid = entry->lo.fields_remap.valid; + entry->lo.val = 0; entry->hi.val = 0; -- 2.25.1