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 45261606A699 for ; Tue, 1 Dec 2026 08:39:53 +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=Ol77kc5e Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D3C610F64E; Tue, 1 Dec 2026 08:39:47 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0B26210F64C; Tue, 1 Dec 2026 08:39:41 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 0ACC960E03; Tue, 1 Dec 2026 08:39:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB151F000C1; Tue, 1 Dec 2026 08:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796114379; bh=6EUPeLXbXSodboYZDq4fpBvjB1dSOj8GTVkaTViJxUw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Ol77kc5eREyuNW2y3AHME5nKHEfO3BoQGvOthWYkpCxYox+woW4OHOpHgFi1Su0pE 6yubuY3QLjG8T5Mr/TBeqP+CvWoowDXYWPJAxAh7TCkTHP6gXWV1Uc4BfOJIqGQHYr cdOo6EysPsy8gslDyzlmse+Yfid2e0MG6b3KkfWxqDPQ7iHqAZSGFP+Xo+VWiVnY61 wn3QKNeqQfDoQpBwNzcFuOujyxA7MUQIK2nUA9dwv90lgg5TuSY4PS/1qiTHp5vh1i DFFqIs3XCFNVK0XSId7/v7W+HHw/30LLuQGx2rYrGjp3ItY6qTNgznYdWjFkTWsKT9 7LpIsJ2BGARNw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5] 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 08:39:39 +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=unavailable 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 5534f8d736ae8e09c0ee2bd1e6fbe48b3f50a027 Author: Lin Huiyi drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check This commit bounds-checks mgpu_info.num_gpu against AMDGPU_UALINK_LOCAL_ACCELS_MAX in __check_local_vpod_integrity() and limits the peer_info->local_accels memcpy() to the populated entries. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm= /amd/amdgpu/amdgpu_ualink.c > index fa4c3d27d2720..c0016e8815e93 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > @@ -1162,6 +1162,18 @@ 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. > + * The platform never exposes more than AMDGPU_UALINK_LOCAL_ACCELS_MAX > + * local GPUs, so reject a configuration that 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] Can this still overflow local_accels[] and peer_info->local_accels[] by one element, while also rejecting valid vPods when other AMD GPUs are registere= d? adev is placed in local_accels[0] before the loop, so n_local_accels stays within mgpu_info.num_gpu only when one of the entries in mgpu_info.gpu_ins[] is adev itself and gets skipped by peer_adev =3D=3D adev. During GPU reset, amdgpu_device_halt_activities() calls amdgpu_unregister_gpu_instance(adev), and soc_v1_0_mode2_restore_ip() resumes the IH ring before soc_v1_0_mode2_restore_hwcontext() re-registers adev (or leaves it unregistered if a later restore step fails). If __check_local_vpod_integri= ty() runs while adev is absent from mgpu_info.gpu_ins[] and mgpu_info.num_gpu is AMDGPU_UALINK_LOCAL_ACCELS_MAX, the loop does not skip adev and can append all AMDGPU_UALINK_LOCAL_ACCELS_MAX peers after local_accels[0], writing one entry past the end of local_accels[] and peer_info->local_accels[]. Conversely, mgpu_info.num_gpu counts all registered amdgpu devices on the host, including non-UALink GPUs (!peer_adev->ualink.info) and GPUs in other vPods, so checking mgpu_info.num_gpu rejects a valid vPod of up to AMDGPU_UALINK_LOCAL_ACCELS_MAX accelerators whenever another AMD GPU is present. Checking n_local_accels >=3D AMDGPU_UALINK_LOCAL_ACCELS_MAX before appending each matching vPod peer in the loop would avoid both issues. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_B6D678900EA= F7134FB708499EF1A13E93608@qq.com?part=3D1