From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
To: Joao Martins <joao.m.martins@oracle.com>,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Cc: Dan Carpenter <dan.carpenter@oracle.com>, Joerg Roedel <joro@8bytes.org>
Subject: Re: [PATCH] iommu/amd: Fix potential @entry null deref
Date: Fri, 11 Sep 2020 10:24:40 +0700 [thread overview]
Message-ID: <f1a0b4f7-33df-f541-9df8-39dd282aef29@amd.com> (raw)
In-Reply-To: <20200910171621.12879-1-joao.m.martins@oracle.com>
Thanks for catching this.
On 9/11/20 12:16 AM, Joao Martins wrote:
> 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.
>
> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Fixes: 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
> 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 07ae8b93887e..8abe1c7ad45b 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3864,12 +3864,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;
>
>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Suravee
WARNING: multiple messages have this Message-ID (diff)
From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
To: Joao Martins <joao.m.martins@oracle.com>,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] iommu/amd: Fix potential @entry null deref
Date: Fri, 11 Sep 2020 10:24:40 +0700 [thread overview]
Message-ID: <f1a0b4f7-33df-f541-9df8-39dd282aef29@amd.com> (raw)
In-Reply-To: <20200910171621.12879-1-joao.m.martins@oracle.com>
Thanks for catching this.
On 9/11/20 12:16 AM, Joao Martins wrote:
> 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.
>
> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Fixes: 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming IRTE")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
> 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 07ae8b93887e..8abe1c7ad45b 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3864,12 +3864,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;
>
>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Suravee
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-09-11 3:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 17:16 [PATCH] iommu/amd: Fix potential @entry null deref Joao Martins
2020-09-10 17:16 ` Joao Martins
2020-09-11 3:24 ` Suravee Suthikulpanit [this message]
2020-09-11 3:24 ` Suravee Suthikulpanit
2020-09-18 8:36 ` Joerg Roedel
2020-09-18 8:36 ` Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f1a0b4f7-33df-f541-9df8-39dd282aef29@amd.com \
--to=suravee.suthikulpanit@amd.com \
--cc=dan.carpenter@oracle.com \
--cc=iommu@lists.linux-foundation.org \
--cc=joao.m.martins@oracle.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.