From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Yiming Qian <yimingqian591@gmail.com>,
Vivek Kasireddy <vivek.kasireddy@intel.com>,
Kevin Tian <kevin.tian@intel.com>, Joerg Roedel <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
keenanat2000@gmail.com, linux-mm@kvack.org,
Christoph Hellwig <hch@lst.de>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH] iommu/iommufd: Require write access for writable MAP_FILE mappings
Date: Mon, 8 Jun 2026 15:54:55 +0200 [thread overview]
Message-ID: <4c21bee6-fa58-4d28-b6e5-aefc9dd67cb5@kernel.org> (raw)
In-Reply-To: <20260608134614.GA4111154@nvidia.com>
On 6/8/26 15:46, Jason Gunthorpe wrote:
> On Mon, Jun 08, 2026 at 03:38:00PM +0200, David Hildenbrand (Arm) wrote:
>> On 6/7/26 14:09, Jason Gunthorpe wrote:
>>>
>>> This looks like an issue with the API design in memfd_pin_folios(),
>>> all users would have a similar bug I think.
>>
>> Agreed.
>>
>> Not sure if it should be part of memfd_pin_folios() itself.
>
> I think it should, drivers should not be open coding this.
>
> If there is such a thing as a read-only memfd then memfd_pin_folios()
> should accept the usual FOLL_WRITE and deal with it internally.
I'd rather not want to use FOLL flags (FOLLOW PAGE leftovers, to be renamed to
GUP_ on some lucky day) on this interface.
But sure, we could add a new set of flags (single flag for now).
>
>>> start/pin/destroy kind of thing to manage this?
>>>
>>> It should not be open coded like this.
>>
>> The permission check is one thing that's clearly missing.
>>
>> Not sure about the mapping_map_writable() handling ... it's weird to rely on
>> that when we are not actually mmaping.
>
> I don't know anything about sealing, but it shouldn't something check
> if it is sealed read-only ?
Right. We could do mapping_map_writable() over the duration of the function I
guess if we care about concurrent races.
Alternative have a new helper that makes sure that mapping->i_mmap_writable is
not negative (write denied).
>
>> Assume we GUP a page and then munmap, mapping_unmap_writable() would be called
>> while we still have a writable GUP reference. Hm.
>
> I suspect the user doing the sealing has to ensure there are no pins
> to the memfd before it seals it. If it already let the unsealed memfd
> out of its control then it probably cannot be reliably sealed read
> only?
Yes, that's my assumption. writable pins derived pre-sealing stay valid.
--
Cheers,
David
prev parent reply other threads:[~2026-06-08 13:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260607085320.73274-1-yimingqian591@gmail.com>
2026-06-07 12:09 ` [PATCH] iommu/iommufd: Require write access for writable MAP_FILE mappings Jason Gunthorpe
2026-06-08 13:38 ` David Hildenbrand (Arm)
2026-06-08 13:46 ` Jason Gunthorpe
2026-06-08 13:54 ` David Hildenbrand (Arm) [this message]
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=4c21bee6-fa58-4d28-b6e5-aefc9dd67cb5@kernel.org \
--to=david@kernel.org \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=joro@8bytes.org \
--cc=keenanat2000@gmail.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=robin.murphy@arm.com \
--cc=vivek.kasireddy@intel.com \
--cc=will@kernel.org \
--cc=yimingqian591@gmail.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