From: sashiko-bot@kernel.org
To: "Gou Hao" <gouhao@uniontech.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 4/4] RDMA/cxgb4: remove dead NULL checks after GFP_NOFAIL allocations
Date: Thu, 23 Jul 2026 08:35:51 +0000 [thread overview]
Message-ID: <20260723083552.774911F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723081813.176792-5-gouhao@uniontech.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Fallback error path and chunking in `_c4iw_write_mem_dma` and `write_adapter_mem` trigger a use-after-free on caller-provided SKBs.
- [High] Unconditional double-free of `mhp->dereg_skb` in the error path of `c4iw_alloc_mr`.
--
--- Patch [4]: [PATCH 4/4] RDMA/cxgb4: remove dead NULL checks after GFP_NOFAIL allocations ---
commit 2b81b1933eb1e926287199e29810f5bc991be785
Author: Gou Hao <gouhao@uniontech.com>
RDMA/cxgb4: remove dead NULL checks after GFP_NOFAIL allocations
alloc_skb() with the __GFP_NOFAIL flag will never return NULL,
so the subsequent NULL checks and error handling are unreachable
dead code. Remove them.
> diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
> index cd1b010141984..08631de17c0a3 100644
> --- a/drivers/infiniband/hw/cxgb4/mem.c
> +++ b/drivers/infiniband/hw/cxgb4/mem.c
> @@ -74,11 +74,8 @@ static int _c4iw_write_mem_dma_aligned(struct c4iw_rdev *rdev, u32 addr,
> c4iw_init_wr_wait(wr_waitp);
> wr_len = roundup(sizeof(*req) + sizeof(*sgl), 16);
>
> - if (!skb) {
> + if (!skb)
> skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
> - if (!skb)
> - return -ENOMEM;
> - }
> set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
[Severity: High]
This is a pre-existing issue, but I noticed a potential use-after-free
related to how these skb pointers are passed in from caller functions.
Looking at _c4iw_write_mem_dma(), the chunking loop reuses the caller's skb
for multiple offload sends:
drivers/infiniband/hw/cxgb4/mem.c:_c4iw_write_mem_dma() {
...
while (remain > inline_threshold) {
// ...
ret = _c4iw_write_mem_dma_aligned(rdev, addr, dmalen, daddr,
skb, remain ? NULL : wr_waitp);
// ...
}
if (remain)
ret = _c4iw_write_mem_inline(rdev, addr, remain, data, skb,
wr_waitp);
...
}
Since the first call to _c4iw_write_mem_dma_aligned() (or
_c4iw_write_mem_inline()) hands the skb to c4iw_ofld_send() which consumes it,
doesn't reusing this same skb pointer in subsequent loop iterations or the
remainder fallback trigger a use-after-free?
Similarly, in write_adapter_mem(), the fallback logic reuses the skb pointer
after _c4iw_write_mem_dma() has potentially consumed it during a failed
offload send:
drivers/infiniband/hw/cxgb4/mem.c:write_adapter_mem() {
...
ret = _c4iw_write_mem_dma(rdev, addr, len, data, skb, wr_waitp);
if (ret) {
pr_warn_ratelimited("%s: dma map failure (non fatal)\n",
pci_name(rdev->lldi.pdev));
ret = _c4iw_write_mem_inline(rdev, addr, len, data, skb,
wr_waitp);
}
...
}
Could this fallback also result in a use-after-free if the skb was consumed
before the error was returned?
>
> req = __skb_put_zero(skb, wr_len);
[ ... ]
> @@ -134,11 +131,8 @@ static int _c4iw_write_mem_inline(struct c4iw_rdev *rdev, u32 addr, u32 len,
> roundup(copy_len, T4_ULPTX_MIN_IO),
> 16);
>
> - if (!skb) {
> + if (!skb)
> skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
> - if (!skb)
> - return -ENOMEM;
> - }
[Severity: High]
This is also a pre-existing issue, but there appears to be a double-free
involving dereg_skb in the error path of c4iw_alloc_mr().
When finish_mem_reg() fails, it jumps to err_dereg_mem and calls dereg_mem()
with mhp->dereg_skb. This eventually passes the skb to c4iw_ofld_send()
which takes ownership of the skb.
drivers/infiniband/hw/cxgb4/mem.c:c4iw_alloc_mr() {
...
err_dereg_mem:
dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp);
err_free_skb:
kfree_skb(mhp->dereg_skb);
...
}
After dereg_mem() returns, the error path unconditionally calls kfree_skb()
on mhp->dereg_skb.
Does this unconditionally double-free the skb after it has already been handed
off to the network stack?
> set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
>
> req = __skb_put_zero(skb, wr_len);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723081813.176792-1-gouhao@uniontech.com?part=4
prev parent reply other threads:[~2026-07-23 8:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 8:18 [PATCH 0/4] remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
2026-07-23 8:18 ` [PATCH 1/4] powerpc/xive: remove dead NULL check after GFP_NOFAIL allocation Gou Hao
2026-07-23 8:28 ` sashiko-bot
2026-07-23 9:37 ` Mukesh Kumar Chaurasiya
2026-07-23 10:26 ` Gou Hao
2026-07-23 8:18 ` [PATCH 2/4] drm: remove dead WARN_ON " Gou Hao
2026-07-23 8:18 ` [PATCH 3/4] lib/test_hmm: remove dead NULL checks after GFP_NOFAIL allocations Gou Hao
2026-07-23 8:29 ` sashiko-bot
2026-07-23 8:18 ` [PATCH 4/4] RDMA/cxgb4: " Gou Hao
2026-07-23 8:35 ` 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=20260723083552.774911F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gouhao@uniontech.com \
--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.