From: Robin Murphy <robin.murphy@arm.com>
To: Tal Zussman <tz2294@columbia.edu>, Jason Gunthorpe <jgg@ziepe.ca>,
Kevin Tian <kevin.tian@intel.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jean-Philippe Brucker <jpb@kernel.org>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iommu: free dev->iommu when iommu_fwspec_init() cannot allocate the fwspec
Date: Mon, 2 Nov 2026 16:51:05 +0000 [thread overview]
Message-ID: <7e209fb2-4bda-4207-9109-c67c8df41e05@arm.com> (raw)
In-Reply-To: <20261031-iommufd-folio-dirty-v1-1-2cef66d2d6d1@columbia.edu>
On 31/10/2026 8:33 pm, Tal Zussman wrote:
> iommu_fwspec_init() allocates dev->iommu with dev_iommu_get() and then
> the fwspec. If the fwspec allocation fails it returns -ENOMEM but leaves
> dev->iommu allocated, and it leaks.
>
> kmemleak reports it when iommufd_fail_nth injects the allocation
> failure:
>
> unreferenced object 0xffff88811c138b00 (size 192):
> comm "iommufd_fail_nt", pid 783
> backtrace:
> __kmalloc_cache_noprof
> dev_iommu_get
> iommu_fwspec_init
> iommu_mock_device_add
> iommufd_test
> iommufd_fops_ioctl
>
> Free dev->iommu on failure if this call allocated it. iommu_init_device()
> allocates it before calling into the driver and frees it on its own
> error path, so leave it alone in that case.
>
> Fixes: 72acd9df18f1 ("iommu: Move iommu_fwspec to struct dev_iommu")
No, the bug is clearly the early return in 2a918911ed3d ("iommufd:
Register iommufd mock devices with fwspec"), so fix it there please.
iommu_fwspec_init() has always been designed to be called in conjunction
with iommu_probe_device() which handles cleanup appropriately. All of
this mock_device hackery not using the proper probe paths is enough of a
pain as it is...
Thanks,
Robin.
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
> drivers/iommu/iommu.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index cd1bca7ede9a..69be8819e05d 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -3074,6 +3074,7 @@ int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode)
> {
> const struct iommu_device *iommu = iommu_from_fwnode(iommu_fwnode);
> struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
> + bool new_iommu = !dev->iommu;
>
> if (!iommu)
> return driver_deferred_probe_check_state(dev);
> @@ -3088,8 +3089,11 @@ int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode)
>
> /* Preallocate for the overwhelmingly common case of 1 ID */
> fwspec = kzalloc_flex(*fwspec, ids, 1);
> - if (!fwspec)
> + if (!fwspec) {
> + if (new_iommu)
> + dev_iommu_free(dev);
> return -ENOMEM;
> + }
>
> fwnode_handle_get(iommu_fwnode);
> fwspec->iommu_fwnode = iommu_fwnode;
>
next prev parent reply other threads:[~2026-11-02 16:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 20:33 [PATCH 0/2] iommufd: remove the last use of set_page_dirty_lock() Tal Zussman
2026-10-31 20:33 ` [PATCH 1/2] iommu: free dev->iommu when iommu_fwspec_init() cannot allocate the fwspec Tal Zussman
2026-11-02 16:51 ` Robin Murphy [this message]
2026-10-31 20:33 ` [PATCH 2/2] iommufd: copy to and from folios in batch_rw() Tal Zussman
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=7e209fb2-4bda-4207-9109-c67c8df41e05@arm.com \
--to=robin.murphy@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tz2294@columbia.edu \
--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®