From: Thomas Tai <thomas.tai@oracle.com>
To: Christoph Hellwig <hch@lst.de>
Cc: iommu@lists.linux-foundation.org, robin.murphy@arm.com,
linux-kernel@vger.kernel.org, konrad.wilk@oracle.com
Subject: Re: [PATCH] dma-direct: Fix potential NULL pointer dereference
Date: Tue, 15 Sep 2020 16:46:17 -0400 [thread overview]
Message-ID: <5136ed8d-d37d-8144-a6f3-c23f272d8926@oracle.com> (raw)
In-Reply-To: <20200915150929.GA19770@lst.de>
On 2020-09-15 11:09 a.m., Christoph Hellwig wrote:
> On Tue, Sep 15, 2020 at 10:40:39AM -0400, Thomas Tai wrote:
>>> +++ b/include/linux/dma-direct.h
>>> @@ -62,9 +62,6 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
>>> {
>>> dma_addr_t end = addr + size - 1;
>>> - if (!dev->dma_mask)
>>> - return false;
>>> -
>>
>> I am concerned that some drivers may rely on this NULL checking. Would you
>> think we can keep this checking and use the following WARN_ON_ONCE()?
>
> dma_capable is not a helper for drivers, but just for dma-direct
> and related code. And this patch adds the checks for the three
> places how we call into the ->map* methods.
>
Hi Christoph,
I tried out the suggested changes, and it successfully warned the null
pointer without panic. I notice that there are some places outside the
dma-direct, which calls dma_capable().
https://elixir.bootlin.com/linux/v5.9-rc5/source/arch/x86/kernel/amd_gart_64.c#L187
https://elixir.bootlin.com/linux/v5.9-rc5/source/drivers/xen/swiotlb-xen.c#L387
Also, if I remove the null checking in dma_capable(), I may run into the
risk of a null pointer dereference within the function.
@@ -62,9 +62,6 @@ static inline bool dma_capable(struct device *dev,
dma_addr_t addr, size_t size,
{
dma_addr_t end = addr + size - 1;
- if (!dev->dma_mask)
- return false;
-
if (is_ram && !IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
min(addr, end) < phys_to_dma(dev, PFN_PHYS(min_low_pfn)))
return false;
return end <= min_not_zero(*dev->dma_mask, dev->bus_dma_limit);
^
|
** risk of a null dereference **
}
Given that the WARN_ON_ONCE already did the intended warning, would you
be ok that I keep the null checking in dma_capable()?
Thank you,
Thomas
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-09-15 20:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-15 14:03 [PATCH] dma-direct: Fix potential NULL pointer dereference Thomas Tai
2020-09-15 14:07 ` Christoph Hellwig
2020-09-15 14:08 ` Christoph Hellwig
2020-09-15 14:11 ` Thomas Tai
2020-09-15 14:26 ` Christoph Hellwig
2020-09-15 14:40 ` Thomas Tai
2020-09-15 15:09 ` Christoph Hellwig
2020-09-15 15:12 ` Thomas Tai
2020-09-15 20:46 ` Thomas Tai [this message]
2020-09-16 6:19 ` Christoph Hellwig
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=5136ed8d-d37d-8144-a6f3-c23f272d8926@oracle.com \
--to=thomas.tai@oracle.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
/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;
as well as URLs for NNTP newsgroup(s).