Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Christian König" <christian.koenig@amd.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Willy Tarreau" <w@1wt.eu>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Chris Wilson" <chris@chris-wilson.co.uk>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	"Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"Rik van Riel" <riel@redhat.com>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org,
	Felix Kuehling <Felix.Kuehling@amd.com>,
	Chris Mason <mason@kernel.org>
Subject: Re: [PATCH 5/5] mm: check permissions and bounds for vm_ops->access
Date: Mon, 16 Nov 2026 19:26:27 +0100	[thread overview]
Message-ID: <200c4dca-63a4-487e-bd59-dc89c9018b0a@kernel.org> (raw)
In-Reply-To: <980220a5-390e-40a7-bd5c-16a2225bd75b@amd.com>

On 11/16/26 16:51, Christian König wrote:
> 
> 
> On 11/12/26 23:09, David Hildenbrand (Arm) wrote:
>> GUP rejects VM_IO and VM_PFNMAP mappings early. __access_remote_vm() then
>> falls back to vm_ops->access without checking VMA permissions and without
>> limiting the request to the VMA size.
>>
>> Consequently, /proc/<pid>/mem can bypass protections even without
>> FOLL_FORCE, or cross into another mapping without checking its
>> permissions.
>>
>> Check VMA permissions before calling ->access and limit each request to
>> the current VMA. Implement similar access permission checks as GUP,
>> however:
>>  (1) Reject writes to CoW mappings because the callbacks access backing
>>      memory directly and cannot handle CoW.
>>  (2) Allow forced writes to non-CoW mappings with VM_MAYWRITE.
>>
>> This intentionally breaks forced writes through legacy amdgpu PROT_NONE,
>> MAP_PRIVATE debugger mappings. The workaround in commit fa5239f2af98
>> ("drm/amdgpu: workaround failed COW checks for Thunk VMAs") cleared
>> VM_MAYWRITE to avoid CoW, but debugger writes still succeeded by
>> exploiting the missing access-permission checks fixed here. Reads remain
>> supported. Userspace must use MAP_SHARED instead; ROCm 5.5.0, released
>> in May 2023, already does so.
>>
>> Link: https://github.com/ROCm/ROCT-Thunk-Interface/commit/fea44fab6e84eda52fcf6b419b35600c18f4c022
>> Fixes: 272ddc8b3735 ("proc: don't use FOLL_FORCE for reading cmdline and environment")
>> Cc: stable@vger.kernel.org
>> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
>> Cc: Christian König <christian.koenig@amd.com>
>> Cc: Simona Vetter <simona@ffwll.ch>
>> Reported-by: Chris Mason <mason@kernel.org>
>> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
>> ---
>>  mm/memory.c | 25 +++++++++++++++++++++++--
>>  1 file changed, 23 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/memory.c b/mm/memory.c
>> index d4370c1b331c9..9872f289c1e49 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -7362,6 +7362,7 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
>>  static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
>>  			      void *buf, int len, unsigned int gup_flags)
>>  {
>> +	const bool force = gup_flags & FOLL_FORCE;
>>  	void *old_buf = buf;
>>  	int write = gup_flags & FOLL_WRITE;
>>  
>> @@ -7401,15 +7402,35 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
>>  			if (gup_flags & FOLL_ANON)
>>  				break;
>>  
>> +			if (write) {
> 
>> +				if (!vma_test(vma, VMA_MAYWRITE_BIT))
>> +					break;
>> +				if (!vma_test(vma, VMA_WRITE_BIT) && !force)
>> +					break;
> 

Hi,

> I might be wrong but IIRC that was brought up before and was rejected.
> 
> We even had a bug report for AMDGPU from a security researcher claiming that you could circumvent security checks using vma->vm_ops->access() which turned out to be complete nonsense after spending tons of time investigating it.
> 

independent of all actual security issues, the current core-mm is completely
fragile as is.

This needs to be fixed independent of driver hacks that are in place.

> The technical background is that there are applications which runtime generate shader code which is then protected by making the VMA read only. But the debugger is still allowed to write to it using vma->vm_ops->access().
> 

Yes, that's precisely what FOLL_FORCE is for, which is what debuggers (ptrace
access) should be using.

So if there are debugger interfaces that are not using FOLL_FORCE, we would have
to see what we can do about that. (and not keep core-mm fragile)


> That behavior is ok because drivers specific and drivers have checks in place if their backing store is read only or not.
> 

"trust me, drivers do the right thing"

Core-mm needs to to something reasonable.
> For an example see this code here: https://elixir.bootlin.com/linux/v7.3.1/source/drivers/gpu/drm/i915/gem/i915_gem_ttm.c#L1163
> 
> So if you do this here you might break intentional uAPI.

Let's figure out what would actually be broken to then decide how we can keep it
working without keeping core-mm a swiss cheese.

Thanks for the review!

-- 
Cheers,

David


  reply	other threads:[~2026-11-16 18:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 22:08 [PATCH 0/5] mm,drm/i915,powerpc/spufs: vm_ops->access related fixes David Hildenbrand (Arm)
2026-11-12 22:08 ` [PATCH 1/5] mm: do not call vm_ops->access with FOLL_ANON David Hildenbrand (Arm)
2026-11-14 18:56   ` Lorenzo Stoakes (ARM)
2026-11-12 22:08 ` [PATCH 2/5] drm/i915: consider vm_pgoff in vm_access() David Hildenbrand (Arm)
2026-11-14 18:58   ` Lorenzo Stoakes (ARM)
2026-11-12 22:08 ` [PATCH 3/5] drm/i915/selftests: request read access for mmap access tests David Hildenbrand (Arm)
2026-11-14 18:58   ` Lorenzo Stoakes (ARM)
2026-11-12 22:09 ` [PATCH 4/5] powerpc/spufs: consider vm_pgoff in spufs_mem_mmap_access() David Hildenbrand (Arm)
2026-11-14 18:59   ` Lorenzo Stoakes (ARM)
2026-11-12 22:09 ` [PATCH 5/5] mm: check permissions and bounds for vm_ops->access David Hildenbrand (Arm)
2026-11-13 20:25   ` Kuehling, Felix
2026-11-13 21:37     ` David Hildenbrand (Arm)
2026-11-14 19:08   ` Lorenzo Stoakes (ARM)
2026-11-16 15:51   ` Christian König
2026-11-16 18:26     ` David Hildenbrand (Arm) [this message]
2026-11-14 16:17 ` [PATCH 0/5] mm,drm/i915,powerpc/spufs: vm_ops->access related fixes David Hildenbrand (Arm)

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=200c4dca-63a4-487e-bd59-dc89c9018b0a@kernel.org \
    --to=david@kernel.org \
    --cc=Felix.Kuehling@amd.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=chleroy@kernel.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=ljs@kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mason@kernel.org \
    --cc=matthew.auld@intel.com \
    --cc=mhocko@suse.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=riel@redhat.com \
    --cc=ritesh.list@gmail.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=rppt@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=sshegde@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=tursulin@ursulin.net \
    --cc=vbabka@kernel.org \
    --cc=w@1wt.eu \
    /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