Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH 5.10] RDMA/hfi1: shut down the trap timer before unregistering
@ 2026-12-01 15:00 Alexander Martyniuk
  2026-12-01 15:11 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Martyniuk @ 2026-12-01 15:00 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: Alexander Martyniuk, lvc-project, Mike Marciniszyn,
	Dennis Dalessandro, Doug Ledford, Jason Gunthorpe,
	Michael N. Henry, Michael J. Ruhl, linux-rdma, linux-kernel,
	Hongyan Xu, Leon Romanovsky

From: Hongyan Xu <getshell@seu.edu.cn>

commit a1c9d476c2316685f85fffb6450ad88d01836357 upstream.

MAD processing arms a trap timer embedded in each hfi1_ibport. Device
unregistration does not stop the timer, so its callback can run after
the port and its containing hfi1_devdata have been released.

Shut down every port timer before unregistering the IB device. The
shutdown form also prevents a concurrent path from rearming the timer.

Fixes: bf90aadd630c ("IB/hfi1: Send MAD traps until repressed")
Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
Link: https://patch.msgid.link/20260928134151.1213-1-getshell@seu.edu.cn
Signed-off-by: Leon Romanovsky <leon@kernel.org>
[Alexander: del_timer_sync() used instead of the timer_shutdown_sync()]
Signed-off-by: Alexander Martyniuk <alexevgmart@gmail.com>
---
Backport fix for CVE-2026-139571
 drivers/infiniband/hw/hfi1/verbs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
index 693922df3543..06cb57da73b2 100644
--- a/drivers/infiniband/hw/hfi1/verbs.c
+++ b/drivers/infiniband/hw/hfi1/verbs.c
@@ -1950,6 +1950,10 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
 void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
 {
 	struct hfi1_ibdev *dev = &dd->verbs_dev;
+	int i;
+
+	for (i = 0; i < dd->num_pports; i++)
+		del_timer_sync(&dd->pport[i].ibport_data.rvp.trap_timer);
 
 	hfi1_verbs_unregister_sysfs(dd);
 
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 5.10] RDMA/hfi1: shut down the trap timer before unregistering
  2026-12-01 15:00 [PATCH 5.10] RDMA/hfi1: shut down the trap timer before unregistering Alexander Martyniuk
@ 2026-12-01 15:11 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 15:11 UTC (permalink / raw)
  To: Alexander Martyniuk; +Cc: linux-rdma

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] RDMA/hfi1: del_timer_sync() in hfi1_unregister_ib_device()
  allows timer rearm
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] IB/hfi1: use-after-free in hfi1_register_ib_device() [1]
--

commit 9089d1fc596021ec5bdbfe05b339211369afcf37
Author: Hongyan Xu <getshell@seu.edu.cn>

RDMA/hfi1: shut down the trap timer before unregistering

This backport stops each port's rvp.trap_timer with del_timer_sync() at
the start of hfi1_unregister_ib_device().

Link: https://patch.msgid.link/20260928134151.1213-1-getshell@seu.edu.cn

> diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
> index 693922df3543b..40695c001ed96 100644
> --- a/drivers/infiniband/hw/hfi1/verbs.c
> +++ b/drivers/infiniband/hw/hfi1/verbs.c
> @@ -1950,6 +1950,10 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
>  void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
>  {
>  	struct hfi1_ibdev *dev = &dd->verbs_dev;
> +	int i;
> +
> +	for (i = 0; i < dd->num_pports; i++)
> +		del_timer_sync(&dd->pport[i].ibport_data.rvp.trap_timer);
>  
>  	hfi1_verbs_unregister_sysfs(dd);

[Severity: High]
Can rvp.trap_timer still be re-armed after del_timer_sync() runs at the
start of hfi1_unregister_ib_device()?

In the upstream commit, timer_shutdown_sync() clears timer->function so
later mod_timer() calls become no-ops.  Replacing it with del_timer_sync()
at the same point in the function leaves rvp.send_agent and the port link
active while hfi1_verbs_unregister_sysfs() and rvt_unregister_device() run
(rvp.send_agent is only cleared inside rvt_unregister_device() ->
rvt_free_mad_agents(), and shutdown_device() disables link and receive
interrupts after hfi1_unregister_ib_device() returns):

CPU0                                  CPU1
remove_one()
  hfi1_unregister_ib_device()
    del_timer_sync(&...trap_timer)
                                      hfi1_bad_pkey()
                                        send_trap()
                                          check_and_add_trap()
                                            mod_timer(&...trap_timer, ...)
    hfi1_verbs_unregister_sysfs()
    rvt_unregister_device()
  ...
  postinit_cleanup()
    hfi1_free_devdata(dd)
                                      <softirq>
                                        hfi1_handle_trap_timer()
                                          spin_lock_irqsave(&ibp->rvp.lock)
                                            <-- use-after-free

In addition, the commit message still states that the shutdown form
prevents a concurrent path from re-arming the timer.

[Severity: Critical]
This problem wasn't introduced by this patch, but can the error unwind
path in hfi1_register_ib_device() leave rvp.trap_timer and dev->mem_timer
armed [1] after failure?

hfi1_register_ib_device() sets up each port's rvp.trap_timer via
init_ibport() and initializes dev->mem_timer before calling
rvt_register_device() and hfi1_verbs_register_sysfs():

drivers/infiniband/hw/hfi1/verbs.c:hfi1_register_ib_device() {
    ...
	ret = rvt_register_device(&dd->verbs_dev.rdi);
	if (ret)
		goto err_verbs_txreq;

	ret = hfi1_verbs_register_sysfs(dd);
	if (ret)
		goto err_class;

	return ret;

err_class:
	rvt_unregister_device(&dd->verbs_dev.rdi);
err_verbs_txreq:
	verbs_txreq_exit(dev);
	dd_dev_err(dd, "cannot register verbs: %d!\n", -ret);
	return ret;
}

If hfi1_verbs_register_sysfs() fails after the device has been exposed by
rvt_register_device(), neither trap_timer nor dev->mem_timer is cancelled
before the caller unwinds and frees hfi1_devdata, leading to a
use-after-free when either timer expires.

[1] https://sashiko.dev/#/bug/linux-a172e3e9-8e63-4881-a07f-6c919cc2c0fa

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201150054.510414-1-alexevgmart@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 15:00 [PATCH 5.10] RDMA/hfi1: shut down the trap timer before unregistering Alexander Martyniuk
2026-12-01 15:11 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox