From: "Chen, Xiaogang" <xiaogang.chen@amd.com>
To: Jiang Liu <gerry@linux.alibaba.com>,
amd-gfx@lists.freedesktop.org, lijo.lazar@amd.com,
Kent.Russell@amd.com, shuox.liu@linux.alibaba.com
Subject: Re: [PATCH v2 4/6] amdgpu: fix use after free bug related to amdgpu_driver_release_kms()
Date: Tue, 7 Jan 2025 16:55:10 -0600 [thread overview]
Message-ID: <9e73447e-520f-4caf-bedf-a8be36105bad@amd.com> (raw)
In-Reply-To: <d097f02c25ff44fced59b10ac72587f304a6637f.1736044362.git.gerry@linux.alibaba.com>
[-- Attachment #1: Type: text/plain, Size: 3649 bytes --]
On 1/4/2025 8:45 PM, Jiang Liu wrote:
> If some GPU device failed to probe, `rmmod amdgpu` will trigger a use
> after free bug related to amdgpu_driver_release_kms() as:
> 2024-12-26 16:17:45 [16002.085540] BUG: kernel NULL pointer dereference, address: 0000000000000000
> 2024-12-26 16:17:45 [16002.093792] #PF: supervisor read access in kernel mode
> 2024-12-26 16:17:45 [16002.099993] #PF: error_code(0x0000) - not-present page
> 2024-12-26 16:17:45 [16002.106188] PGD 0 P4D 0
> 2024-12-26 16:17:45 [16002.109464] Oops: Oops: 0000 [#1] PREEMPT SMP NOPTI
> 2024-12-26 16:17:45 [16002.115372] CPU: 2 PID: 14375 Comm: rmmod Kdump: loaded Tainted: G W E 6.10.0+ #2
> 2024-12-26 16:17:45 [16002.125577] Hardware name: Alibaba Alibaba Cloud ECS/Alibaba Cloud ECS, BIOS 3.0.ES.AL.P.087.05 04/07/2024
> 2024-12-26 16:17:45 [16002.136858] RIP: 0010:drm_sched_fini+0x3f/0xe0 [gpu_sched]
> 2024-12-26 16:17:45 [16002.143463] Code: 60 c6 87 be 00 00 00 01 e8 ce e0 90 d8 48 8d bb 80 00 00 00 e8 c2 e0 90 d8 8b 43 20 85 c0 74 51 45 31 e4 48 8b
> 43 28 4d 63 ec <4a> 8b 2c e8 48 89 ef e8 f5 0e 59 d9 48 8b 45 10 48 8d 55 10 48 39
> 2024-12-26 16:17:45 [16002.164992] RSP: 0018:ffffb570dbbb7da8 EFLAGS: 00010246
> 2024-12-26 16:17:45 [16002.171316] RAX: 0000000000000000 RBX: ffff96b0fdadc878 RCX: 0000000000000000
> 2024-12-26 16:17:46 [16002.179784] RDX: 000fffffffe00000 RSI: 0000000000000000 RDI: ffff96b0fdadc8f8
> 2024-12-26 16:17:46 [16002.188252] RBP: ffff96b0fdadc800 R08: ffff97abbd035040 R09: ffffffff9ac52540
> 2024-12-26 16:17:46 [16002.196722] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> 2024-12-26 16:17:46 [16002.205179] R13: 0000000000000000 R14: ffff96b0fdadfc00 R15: 0000000000000000
> 2024-12-26 16:17:46 [16002.213648] FS: 00007f2737000740(0000) GS:ffff97abbd100000(0000) knlGS:0000000000000000
> 2024-12-26 16:17:46 [16002.223189] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> 2024-12-26 16:17:46 [16002.230103] CR2: 0000000000000000 CR3: 000000011be3a005 CR4: 0000000000f70ef0
> 2024-12-26 16:17:46 [16002.238581] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> 2024-12-26 16:17:46 [16002.247053] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400
> e024se+0x3c/0x90 [amdxcp]
> 2024-12-26 16:17:46 [16002.337645] __do_sys_delete_module.constprop.0+0x176/0x310
> 2024-12-26 16:17:46 [16002.344324] do_syscall_64+0x5d/0x170
> 2024-12-26 16:17:46 [16002.348858] entry_SYSCALL_64_after_hwframe+0x76/0x7e
> 2024-12-26 16:17:46 [16002.354956] RIP: 0033:0x7f2736a620cb-12-26
>
> Fix it by unplugging xcp drm devices when failed to probe GPU devices.
>
> Signed-off-by: Jiang Liu<gerry@linux.alibaba.com>
> Tested-by: Shuo Liu<shuox.liu@linux.alibaba.com>
> Reviewed-by: Lijo Lazar<lijo.lazar@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index d2a046736edd..9ebc0d47d1cb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -165,8 +165,10 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
> DRM_WARN("smart shift update failed\n");
>
> out:
> - if (r)
> + if (r) {
> + amdgpu_xcp_dev_unplug(adev);
You have made amdgpu_xcp_drm_dev_free, why still use
amdgpu_xcp_dev_unplug here? I think you want undo
amdgpu_xcp_drm_dev_alloc in error path. Why involve adev device unplug?
It is a different scenario.
Regards
Xiaogang
> amdgpu_driver_unload_kms(dev);
> + }
>
> return r;
> }
[-- Attachment #2: Type: text/html, Size: 4618 bytes --]
next prev parent reply other threads:[~2025-01-07 22:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-05 2:45 [PATCH v2 0/6] Fix several bugs in error handling during device probe Jiang Liu
2025-01-05 2:45 ` [PATCH v2 1/6] amdgpu: fix possible resource leakage in kfd_cleanup_nodes() Jiang Liu
2025-01-05 5:22 ` Shuo Liu
2025-01-05 6:57 ` Gerry Liu
2025-01-06 3:07 ` Gerry Liu
2025-01-07 22:53 ` Chen, Xiaogang
2025-01-08 2:29 ` Gerry Liu
2025-01-05 2:45 ` [PATCH v2 2/6] amdgpu: clear adev->in_suspend flag when fails to suspend Jiang Liu
2025-01-05 2:45 ` [PATCH v2 3/6] drm/amdxcp: introduce new API amdgpu_xcp_drm_dev_free() Jiang Liu
2025-01-06 6:51 ` Lazar, Lijo
2025-01-07 2:00 ` Gerry Liu
2025-01-05 2:45 ` [PATCH v2 4/6] amdgpu: fix use after free bug related to amdgpu_driver_release_kms() Jiang Liu
2025-01-05 5:16 ` Shuo Liu
2025-01-07 22:55 ` Chen, Xiaogang [this message]
2025-01-08 3:34 ` Gerry Liu
2025-01-05 2:45 ` [PATCH v2 5/6] amdgpu: fix invalid memory access in amdgpu_fence_driver_sw_fini() Jiang Liu
2025-01-07 22:55 ` Chen, Xiaogang
2025-01-05 2:45 ` [PATCH v2 6/6] amdgpu: get rid of false warnings caused by amdgpu_irq_put() Jiang Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e73447e-520f-4caf-bedf-a8be36105bad@amd.com \
--to=xiaogang.chen@amd.com \
--cc=Kent.Russell@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=gerry@linux.alibaba.com \
--cc=lijo.lazar@amd.com \
--cc=shuox.liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox