From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4F3E3233FA for ; Thu, 27 Nov 2025 08:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764232728; cv=none; b=WL3jXC4nVIrP6rpPpR1823SLKeIYsy8kmRy0YyCqv3SuAFAMKHge8DKFsEIYjxiHUh3lTccimIpH2Yb6a42HuGN4Gtm7zIBNXAEKNvxwQEvpiqa11neVIs4OGpzX3KwF2ycf5MWzskcpSLdKN1X9hn7Fb9l2VtOtNu8hQ2xhOkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764232728; c=relaxed/simple; bh=qnx/n7ISPo6IfaQt0Ak+D6/oxoHkK37j5g3IpC14Luc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c8FEDS3yZFeeYT5K8JMeRSawUlIEyg3Dcb0WIwl5e3+E9fK6R4nbNrc7gN7Gogz3iagryO1Li59Qnww1v4zBSpixG32JwTXjbS1z5DF+pcASe6o6FoOsqM3sZYsgt2TyPJVmilMxdH4W7cVpUh8vHi3gbOlmV+jlm62CqCUnUow= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=KEebosn5; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="KEebosn5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764232722; bh=qnx/n7ISPo6IfaQt0Ak+D6/oxoHkK37j5g3IpC14Luc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KEebosn5+T9zt6LKYS6zFFlAW5tqejrk6v4rtlMSIA2uV9Qkmqcz76Rzim3E/ySxN 6AASoV9Uetc28K50l/CBaf6B4UhYJmB7I9isLB7jHaFpRH1L/vm+J26e1HfqBSz6e5 cjT+qF2LFvrUbDDcdp90/nWPjVqxmLjnjdXsSjE7K7jJQ9o06pVp+SyHcga7VU2pFV cfk0JMqrh4eowInBtNWQLm9QCuZRpgm3s2NPCFZHB75ja0+lpDtmAprN3QemAW7WLX 7XoL7qfPHxjh6G5tC/W6UfHYq5pV1MP2YbMJIPHBftvkUpGDNkpfQmRN6R20+utc1v oFzfN4Bc2sqLg== Received: from fedora (unknown [IPv6:2a01:e0a:2c:6930:d919:a6e:5ea1:8a9f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id 774A717E0360; Thu, 27 Nov 2025 09:38:42 +0100 (CET) Date: Thu, 27 Nov 2025 09:38:38 +0100 From: Boris Brezillon To: Akash Goel Cc: liviu.dudau@arm.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] drm/panthor: Prevent potential UAF in group creation Message-ID: <20251127093838.00470c7d@fedora> In-Reply-To: <20251127081239.3744766-1-akash.goel@arm.com> References: <20251127081239.3744766-1-akash.goel@arm.com> Organization: Collabora X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-redhat-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 27 Nov 2025 08:12:39 +0000 Akash Goel wrote: > This commit prevents the possibility of a use after free issue in the > GROUP_CREATE ioctl function, which arose as pointer to the group is > accessed in that ioctl function after storing it in the Xarray. > A malicious userspace can second guess the handle of a group and try > to call GROUP_DESTROY ioctl from another thread around the same time > as GROUP_CREATE ioctl. > > To prevent the use after free exploit, this commit uses a mark on an > entry of group pool Xarray which is added just before returning from > the GROUP_CREATE ioctl function. The mark is checked for all ioctls > that specify the group handle and so userspace won't be abe to delete > a group that isn't marked yet. > > Co-developed-by: Boris Brezillon > Signed-off-by: Akash Goel Already approved privately, but here's the official Reviewed-by: Boris Brezillon > --- > drivers/gpu/drm/panthor/panthor_sched.c | 19 +++++++++++++++---- > 1 file changed, 15 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c > index b834123a6560..a6b8024e1a3c 100644 > --- a/drivers/gpu/drm/panthor/panthor_sched.c > +++ b/drivers/gpu/drm/panthor/panthor_sched.c > @@ -779,6 +779,12 @@ struct panthor_job_profiling_data { > */ > #define MAX_GROUPS_PER_POOL 128 > > +/* > + * Mark added on an entry of group pool Xarray to identify if the group has > + * been fully initialized and can be accessed elsewhere in the driver code. > + */ > +#define GROUP_REGISTERED XA_MARK_1 > + > /** > * struct panthor_group_pool - Group pool > * > @@ -3007,7 +3013,7 @@ void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile) > return; > > xa_lock(&gpool->xa); > - xa_for_each(&gpool->xa, i, group) { > + xa_for_each_marked(&gpool->xa, i, group, GROUP_REGISTERED) { > guard(spinlock)(&group->fdinfo.lock); > pfile->stats.cycles += group->fdinfo.data.cycles; > pfile->stats.time += group->fdinfo.data.time; > @@ -3727,6 +3733,8 @@ int panthor_group_create(struct panthor_file *pfile, > > group_init_task_info(group); > > + xa_set_mark(&gpool->xa, gid, GROUP_REGISTERED); > + > return gid; > > err_erase_gid: > @@ -3744,6 +3752,9 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle) > struct panthor_scheduler *sched = ptdev->scheduler; > struct panthor_group *group; > > + if (!xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED)) > + return -EINVAL; > + > group = xa_erase(&gpool->xa, group_handle); > if (!group) > return -EINVAL; > @@ -3769,12 +3780,12 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle) > } > > static struct panthor_group *group_from_handle(struct panthor_group_pool *pool, > - u32 group_handle) > + unsigned long group_handle) > { > struct panthor_group *group; > > xa_lock(&pool->xa); > - group = group_get(xa_load(&pool->xa, group_handle)); > + group = group_get(xa_find(&pool->xa, &group_handle, group_handle, GROUP_REGISTERED)); > xa_unlock(&pool->xa); > > return group; > @@ -3861,7 +3872,7 @@ panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile, > return; > > xa_lock(&gpool->xa); > - xa_for_each(&gpool->xa, i, group) { > + xa_for_each_marked(&gpool->xa, i, group, GROUP_REGISTERED) { > stats->resident += group->fdinfo.kbo_sizes; > if (group->csg_id >= 0) > stats->active += group->fdinfo.kbo_sizes;