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 5D22B606A31C for ; Mon, 30 Nov 2026 06:52:00 +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=Iyu6jWf7 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F20E110E1B3; Mon, 30 Nov 2026 06:51:54 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id D4AE210E1B3 for ; Mon, 30 Nov 2026 06:51:48 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 63A0341207; Mon, 30 Nov 2026 06:51:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F31CE1F00899; Mon, 30 Nov 2026 06:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796021508; bh=KBZTlMrh6TngBHT0CypeJ2vjY7mH8C+nRc8VAh7P7Lw=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=Iyu6jWf7b0fa5ZOrnQkKiA/f3rq+Cd9VLGE0IG7rnUnqP2QjLAPXjelpkJWUR+fg6 GiBLWcTdawjaMer00iyRk59sLkyCfQ4aipz88M+J5tCEFo9CCd0cjwmIPXw2brdmB5 ++HKwE/IYqLkYNbbFR9g4Rv7OxYaUyAL3RCWvih3slE1tVXaK/ABeFjUedo8cYi713 8MfvS4/M5MJgCpdOqtMaUmcPkg8KatqwL/Z5ti6FCb8Ux2irhk2itL2zadQ+XAcVNd i87/GocAg8m4Ozq5oSD4Z9wH1j9pjWkKmfDZRCHwx3+b7JPLOpoaSc4gNCQByE2ZR5 2VO684wqAedsQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH V2 1/2] drm/amdgpu: reject userptr BOs as userqueue write pointers To: "Jesse Zhang" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261130062604.1921479-1-Jesse.Zhang@amd.com> References: <20261130062604.1921479-1-Jesse.Zhang@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 06:51:47 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: userptr check bypass via zero addr in amdgpu_ttm_tt_is_userptr() -- commit 49d56b1a7c36fe3478f82185ee8e35956c14e164 Author: Jesse Zhang drm/amdgpu: reject userptr BOs as userqueue write pointers This commit rejects userptr BOs in amdgpu_userq_fence_read_wptr() and mes_userq_create_wptr_mapping() using amdgpu_ttm_tt_is_userptr(). > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gp= u/drm/amd/amdgpu/amdgpu_userq_fence.c > index 614599ba5455a..443a00514035f 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c > @@ -401,6 +401,12 @@ static int amdgpu_userq_fence_read_wptr(struct amdgp= u_device *adev, > } > =20 > bo =3D mapping->bo_va->base.bo; > + /* Userptr pages may not be populated when reading the WPTR. */ > + if (amdgpu_ttm_tt_is_userptr(bo->tbo.ttm)) { > + ret =3D -EINVAL; > + goto lock_error; > + } > + > ret =3D amdgpu_bo_kmap(bo, (void **)&ptr); > if (ret) { > DRM_ERROR("Failed mapping the userqueue wptr bo"); > diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm= /amd/amdgpu/mes_userqueue.c > index 7abb9d95ef59a..3d4bc3a902a32 100644 > --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c > +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c > @@ -73,7 +73,9 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *ade= v, > } > =20 > wptr_obj->obj =3D amdgpu_bo_ref(wptr_mapping->bo_va->base.bo); > - if (wptr_obj->obj->tbo.base.size > PAGE_SIZE) { > + /* Userptr pages cannot be obtained by ttm_bo_validate(). */ > + if (wptr_obj->obj->tbo.base.size > PAGE_SIZE || > + amdgpu_ttm_tt_is_userptr(wptr_obj->obj->tbo.ttm)) { > ret =3D -EINVAL; > goto fail_map; > } [Severity: High] Can a userptr BO created with addr =3D=3D 0 bypass both of these amdgpu_ttm_tt_is_userptr() checks? amdgpu_gem_userptr_ioctl() permits args->addr =3D=3D 0 (for example with AMDGPU_GEM_USERPTR_READONLY and without AMDGPU_GEM_USERPTR_VALIDATE), which leaves gtt->userptr =3D=3D 0, sets TTM_TT_FLAG_EXTERNAL, and leaves ttm->pages unpopulated. Because amdgpu_ttm_tt_is_userptr() tests !gtt->userptr rather than gtt->usertask: drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:amdgpu_ttm_tt_is_userptr() { struct amdgpu_ttm_tt *gtt =3D ttm_to_amdgpu_ttm_tt(ttm); if (gtt =3D=3D NULL || !gtt->userptr) return false; return true; } it returns false when gtt->userptr =3D=3D 0. Calling amdgpu_bo_kmap() on t= hat BO in amdgpu_userq_fence_read_wptr() then reaches ttm_bo_kmap_ttm() with ttm->pages[0] =3D=3D NULL, and validating it into GTT in mes_userq_create_wptr_mapping() reaches amdgpu_ttm_backend_bind() with gtt->gobj->import_attach =3D=3D NULL, both causing a NULL pointer dereference. Checking gtt->usertask (as amdgpu_ttm_tt_get_usermm() does) in amdgpu_ttm_tt_is_userptr() would catch userptr BOs regardless of address. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130062604.1921= 479-1-Jesse.Zhang@amd.com?part=3D1