From: Jerry Snitselaar <jsnitsel@redhat.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Lu Baolu <baolu.lu@linux.intel.com>
Subject: Re: [RFC PATCH] iommu/vt-d: Add sanity check to iommu_sva_bind_device()
Date: Thu, 13 Oct 2022 09:33:17 -0700 [thread overview]
Message-ID: <20221013163317.pgcsvmktotdtkduf@cantor> (raw)
In-Reply-To: <20221013153355.2365865-1-jsnitsel@redhat.com>
And I apparently had vt-d on the brain, which should be dropped
from the summary.
On Thu, Oct 13, 2022 at 08:33:55AM -0700, Jerry Snitselaar wrote:
> iommu_sva_bind_device() should only be called if
> iommu_dev_enable_feature() succeeded. There has been one case already
> where that hasn't been the case, which resulted in a null pointer
> deref in dev_iommu_ops(). To avoid that happening in the future if
> another driver makes that mistake, sanity check dev->iommu and
> dev->iommu->iommu_dev prior to calling dev_iommu_ops().
>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: Will Deacon <will@kernel.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Lu Baolu <baolu.lu@linux.intel.com>
> Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
> ---
> drivers/iommu/iommu.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 4893c2429ca5..20ec75667529 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -2746,7 +2746,15 @@ iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata)
> {
> struct iommu_group *group;
> struct iommu_sva *handle = ERR_PTR(-EINVAL);
> - const struct iommu_ops *ops = dev_iommu_ops(dev);
> + const struct iommu_ops *ops;
> +
> + if (!dev->iommu || !dev->iommu->iommu_dev) {
> + dev_warn(dev, "%s called without checking succes of iommu_dev_enable_feature?\n",
> + __func__);
> + return ERR_PTR(-ENODEV);
> + }
> +
> + ops = dev_iommu_ops(dev);
>
> if (!ops->sva_bind)
> return ERR_PTR(-ENODEV);
> --
> 2.37.2
>
next prev parent reply other threads:[~2022-10-13 16:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 15:33 Jerry Snitselaar
2022-10-13 15:37 ` Jerry Snitselaar
2022-10-13 16:33 ` Jerry Snitselaar [this message]
2022-10-13 17:13 ` [RFC PATCH v2] iommu: " Jerry Snitselaar
2022-10-14 1:52 ` [RFC PATCH] iommu/vt-d: " Baolu Lu
2022-10-14 2:10 ` Jerry Snitselaar
2022-10-14 2:22 ` Baolu Lu
2022-10-14 6:52 ` Jerry Snitselaar
2022-10-14 11:01 ` Robin Murphy
2022-10-14 15:25 ` Jerry Snitselaar
2022-10-14 16:50 ` Jerry Snitselaar
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=20221013163317.pgcsvmktotdtkduf@cantor \
--to=jsnitsel@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®