From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AE3E1DFF0 for ; Mon, 13 Apr 2026 14:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776092007; cv=none; b=cKp99dDHV4p1p1s/+QPkG5GmHkiJmFKDa8JRR8BpdRtc5NwOl8QjxWS/1CPi9Jw0pOrZK0n2c1f7vjcDzsZPGKnwZinBnT9FbnddmmecfZDuLrGw5UckcRjIeD1oaW+2o1VpfObYfuME0VLpEaVoFyWtJBbsS6SHGmzbYkUjd0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776092007; c=relaxed/simple; bh=U/o56xLAUs5BK0XAFsMnzu3D154pEgSCh5Zp1ZH9ynQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nfhYGPduBy5p98kLCj913e34QhbVSm0ZJpRxj+/6qXkAf5mNM/scFtsTjVq9uP0xN6UhrIs3iCI4PnBd3nCeKgFCjXc1/xV7h4j7Na7G5MN6xg3js+PoBg3o+690fjU/ysvdq7X30+YhwrN2+QmUk6PuRXYf+cRZndTGYxz168A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=fub1TeUV; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="fub1TeUV" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EBF882E99 for ; Mon, 13 Apr 2026 07:53:19 -0700 (PDT) Received: from [192.168.0.1] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CCED3F641 for ; Mon, 13 Apr 2026 07:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1776092005; bh=U/o56xLAUs5BK0XAFsMnzu3D154pEgSCh5Zp1ZH9ynQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fub1TeUVTbymsCVNqZZR3wzlVl+Ulgsk7DoNggZjHRBx3FvO3IqSIkdKndz19qgmK 8S5PJ1tEIsmpGwXosT2KnlqsxxQlaxDORX5Mu+5d0L2tucudBgv0T0s0UNuJbMt7gM AO5F5W2i2GJn/EXDNwZgsk5JF9eEE4abigCGtvTo= Date: Mon, 13 Apr 2026 15:53:20 +0100 From: Liviu Dudau To: Akash Goel Cc: boris.brezillon@collabora.com, steven.price@arm.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, nd@arm.com Subject: Re: [PATCH v2] drm/panthor: Avoid potential UAF due to memory reclaim Message-ID: References: <20260413080253.1288157-1-akash.goel@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260413080253.1288157-1-akash.goel@arm.com> On Mon, Apr 13, 2026 at 09:02:53AM +0100, Akash Goel wrote: > Recent changes to add shrinker support introduced a use after free > vulnerability. > When a BO is evicted from the shrinker callback, all its CPU and GPU > mappings are invalidated. It can happen that another GPU mapping is > created for the BO after the eviction. Because of the new GPU mapping, > BO will be added back to one of the reclaim list but the state of > corresponding vm_bo will not be changed. > If vm_bo remains in evicted state and shrinker callback is invoked > again then the new GPU mapping won't be invalidated. As a result the > backing pages, which were acquired on the creation of new GPU mapping, > can get reclaimed and reused whilst they are still mapped to the GPU. > > To prevent the use after free possibility, this commit removes the > evicted check for vm_bo so that all GPU mappings are checked for > invalidation. > > v2: > - Update comment and add a newline in > panthor_vm_evict_bo_mappings_locked(). > > Fixes: fb42964e2a76 ("drm/panthor: Add a GEM shrinker") > Suggested-by: Boris Brezillon > Signed-off-by: Akash Goel > Reviewed-by: Boris Brezillon I seem to have some email delivery delays, I've seen v2 after I've replied to v1: Reviewed-by: Liviu Dudau Best regards, Liviu > --- > drivers/gpu/drm/panthor/panthor_mmu.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > index fa8b31df85c9..592a6829bee6 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -2350,14 +2350,20 @@ int panthor_vm_evict_bo_mappings_locked(struct panthor_gem_object *bo) > struct panthor_vm *vm = container_of(vm_bo->vm, struct panthor_vm, base); > struct drm_gpuva *va; > > - /* Skip already evicted GPU mappings. */ > - if (vm_bo->evicted) > - continue; > - > if (!mutex_trylock(&vm->op_lock)) > return -EDEADLK; > > - drm_gpuvm_bo_evict(vm_bo, true); > + /* It can be that the vm_bo was already evicted but a new > + * mapping pointing to this BO got created in the meantime, > + * thus turning the vm_bo in partially evicted state. In that case > + * we don't call drm_gpuvm_bo_evict() again because this would > + * mess up with the internal gpuvm lists, but we do walk the > + * VAs on this vm_bo to make sure the non-evicted ones are > + * torn down. > + */ > + if (!vm_bo->evicted) > + drm_gpuvm_bo_evict(vm_bo, true); > + > drm_gpuvm_bo_for_each_va(va, vm_bo) { > struct panthor_vma *vma = container_of(va, struct panthor_vma, base); > > -- > 2.25.1 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯