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 7A14637754C for ; Fri, 9 Oct 2026 21:00:14 +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=1791579617; cv=none; b=GAQqilOkra93SQHiYIueFvZZWsL781+ldgcDWIc/lqKNEByH1+xvZpp6CJ9OHb4eew6EO46CVmCUI59h78w4gY/c14WeTs6M/wmxv+hN9rST31rF8qswFs8p5uFL4QscHbt/FFq70SkXW+1EuBtps4BkWFilJeFwXLtMO+9qLU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791579617; c=relaxed/simple; bh=yVxRx8Iwa/de/sDhPPSGo7hWUp05Xa6aoPl2C0SywbM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K/WeZsRe4k8DBE88KVSQ4cF606qFqJhhKBWuWsZl0Ui+a1YldDpmuNqvnWK/e4uymiIK7OUVszoKd/GgwOtCiIieHO0dJgn0EcDHI3YuMMaTmACpr/S+MSI7PPYPqQMHPyOWOlRLhIw2AFq+e5tSaWnXCGVQE47Xsvc2UwdDCFU= 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=fkXyMOuv; 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="fkXyMOuv" 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 4823A1FC7 for ; Fri, 9 Oct 2026 14:00:10 -0700 (PDT) Received: from [10.2.11.34] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CCA83F763 for ; Fri, 9 Oct 2026 14:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1791579613; bh=yVxRx8Iwa/de/sDhPPSGo7hWUp05Xa6aoPl2C0SywbM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fkXyMOuvgln9bQt5s6I7Nhi7/Qp2EIt4rfJb9TitsuuqG8k4DATFRwSz+nvYsEsOO ydbxwHDe+dh9fCFSu1Kjc5Qi5eNltyH7exk2fHn0irDseV2AgJIYXAhWJyZPvHQjlo /O9NEGu91AnncHbaiVoEHvtfOsPL/AzjXT2b6Lkg= Date: Fri, 9 Oct 2026 22:00:01 +0100 From: Liviu Dudau To: Osama Abdelkader Cc: Boris Brezillon , Steven Price , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Chia-I Wu , Akash Goel , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase Message-ID: References: <20261008100935.3059587-1-osama.abdelkader@gmail.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: <20261008100935.3059587-1-osama.abdelkader@gmail.com> On Thu, Oct 08, 2026 at 12:09:35PM +0200, Osama Abdelkader wrote: > panthor_group_destroy() checks the GROUP_REGISTERED mark and then calls > xa_erase() without holding the xarray lock across both. If the handle is > destroyed by another thread in between, and a concurrent GROUP_CREATE > reuses the freed ID, the first destroy erases and releases the new, > still-initializing group, leading to a use-after-free in > panthor_group_create(). > > Do the mark check and erase atomically under xa_lock(). > > Fixes: eec7e23d848d ("drm/panthor: Prevent potential UAF in group creation") > Assisted-by: Claude:claude-opus-5.5 > Reviewed-by: Boris Brezillon > Reviewed-by: Liviu Dudau > Cc: stable@vger.kernel.org > Signed-off-by: Osama Abdelkader Pushed to drm-misc-next. Best regards, Liviu > --- > v2: > - added Assisted-by tag, no code changes. > --- > drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c > index 0493858e55d7..a343c5180e01 100644 > --- a/drivers/gpu/drm/panthor/panthor_sched.c > +++ b/drivers/gpu/drm/panthor/panthor_sched.c > @@ -3770,12 +3770,18 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle) > struct panthor_group_pool *gpool = pfile->groups; > struct panthor_device *ptdev = pfile->ptdev; > struct panthor_scheduler *sched = ptdev->scheduler; > - struct panthor_group *group; > + struct panthor_group *group = NULL; > > - if (!xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED)) > - return -EINVAL; > + /* > + * Check the mark and erase the entry atomically, so a concurrent > + * destroy + create can't make us erase a group that's still being > + * initialized and happens to reuse the same handle. > + */ > + xa_lock(&gpool->xa); > + if (xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED)) > + group = __xa_erase(&gpool->xa, group_handle); > + xa_unlock(&gpool->xa); > > - group = xa_erase(&gpool->xa, group_handle); > if (!group) > return -EINVAL; > > -- > 2.53.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯