From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4415606A330 for ; Sat, 14 Nov 2026 19:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QYNoTnXj Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AC7310E181; Sat, 14 Nov 2026 19:08:20 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id EED9210E181; Sat, 14 Nov 2026 19:08:13 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id DFB1E60DE6; Sat, 14 Nov 2026 19:08:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C2531F000C4; Sat, 14 Nov 2026 19:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794683292; bh=jrpYg7S3w1u/s304fksd+9WkuwgFpjkNMJMjxnYOktE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=QYNoTnXjjZhBPnpa8pOfyk2yFfApF74bnIOvALp/oKYkwpyK77UolVRCAS9PWBwUT vTBNeJc2BT3hD65bSUXiJIzuZRodbsdX1fnL8/SMLFCYNn/+H570eO0UW2ZwVw9sWk GMxUycxR4kFYE/1x4BsPOWM6QfVcHWY7lAkRzLGYC2spj4KtaAwckhv3IaoPq1c+i0 7WJXBqF1BvvLoxaDFl2abs10ZuIiJ39Ub7KZHMiai60iJ0e/m7v+0PTgqGv8kiifml yLA7l8Fl3UguxEqgTAbhHe6k1GakSXqMGY5FQ9ZyVqlS8LVqbDnHwiqz6bl9cWiY9E wqQgRo+ur+kWQ== Date: Sat, 14 Nov 2026 19:08:02 +0000 From: "Lorenzo Stoakes (ARM)" To: "David Hildenbrand (Arm)" Cc: "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Andrew Morton , Willy Tarreau , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Chris Wilson , Matthew Auld , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , Shrikanth Hegde , Rik van Riel , Benjamin Herrenschmidt , 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 , Christian =?utf-8?B?S8O2bmln?= , Chris Mason Subject: Re: [PATCH 5/5] mm: check permissions and bounds for vm_ops->access Message-ID: References: <20261112-access_shite-v1-0-988a5c470db2@kernel.org> <20261112-access_shite-v1-5-988a5c470db2@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261112-access_shite-v1-5-988a5c470db2@kernel.org> X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-gfx" X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Nov 12, 2026 at 11:09:01PM +0100, 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//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 > Cc: Christian König > Cc: Simona Vetter > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) LGTM, yikes at this in general :) Reviewed-by: Lorenzo Stoakes (ARM) > --- > 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; > + /* > + * In contrast to GUP, we historically allowed > + * FOLL_FORCE write access to non-CoW mappings. > + * However, we must always reject CoW mappings > + * as we cannot CoW here. > + */ > + if (vma_is_cow_mapping(vma)) > + break; > + } else if (!vma_test(vma, VMA_READ_BIT)) { > + if (!force || !vma_test(vma, VMA_MAYREAD_BIT)) > + break; > + } > + > /* > * Check if this is a VM_IO | VM_PFNMAP VMA, which > * we can access using slightly different code. > */ > bytes = 0; > #ifdef CONFIG_HAVE_IOREMAP_PROT > - if (vma->vm_ops && vma->vm_ops->access) > + if (vma->vm_ops && vma->vm_ops->access) { > + bytes = min_t(unsigned long, len, vma->vm_end - addr); > bytes = vma->vm_ops->access(vma, addr, buf, > - len, write); > + bytes, write); > + } > #endif > if (bytes <= 0) > break; > > -- > 2.43.0 > -- Cheers, Lorenzo