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 6387D606A32C for ; Wed, 2 Dec 2026 22:53:55 +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=g2hutv1g Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BDA1D10E12B; Wed, 2 Dec 2026 22:53:49 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 03C9A10E12B; Wed, 2 Dec 2026 22:53:44 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id E957761FAE; Wed, 2 Dec 2026 22:53:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B7D21F00897; Wed, 2 Dec 2026 22:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796252022; bh=qZY8E5GFsZIXDbZI4XLCbt1RUnGvb6mB9hokc/xcxJ0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=g2hutv1gXXQOddlGqeUQeCbtvU6Dqc5w6KjY7dLy1TsErr44DAo6pjHd/r17UpEm1 +X5H60/w2bBoCmPMCAa5gv5uIGmd09K7y5nrgpombp1MMVhMu6oxHUAVlu64TGhpu7 kUsfhkQsTSgLN/asqn+feqkQgTBgVcx4eyY8mqP+O3bQbbq2NxcB+dUAZs6nDI5ISF I5nkqFqjW1VCBvhi/1m4p5utlAUoa/q7lgN4Ikpofu2Zu31BzP4hW0g7rFXNky0asG g97wjIWYnKRtXxjw1MFBKl+WP1COWcxwbsINejc/NvRZJXyXM5+wGwd7YyGULiO8dX GoRoPFVgpdStg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/3] drm/amdgpu: fix IB content read in the devcoredump To: "Matt Turner" Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261202-amdgpu-devcoredump-fixes-v1-1-59f622a29769@gmail.com> References: <20261202-amdgpu-devcoredump-fixes-v1-0-59f622a29769@gmail.com> <20261202-amdgpu-devcoredump-fixes-v1-1-59f622a29769@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 22:53:42 +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: unaligned VRAM IB read in amdgpu_devcoredump_print_ibs() -- commit 14b3e312c2b66e1a7d6ed65ad219c71a4c22a7ca Author: Matt Turner drm/amdgpu: fix IB content read in the devcoredump This commit reworks IB content dumping in amdgpu_devcoredump_print_ibs() to validate mappings and BO resources, account for mapping->offset, read VRAM via amdgpu_device_vram_access(), and map non-VRAM pages into a local ttm_bo_kmap_obj. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/g= pu/drm/amd/amdgpu/amdgpu_dev_coredump.c > index 30a8b4c5591dd..0c6533b950f60 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c [ ... ] > @@ -271,6 +281,7 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, > } > =20 > for (int i =3D 0; i < coredump->num_ibs; i++) { > + u64 size =3D (u64)coredump->ibs[i].ib_size_dw * 4; > bool emit_content =3D false; > =20 > ib_content =3D kvmalloc_array(coredump->ibs[i].ib_size_dw, 4, > @@ -280,41 +291,55 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, > =20 > va_start =3D coredump->ibs[i].gpu_addr & AMDGPU_GMC_HOLE_MASK; > mapping =3D amdgpu_vm_bo_lookup_mapping(vm, va_start); > - if (!mapping) > + abo =3D amdgpu_devcoredump_mapping_bo(mapping); > + if (!abo || !abo->tbo.resource) > goto output_ib_content; > =20 > - abo =3D mapping->bo_va->base.bo; > - offset =3D va_start - mapping->start * AMDGPU_GPU_PAGE_SIZE; > + if (va_start + size > > + (mapping->last + 1) * AMDGPU_GPU_PAGE_SIZE) > + goto output_ib_content; > =20 > - if (abo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS) { > + offset =3D va_start - mapping->start * AMDGPU_GPU_PAGE_SIZE + > + mapping->offset; > + > + if (abo->tbo.resource->mem_type =3D=3D TTM_PL_VRAM) { > struct amdgpu_res_cursor cursor; > =20 > off =3D 0; > - > - if (abo->tbo.resource->mem_type !=3D TTM_PL_VRAM) > - goto output_ib_content; > - > - amdgpu_res_first(abo->tbo.resource, offset, > - coredump->ibs[i].ib_size_dw * 4, &cursor); > + amdgpu_res_first(abo->tbo.resource, offset, size, > + &cursor); > while (cursor.remaining) { > - amdgpu_device_mm_access(adev, cursor.start, > - &ib_content[off], cursor.size, > - false); > + amdgpu_device_vram_access(adev, cursor.start, > + &ib_content[off], > + cursor.size, false); > off +=3D cursor.size / 4; > amdgpu_res_next(&cursor, cursor.size); > } > emit_content =3D true; [Severity: Medium] Can an unaligned IB address cause amdgpu_devcoredump_print_ibs() to print uninitialized kernel memory from ib_content? amdgpu_cs_p2_ib() copies userspace's chunk_ib->va_start into ib->gpu_addr without checking 4-byte alignment. When va_start is not 4-byte aligned, offset, cursor.start, and cursor.size are unaligned as well. For CPU-invisible VRAM, amdgpu_device_vram_access() falls back to amdgpu_device_mm_access(), which aborts without writing to the buffer: drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:amdgpu_device_mm_access() { if (!drm_dev_enter(adev_to_drm(adev), &idx)) return; if (!IS_ALIGNED(pos, 4) || !IS_ALIGNED(size, 4)) { dev_err(adev->dev, "unaligned pos/size (pos=3D0x%llx, size=3D0x%zx)\n", pos, size); drm_dev_exit(idx); return; } Since ib_content is allocated without __GFP_ZERO and emit_content is set to true unconditionally, the devcoredump formats uninitialized memory. Even in CPU-visible VRAM, if an unaligned IB crosses a buddy block boundary, cursor.size on the first block is not a multiple of 4, so off +=3D cursor.size / 4 misaligns subsequent block reads and leaves the trailing bytes of ib_content unwritten. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202-amdgpu-dev= coredump-fixes-v1-0-59f622a29769@gmail.com?part=3D1