2023-11-17 07:07:07

by Shifeng Li

[permalink] [raw]
Subject: [PATCH] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info()

When removing the irdma driver or unplugging its aux device, the ccq
queue is released before destorying the cqp_cmpl_wq queue.
But in the window, there may still be completion events for wqes. That
will cause a UAF in irdma_sc_ccq_get_cqe_info().

[34693.333191] BUG: KASAN: use-after-free in irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
[34693.333194] Read of size 8 at addr ffff889097f80818 by task kworker/u67:1/26327
[34693.333194]
[34693.333199] CPU: 9 PID: 26327 Comm: kworker/u67:1 Kdump: loaded Tainted: G O --------- -t - 4.18.0 #1
[34693.333200] Hardware name: SANGFOR Inspur/NULL, BIOS 4.1.13 08/01/2016
[34693.333211] Workqueue: cqp_cmpl_wq cqp_compl_worker [irdma]
[34693.333213] Call Trace:
[34693.333220] dump_stack+0x71/0xab
[34693.333226] print_address_description+0x6b/0x290
[34693.333238] ? irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
[34693.333240] kasan_report+0x14a/0x2b0
[34693.333251] irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
[34693.333264] ? irdma_free_cqp_request+0x151/0x1e0 [irdma]
[34693.333274] irdma_cqp_ce_handler+0x1fb/0x3b0 [irdma]
[34693.333285] ? irdma_ctrl_init_hw+0x2c20/0x2c20 [irdma]
[34693.333290] ? __schedule+0x836/0x1570
[34693.333293] ? strscpy+0x83/0x180
[34693.333296] process_one_work+0x56a/0x11f0
[34693.333298] worker_thread+0x8f/0xf40
[34693.333301] ? __kthread_parkme+0x78/0xf0
[34693.333303] ? rescuer_thread+0xc50/0xc50
[34693.333305] kthread+0x2a0/0x390
[34693.333308] ? kthread_destroy_worker+0x90/0x90
[34693.333310] ret_from_fork+0x1f/0x40

Signed-off-by: Shifeng Li <[email protected]>
---
drivers/infiniband/hw/irdma/hw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
index ab246447520b..de7337a6a874 100644
--- a/drivers/infiniband/hw/irdma/hw.c
+++ b/drivers/infiniband/hw/irdma/hw.c
@@ -570,8 +570,6 @@ static void irdma_destroy_cqp(struct irdma_pci_f *rf, bool free_hwcqp)
struct irdma_cqp *cqp = &rf->cqp;
int status = 0;

- if (rf->cqp_cmpl_wq)
- destroy_workqueue(rf->cqp_cmpl_wq);
if (free_hwcqp)
status = irdma_sc_cqp_destroy(dev->cqp);
if (status)
@@ -737,6 +735,8 @@ static void irdma_destroy_ccq(struct irdma_pci_f *rf)
struct irdma_ccq *ccq = &rf->ccq;
int status = 0;

+ if (rf->cqp_cmpl_wq)
+ destroy_workqueue(rf->cqp_cmpl_wq);
if (!rf->reset)
status = irdma_sc_ccq_destroy(dev->ccq, 0, true);
if (status)
--
2.25.1


2023-11-17 17:38:13

by Shiraz Saleem

[permalink] [raw]
Subject: RE: [PATCH] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info()

> Subject: [PATCH] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info()
>
> When removing the irdma driver or unplugging its aux device, the ccq queue is
> released before destorying the cqp_cmpl_wq queue.
> But in the window, there may still be completion events for wqes. That will cause a
> UAF in irdma_sc_ccq_get_cqe_info().
>
> [34693.333191] BUG: KASAN: use-after-free in
> irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma] [34693.333194] Read of size 8
> at addr ffff889097f80818 by task kworker/u67:1/26327 [34693.333194]
> [34693.333199] CPU: 9 PID: 26327 Comm: kworker/u67:1 Kdump: loaded
> Tainted: G O --------- -t - 4.18.0 #1
> [34693.333200] Hardware name: SANGFOR Inspur/NULL, BIOS 4.1.13
> 08/01/2016 [34693.333211] Workqueue: cqp_cmpl_wq cqp_compl_worker
> [irdma] [34693.333213] Call Trace:
> [34693.333220] dump_stack+0x71/0xab
> [34693.333226] print_address_description+0x6b/0x290
> [34693.333238] ? irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
> [34693.333240] kasan_report+0x14a/0x2b0 [34693.333251]
> irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma] [34693.333264] ?
> irdma_free_cqp_request+0x151/0x1e0 [irdma] [34693.333274]
> irdma_cqp_ce_handler+0x1fb/0x3b0 [irdma] [34693.333285] ?
> irdma_ctrl_init_hw+0x2c20/0x2c20 [irdma] [34693.333290] ?
> __schedule+0x836/0x1570 [34693.333293] ? strscpy+0x83/0x180
> [34693.333296] process_one_work+0x56a/0x11f0 [34693.333298]
> worker_thread+0x8f/0xf40 [34693.333301] ? __kthread_parkme+0x78/0xf0
> [34693.333303] ? rescuer_thread+0xc50/0xc50 [34693.333305]
> kthread+0x2a0/0x390 [34693.333308] ? kthread_destroy_worker+0x90/0x90
> [34693.333310] ret_from_fork+0x1f/0x40
>
> Signed-off-by: Shifeng Li <[email protected]>
> ---
> drivers/infiniband/hw/irdma/hw.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
> index ab246447520b..de7337a6a874 100644
> --- a/drivers/infiniband/hw/irdma/hw.c
> +++ b/drivers/infiniband/hw/irdma/hw.c
> @@ -570,8 +570,6 @@ static void irdma_destroy_cqp(struct irdma_pci_f *rf,
> bool free_hwcqp)
> struct irdma_cqp *cqp = &rf->cqp;
> int status = 0;
>
> - if (rf->cqp_cmpl_wq)
> - destroy_workqueue(rf->cqp_cmpl_wq);
> if (free_hwcqp)
> status = irdma_sc_cqp_destroy(dev->cqp);
> if (status)
> @@ -737,6 +735,8 @@ static void irdma_destroy_ccq(struct irdma_pci_f *rf)
> struct irdma_ccq *ccq = &rf->ccq;
> int status = 0;
>
> + if (rf->cqp_cmpl_wq)
> + destroy_workqueue(rf->cqp_cmpl_wq);
> if (!rf->reset)
> status = irdma_sc_ccq_destroy(dev->ccq, 0, true);
> if (status)
> --
> 2.25.1

Looks good. Thanks!

Acked-by: Shiraz Saleem <[email protected]>

2023-11-19 13:13:24

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info()

On Thu, Nov 16, 2023 at 10:50:43PM -0800, Shifeng Li wrote:
> When removing the irdma driver or unplugging its aux device, the ccq
> queue is released before destorying the cqp_cmpl_wq queue.
> But in the window, there may still be completion events for wqes. That
> will cause a UAF in irdma_sc_ccq_get_cqe_info().
>
> [34693.333191] BUG: KASAN: use-after-free in irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
> [34693.333194] Read of size 8 at addr ffff889097f80818 by task kworker/u67:1/26327
> [34693.333194]
> [34693.333199] CPU: 9 PID: 26327 Comm: kworker/u67:1 Kdump: loaded Tainted: G O --------- -t - 4.18.0 #1
> [34693.333200] Hardware name: SANGFOR Inspur/NULL, BIOS 4.1.13 08/01/2016
> [34693.333211] Workqueue: cqp_cmpl_wq cqp_compl_worker [irdma]
> [34693.333213] Call Trace:
> [34693.333220] dump_stack+0x71/0xab
> [34693.333226] print_address_description+0x6b/0x290
> [34693.333238] ? irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
> [34693.333240] kasan_report+0x14a/0x2b0
> [34693.333251] irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
> [34693.333264] ? irdma_free_cqp_request+0x151/0x1e0 [irdma]
> [34693.333274] irdma_cqp_ce_handler+0x1fb/0x3b0 [irdma]
> [34693.333285] ? irdma_ctrl_init_hw+0x2c20/0x2c20 [irdma]
> [34693.333290] ? __schedule+0x836/0x1570
> [34693.333293] ? strscpy+0x83/0x180
> [34693.333296] process_one_work+0x56a/0x11f0
> [34693.333298] worker_thread+0x8f/0xf40
> [34693.333301] ? __kthread_parkme+0x78/0xf0
> [34693.333303] ? rescuer_thread+0xc50/0xc50
> [34693.333305] kthread+0x2a0/0x390
> [34693.333308] ? kthread_destroy_worker+0x90/0x90
> [34693.333310] ret_from_fork+0x1f/0x40
>
> Signed-off-by: Shifeng Li <[email protected]>
> ---
> drivers/infiniband/hw/irdma/hw.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

Please add Fixes line and resubmit together with Shiraz's Acked-by,

Thanks

2023-11-20 02:59:40

by Shifeng Li

[permalink] [raw]
Subject: Re: [PATCH] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info()

在 2023/11/19 21:13, Leon Romanovsky 写道:
> On Thu, Nov 16, 2023 at 10:50:43PM -0800, Shifeng Li wrote:
>> When removing the irdma driver or unplugging its aux device, the ccq
>> queue is released before destorying the cqp_cmpl_wq queue.
>> But in the window, there may still be completion events for wqes. That
>> will cause a UAF in irdma_sc_ccq_get_cqe_info().
>>
>> [34693.333191] BUG: KASAN: use-after-free in irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
>> [34693.333194] Read of size 8 at addr ffff889097f80818 by task kworker/u67:1/26327
>> [34693.333194]
>> [34693.333199] CPU: 9 PID: 26327 Comm: kworker/u67:1 Kdump: loaded Tainted: G O --------- -t - 4.18.0 #1
>> [34693.333200] Hardware name: SANGFOR Inspur/NULL, BIOS 4.1.13 08/01/2016
>> [34693.333211] Workqueue: cqp_cmpl_wq cqp_compl_worker [irdma]
>> [34693.333213] Call Trace:
>> [34693.333220] dump_stack+0x71/0xab
>> [34693.333226] print_address_description+0x6b/0x290
>> [34693.333238] ? irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
>> [34693.333240] kasan_report+0x14a/0x2b0
>> [34693.333251] irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma]
>> [34693.333264] ? irdma_free_cqp_request+0x151/0x1e0 [irdma]
>> [34693.333274] irdma_cqp_ce_handler+0x1fb/0x3b0 [irdma]
>> [34693.333285] ? irdma_ctrl_init_hw+0x2c20/0x2c20 [irdma]
>> [34693.333290] ? __schedule+0x836/0x1570
>> [34693.333293] ? strscpy+0x83/0x180
>> [34693.333296] process_one_work+0x56a/0x11f0
>> [34693.333298] worker_thread+0x8f/0xf40
>> [34693.333301] ? __kthread_parkme+0x78/0xf0
>> [34693.333303] ? rescuer_thread+0xc50/0xc50
>> [34693.333305] kthread+0x2a0/0x390
>> [34693.333308] ? kthread_destroy_worker+0x90/0x90
>> [34693.333310] ret_from_fork+0x1f/0x40
>>
>> Signed-off-by: Shifeng Li <[email protected]>
>> ---
>> drivers/infiniband/hw/irdma/hw.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Please add Fixes line and resubmit together with Shiraz's Acked-by,
>

I have sent the v2 patch,

Thanks

> Thanks