Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexander Martyniuk" <alexevgmart@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH 5.10] RDMA/hfi1: shut down the trap timer before unregistering
Date: Tue, 01 Dec 2026 15:11:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-243557@kernel.org> (raw)
In-Reply-To: <20261201150054.510414-1-alexevgmart@gmail.com>

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

      reply	other threads:[~2026-12-01 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=sashiko-outbox-243557@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexevgmart@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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