All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: linux-pci@vger.kernel.org, ntb@lists.linux.dev
Subject: Re: [PATCH 10/11] NTB: ntb_transport: Use atomic MW translation groups
Date: Mon, 03 Aug 2026 18:40:21 +0000	[thread overview]
Message-ID: <20260803184022.4C9871F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260803180439.1963864-11-den@valinux.co.jp>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing work cancellation in probe error path leads to Use-After-Free.
--

--- Patch [10]: [PATCH 10/11] NTB: ntb_transport: Use atomic MW translation groups ---
commit 92a31c981341f2c994839699e7b4fa179c125291
Author: Koichiro Den <den@valinux.co.jp>

NTB: ntb_transport: Use atomic MW translation groups

This commit modifies the ntb_transport driver to allocate and program MWs
in a translation group as one contiguous unit. It queries each group,
allocates its backing once, and uses group set and clear operations.

> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index f59f926d4bfaa..2c7728898890c 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c

[ ... ]

> @@ -1291,6 +1366,22 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
>  
>  	max_mw_count_for_spads = (spad_count - MW0_SZ_HIGH) / 2;
>  	nt->mw_count = min(mw_count, max_mw_count_for_spads);
> +	if (nt->mw_count) {
> +		rc = ntb_mw_get_trans_group(ndev, PIDX, nt->mw_count - 1,
> +					    &group_first, &group_count);
> +		if (rc)
> +			goto err;
> +
> +		if (group_first < 0 || group_count <= 0 ||
> +		    (unsigned int)group_first >= nt->mw_count ||
> +		    (unsigned int)group_count !=
> +		    nt->mw_count - (unsigned int)group_first) {
> +			dev_err(&ndev->dev,
> +				"Scratchpad limit splits an MW translation group\n");
> +			rc = -EOPNOTSUPP;
> +			goto err;
> +		}
> +	}
>  
>  	nt->msi_spad_offset = nt->mw_count * 2 + MW0_SZ_HIGH;
>  

[Severity: High]
This is a pre-existing issue, but does the probe error path need to cancel
link_work?

Looking at ntb_transport_probe(), ntb_set_ctx() registers device callbacks:

    rc = ntb_set_ctx(ndev, nt, &ntb_transport_ops);
    if (rc)
        goto err2;

    INIT_LIST_HEAD(&nt->client_devs);
    rc = ntb_bus_init(nt);
    if (rc)
        goto err3;

If an interrupt fires immediately after ntb_set_ctx() registers the
callbacks, the link_event callback could queue nt->link_work on the system
workqueue.

If ntb_bus_init() subsequently fails, the error path jumps to err3 and
frees the context without explicitly canceling the work via
cancel_delayed_work_sync():

err3:
    ntb_clear_ctx(ndev);
err2:
    kfree(nt->qp_vec);
err1:
    while (i--) {
        mw = &nt->mw_vec[i];
        iounmap(mw->vbase);
    }
    kfree(nt->mw_vec);
err:
    kfree(nt);

Could this leave link_work queued on freed memory, leading to a
use-after-free when the work queue executes it?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803180439.1963864-1-den@valinux.co.jp?part=10

  reply	other threads:[~2026-08-03 18:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 18:04 [PATCH 00/11] PCI/NTB: endpoint: packed vNTB memory windows Koichiro Den
2026-08-03 18:04 ` [PATCH 01/11] NTB: Add atomic MW translation group operations Koichiro Den
2026-08-03 18:10   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 02/11] NTB: epf: Parse a versioned packed MW layout Koichiro Den
2026-08-03 18:23   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 03/11] PCI: endpoint: pci-epf-vntb: Add packed MW layout handling Koichiro Den
2026-08-03 18:25   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 04/11] PCI: endpoint: pci-epf-vntb: Implement MW group translation callbacks Koichiro Den
2026-08-03 18:25   ` sashiko-bot
2026-08-04  1:41     ` Koichiro Den
2026-08-03 18:04 ` [PATCH 05/11] PCI: endpoint: pci-epf-vntb: Allocate packed outbound MW space Koichiro Den
2026-08-03 18:32   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 06/11] PCI: endpoint: pci-epf-vntb: Add outbound MW group commands Koichiro Den
2026-08-03 18:28   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 07/11] NTB: epf: Implement MW group translation callbacks Koichiro Den
2026-08-03 18:29   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 08/11] NTB: perf: Reject grouped memory windows Koichiro Den
2026-08-03 18:25   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 09/11] NTB/msi: Require a singleton memory window Koichiro Den
2026-08-03 18:23   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 10/11] NTB: ntb_transport: Use atomic MW translation groups Koichiro Den
2026-08-03 18:40   ` sashiko-bot [this message]
2026-08-03 18:04 ` [PATCH 11/11] PCI: endpoint: pci-epf-vntb: Expose packed MWs through configfs Koichiro Den
2026-08-03 18:40   ` sashiko-bot
2026-08-03 23:00 ` [PATCH 00/11] PCI/NTB: endpoint: packed vNTB memory windows Randy Dunlap
2026-08-04  0:55   ` Koichiro Den

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=20260803184022.4C9871F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=den@valinux.co.jp \
    --cc=linux-pci@vger.kernel.org \
    --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.