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 071FA606A338 for ; Tue, 1 Dec 2026 06:06:29 +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=IwmzshzQ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6AD7F10F024; Tue, 1 Dec 2026 06:06:23 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97B7910ED9A; Tue, 1 Dec 2026 06:06:17 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 95E4D62171; Tue, 1 Dec 2026 06:06:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 099BD1F0089A; Tue, 1 Dec 2026 06:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796105176; bh=J2WkjFIKd5JPTdzgrgnIZoNu/kXWqYE1wleKpPslByY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=IwmzshzQ5zAcHOzOWq15JG7XUs+t/zcATNxfoqwLGJLdvTc7P2adm5o9/wTM9wOap dv8qB4YkpED4hNdn0IH9aUMllA92/NK5cnaps6VsYndyhvvIjTU/sfVwZFWxb8OnSF 0icdUSt8lO7IrTkFNwjidOSyeP878aF9Yv6dHuWbm4lnpJA+EfSYSTclPU64gTYYA5 h7+onuqwhKRGAwHixxJbES8SYTxXDnaFtvZG/rPxtgkDh8xEJwqiWAJ5U4ACW48pRh 3ceRLGUEWMSkibEuOyajc5nWi8fijJsVrNngR7GrI7a+ED/nxGrLSkJwp75fs4mGpi PusM8jfoQAXjg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check To: "Lin Huiyi" Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 06:06:15 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" 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: - [Medium] drm/amdgpu: flawed mgpu_info.num_gpu check in __check_local_vpod_integrity() -- commit 1d7eca73ed4f664c879aa6472e418261effb5a74 Author: Lin Huiyi drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check This commit adds a check on mgpu_info.num_gpu against AMDGPU_UALINK_LOCAL_ACCELS_MAX in __check_local_vpod_integrity() and limits the memcpy() length to the populated entries in local_accels[]. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm= /amd/amdgpu/amdgpu_ualink.c > index fa4c3d27d2720..f697dde5a0d4d 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > @@ -1162,6 +1162,17 @@ static int __check_local_vpod_integrity(struct amd= gpu_device *adev) > __set_bit(info->ppod.accel_id, local_accel_ids); > local_accels[n_local_accels++] =3D info->ppod.accel_id; > =20 > + /* > + * local_accels[] holds the local GPU itself plus one entry per peer, > + * so more GPUs than AMDGPU_UALINK_LOCAL_ACCELS_MAX cannot fit. > + */ > + if (unlikely(mgpu_info.num_gpu > AMDGPU_UALINK_LOCAL_ACCELS_MAX)) { > + dev_warn(adev->dev, > + "UALINK: integrity fail: too many local GPUs: %u (max %u)\n", > + mgpu_info.num_gpu, AMDGPU_UALINK_LOCAL_ACCELS_MAX); > + return -EINVAL; > + } > + > for (i =3D 0; i < mgpu_info.num_gpu; i++) { > peer_adev =3D mgpu_info.gpu_ins[i].adev; > if (peer_adev =3D=3D adev || !peer_adev->ualink.info) [Severity: Medium] Should the bounds check test n_local_accels against AMDGPU_UALINK_LOCAL_ACCELS_MAX inside the loop after filtering for vPod membership, instead of checking mgpu_info.num_gpu up front? mgpu_info.num_gpu counts all registered amdgpu instances in the system, whereas the loop skips non-UALink GPUs (!peer_adev->ualink.info) and GPUs in other vPods (!test_bit(accel_id, info->vpod.active_accel_bits)). Checking mgpu_info.num_gpu > AMDGPU_UALINK_LOCAL_ACCELS_MAX before filtering rejects valid vPods of 8 or fewer GPUs on systems that also have an integrated or non-UALink GPU, or that partition more than 8 local GPUs across multiple vPods. In addition, local_accels[0] is already populated with info->ppod.accel_id before the loop (n_local_accels =3D=3D 1). Allowing mgpu_info.num_gpu =3D= =3D 8 assumes adev itself is in mgpu_info.gpu_ins[] and will be skipped by peer_adev =3D=3D adev. However, amdgpu_unregister_gpu_instance() removes a= dev from mgpu_info.gpu_ins[] before interrupts are disabled in amdgpu_driver_unload_kms() and during reset in amdgpu_device_halt_activities(). If __check_local_vpod_integrity() runs from amdgpu_ualink_config_update_handler() while adev is not in mgpu_info.gpu_ins[] and 8 matching peers remain, n_local_accels reaches 9 and writes one element past the end of local_accels[] and peer_info->local_accels[]. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_90933440D34= FACA121875E13683CE1BC3309@qq.com?part=3D1