From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: ntb@lists.linux.dev
Subject: Re: [PATCH 11/11] NTB: ntb_transport: Drain RX tasklets during link cleanup
Date: Mon, 07 Sep 2026 14:50:42 +0000 [thread overview]
Message-ID: <20260907145043.762E71F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907142429.951930-12-den@valinux.co.jp>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] In-flight RX DMA transfers are not drained during link cleanup before freeing Memory Window (MW) buffers, leading to DMA Use-After-Free, Read-After-Free, and potential information leaks.
--
commit 0ffb444fbfb867ed6e5c68ad186229e763417ba5
Author: Koichiro Den <den@valinux.co.jp>
NTB: ntb_transport: Drain RX tasklets during link cleanup
This commit modifies the queue pair link cleanup process to explicitly drain
and kill the receive tasklet. It temporarily disables the queue pair link
work to prevent concurrent reactivations while resetting the queue pair.
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -969,11 +969,16 @@ static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp)
>
> dev_info(&pdev->dev, "qp %d: Link Cleanup\n", qp->qp_num);
>
> - cancel_delayed_work_sync(&qp->link_work);
> + disable_delayed_work_sync(&qp->link_work);
> + ntb_transport_set_qp_active(qp, false);
> + tasklet_kill(&qp->rxc_db_work);
[Severity: High]
This isn't a bug introduced by this patch, but while we are draining the
tasklet here, does this code still leave in-flight RX DMA transfers active
when the memory window is subsequently freed?
When a link down event occurs, ntb_transport_link_cleanup() calls
ntb_qp_link_cleanup(), which now successfully kills the rxc_db_work tasklet.
However, it does not appear to wait for or terminate pending DMA transfers on
qp->rx_dma_chan. After this function returns, ntb_transport_link_cleanup()
proceeds to call ntb_free_mw(), which returns the physical memory to the
system via dma_free_attrs().
If the hardware DMA engine is executing asynchronously, couldn't it
continue reading from or writing to this freed physical memory, potentially
causing a DMA use-after-free or data leak?
Furthermore, when the DMA asynchronous transfer completes, the
ntb_rx_copy_callback() function could be invoked:
ntb_rx_copy_callback() {
...
offset = qp->rx_buff + qp->rx_max_frame * qp->rx_index;
...
}
Since ntb_free_mw() sets qp->rx_buff to NULL, could this result in a NULL
pointer dereference? Additionally, on success, ntb_complete_rxc() attempts
to write to entry->rx_hdr, which points into the now-freed memory window,
which could cause a software use-after-free.
Is it possible we also need to drain or explicitly terminate the DMA channel
transfers before resetting the link context and returning?
> +
> ntb_qp_link_down_reset(qp);
>
> if (qp->event_handler)
> qp->event_handler(qp->cb_data, qp->link_is_up);
> +
> + enable_delayed_work(&qp->link_work);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907142429.951930-1-den@valinux.co.jp?part=11
prev parent reply other threads:[~2026-09-07 14:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 14:24 [PATCH 00/11] NTB: ntb_transport: Miscellaneous fixes Koichiro Den
2026-09-07 14:24 ` [PATCH 01/11] NTB: ntb_transport: Remove the device debugfs directory Koichiro Den
2026-09-07 14:36 ` sashiko-bot
2026-09-07 14:24 ` [PATCH 02/11] NTB: ntb_transport: Start TX offload thread after queue setup Koichiro Den
2026-09-07 14:37 ` sashiko-bot
2026-09-07 14:24 ` [PATCH 03/11] NTB: ntb_transport: Prepare remote RX info accesses for MW teardown Koichiro Den
2026-09-07 14:38 ` sashiko-bot
2026-09-07 14:24 ` [PATCH 04/11] NTB: ntb_transport: Clear QP pointers when freeing an MW Koichiro Den
2026-09-07 14:42 ` sashiko-bot
2026-09-09 4:57 ` Koichiro Den
2026-09-07 14:24 ` [PATCH 05/11] NTB: ntb_transport: Avoid deadlock when cancelling link work Koichiro Den
2026-09-07 14:45 ` sashiko-bot
2026-09-07 14:24 ` [PATCH 06/11] NTB: ntb_transport: Publish link state after QP setup Koichiro Den
2026-09-07 14:47 ` sashiko-bot
2026-09-09 4:42 ` Koichiro Den
2026-09-07 14:24 ` [PATCH 07/11] NTB: ntb_transport: Clear link state before QP cleanup Koichiro Den
2026-09-07 14:43 ` sashiko-bot
2026-09-09 4:47 ` Koichiro Den
2026-09-07 14:24 ` [PATCH 08/11] NTB: ntb_transport: Abort link setup on QP MW allocation failure Koichiro Den
2026-09-07 14:45 ` sashiko-bot
2026-09-07 14:24 ` [PATCH 09/11] NTB: ntb_transport: Stop QP work before freeing a queue Koichiro Den
2026-09-07 14:50 ` sashiko-bot
2026-09-07 14:24 ` [PATCH 10/11] NTB: ntb_transport: Stop RX tasklet scheduling " Koichiro Den
2026-09-07 14:24 ` [PATCH 11/11] NTB: ntb_transport: Drain RX tasklets during link cleanup Koichiro Den
2026-09-07 14:50 ` 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=20260907145043.762E71F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=den@valinux.co.jp \
--cc=ntb@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.