Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jaeyeong Lee" <lee@jaeyeong.cc>, linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/qedr: prevent listener teardown from racing MPA requests
Date: Sun, 29 Nov 2026 03:00:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-239286@kernel.org> (raw)
In-Reply-To: <179583482032.4059708.5194029012702478533@jaeyeong.cc>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Critical] qed: list corruption in qed_iwarp_ll2_comp_syn_pkt() via
  qed_iwarp_return_ep()
- [High] qed: sleep in atomic and tasklet deadlock in
  qed_iwarp_mpa_received()
- [High] qed: dangling listener in ep->cb_context after
  qed_iwarp_mpa_received()
- [High] RDMA/qedr: deferred cm_id deref in qedr_iw_destroy_listen()
  breaks teardown
--

commit 620c4b74ad2840cfcbf4876ab5ebe8f2f0193736
Author: Jaeyeong Lee <lee@jaeyeong.cc>

RDMA/qedr: prevent listener teardown from racing MPA requests

This commit tracks pending passive iWARP endpoints against their listener
under iw_lock and defers qed and qedr listener freeing with RCU so
listener destruction does not race with incoming MPA requests.

> diff --git a/drivers/infiniband/hw/qedr/qedr_iw_cm.c b/drivers/infiniband/hw/qedr/qedr_iw_cm.c
> index 8d38e74f1b127..322929144fbc4 100644
> --- a/drivers/infiniband/hw/qedr/qedr_iw_cm.c
> +++ b/drivers/infiniband/hw/qedr/qedr_iw_cm.c
> @@ -719,6 +719,15 @@ int qedr_iw_create_listen(struct iw_cm_id *cm_id, int backlog)
>  	return rc;
>  }
>  
> +static void qedr_iw_free_listener(struct rcu_head *rcu)
> +{
> +	struct qedr_iw_listener *listener;
> +
> +	listener = container_of(rcu, struct qedr_iw_listener, rcu);
> +	listener->cm_id->rem_ref(listener->cm_id);
> +	kfree(listener);
> +}
> +
>  int qedr_iw_destroy_listen(struct iw_cm_id *cm_id)
>  {
>  	struct qedr_iw_listener *listener = cm_id->provider_data;
> @@ -729,8 +738,7 @@ int qedr_iw_destroy_listen(struct iw_cm_id *cm_id)
>  		rc = dev->ops->iwarp_destroy_listen(dev->rdma_ctx,
>  						    listener->qed_handle);
>  
> -	cm_id->rem_ref(cm_id);
> -	kfree(listener);
> +	call_rcu(&listener->rcu, qedr_iw_free_listener);
>  	return rc;
>  }

[Severity: High]
Does deferring cm_id->rem_ref() to call_rcu() break iw_destroy_cm_id()
teardown?

drivers/infiniband/core/iwcm.c:iw_destroy_cm_id() {
	destroy_cm_id(cm_id);
	if (refcount_read(&cm_id_priv->refcount) > 1)
		flush_workqueue(iwcm_wq);
	iwcm_deref_id(cm_id_priv);
}

Because qedr_iw_destroy_listen() returns before qedr_iw_free_listener()
drops the provider reference on cm_id, refcount_read(&cm_id_priv->refcount)
is always greater than 1.  As a result, destroying a listener from inside
a connection-request callback running on iwcm_wq will unconditionally hit
flush_workqueue(iwcm_wq) and self-deadlock on the ordered workqueue.

In addition, because qedr_iw_destroy_listen() does not wait for an
in-flight qed_iwarp_mpa_received() RCU reader that already claimed
ep->listener, that reader can call listener->cm_id->event_handler() after
destroy_cm_id() sets IWCM_F_DROP_EVENTS; cm_work_handler() then drops the
IW_CM_EVENT_CONNECT_REQUEST without freeing the allocated qedr_iw_ep or
private_data and without rejecting the lower-level qed_iwarp_ep.  Finally,
qedr_exit_module() has no rcu_barrier() to wait for pending
qedr_iw_free_listener() callbacks before module unload.

> diff --git a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
> index 4d1ce9b1a3f2e..c064e0509de96 100644
> --- a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
> +++ b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c
[ ... ]
> @@ -812,7 +821,28 @@ qed_iwarp_mpa_received(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
>  	params.status = 0;
>  
>  	ep->state = QED_IWARP_EP_MPA_REQ_RCVD;
> +
> +	rcu_read_lock();
> +	spin_lock_bh(&iwarp_info->iw_lock);
> +	listener = ep->listener;
> +	ep->listener = NULL;
> +	if (listener) {
> +		ep->event_cb = listener->event_cb;
> +		ep->cb_context = listener->cb_context;
> +	}
> +	spin_unlock_bh(&iwarp_info->iw_lock);

[Severity: High]
Does clearing ep->listener while storing listener->cb_context in
ep->cb_context leave a dangling struct qedr_iw_listener pointer on the
endpoint after rcu_read_unlock()?

CPU0 (<softirq>)                  CPU1
qed_iwarp_mpa_received()
  ep->listener = NULL
  ep->event_cb =
    qedr_iw_event_handler
  ep->cb_context = qedr_listener
  ep->event_cb(...)
  rcu_read_unlock()
                                  qedr_iw_destroy_listen()
                                    qed_iwarp_destroy_listen()
                                      /* skips ep: ep->listener == NULL */
                                    call_rcu(..., qedr_iw_free_listener)
                                  ...
                                  qedr_iw_free_listener()
                                    kfree(qedr_listener)
qed_iwarp_exception_received()
  ep->event_cb(ep->cb_context, ...)
    qedr_iw_event_handler()
      ep->dev                     <-- use-after-free

ep->cb_context is not replaced with a struct qedr_iw_ep pointer until
qed_iwarp_accept() or qed_iwarp_reject() runs asynchronously on iwcm_wq.
If the listener is destroyed in that window (or if the connect request
event is dropped) and an async firmware event such as
IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED arrives on the connection,
qedr_iw_event_handler() casts the freed struct qedr_iw_listener pointer in
ep->cb_context to struct qedr_iw_ep and dereferences it.

> +
> +	if (!listener) {
> +		rcu_read_unlock();
> +		ep->cm_info.private_data_len = 0;
> +		if (qed_iwarp_mpa_offload(p_hwfn, ep))
> +			DP_NOTICE(p_hwfn,
> +				  "Failed to reject connection for closed listener\n");
> +		return;
> +	}

[Severity: High]
Can qed_iwarp_mpa_offload() be called for a passive endpoint from
qed_iwarp_mpa_received()?

qed_iwarp_mpa_received() runs inside the p_hwfn->sp_dpc slowpath EQ
tasklet (qed_int_sp_dpc() -> qed_eq_completion() ->
qed_async_event_completion() -> qed_iwarp_async_event() ->
qed_iwarp_connect_complete()).  For a passive endpoint
(ep->connect_mode == TCP_CONNECT_PASSIVE), qed_iwarp_mpa_offload() selects
QED_SPQ_MODE_EBLOCK and calls qed_spq_post() -> qed_spq_block(), which
waits for a slowpath completion EQE that can only be processed by the very
same sp_dpc tasklet and falls back to msleep(SPQ_BLOCK_SLEEP_MS) in softirq
atomic context until the ramrod times out and triggers
QED_HW_ERR_RAMROD_FAIL.

When qed_iwarp_mpa_offload() fails, ep is also left on iwarp_info->ep_list,
leaking ep and its tcp_cid, and unlike qed_iwarp_reject() this path does
not call qed_iwarp_mpa_v2_set_private() to populate the 4-byte MPAv2
header in out_pdata.

[ ... ]

> @@ -2421,17 +2454,21 @@ qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
>  	}
>  
>  	DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n");
> -	/* There may be an open ep on this connection if this is a syn
> -	 * retrasnmit... need to make sure there isn't...
> -	 */
> -	if (qed_iwarp_ep_exists(p_hwfn, &cm_info))
> -		goto err;
> -
>  	ep = qed_iwarp_get_free_ep(p_hwfn);
>  	if (!ep)
>  		goto err;
>  
>  	spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
> +	listener = qed_iwarp_get_listener(p_hwfn, &cm_info);
> +	if (!listener || qed_iwarp_ep_exists(p_hwfn, &cm_info)) {
> +		spin_unlock_bh(&p_hwfn->p_hwfn->p_rdma_info->iwarp.iw_lock);
> +		qed_iwarp_return_ep(p_hwfn, ep);
> +		goto err;
> +	}

[Severity: Critical]
Does calling qed_iwarp_return_ep() here corrupt ep->list_entry and crash on
a retransmitted SYN or concurrent listener teardown?

qed_iwarp_get_free_ep() pops ep from ep_free_list with
list_del(&ep->list_entry), leaving ep->list_entry poisoned because it has
not yet been added to ep_list.  qed_iwarp_return_ep() then calls
list_move_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_free_list),
which runs __list_del_entry() on the already deleted and poisoned
ep->list_entry.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179583482032.4059708.5194029012702478533@jaeyeong.cc?part=1

      parent reply	other threads:[~2026-11-29  3:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  3:00 [PATCH] RDMA/qedr: prevent listener teardown from racing MPA requests Jaeyeong Lee
2026-11-28  3:03 ` netdev-bot+sinfo
2026-11-29  3:00 ` 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-239286@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lee@jaeyeong.cc \
    --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