Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrew Stellman" <bugs@stellman-greene.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback
Date: Sat, 28 Nov 2026 14:21:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-238765@kernel.org> (raw)
In-Reply-To: <20261128140843.59029-1-bugs@stellman-greene.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] RDMA/siw: race with siw_cm_work_handler() in
  siw_rtr_data_ready()
--

commit 79aa7e62cc4f0bc3e76b32bcd12993ddd9a6d3e4
Author: Andrew Stellman <astellman@stellman-greene.com>

RDMA/siw: Fix NULL dereference when disconnect races the RTR callback

This commit inlines the QP socket callback assignment in
siw_rtr_data_ready() under sk->sk_callback_lock after verifying that
sk_to_cep(sk) == cep and cep->qp == qp.

> diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
> index ed49818793dde..8612db3cc94e8 100644
> --- a/drivers/infiniband/sw/siw/siw_cm.c
> +++ b/drivers/infiniband/sw/siw/siw_cm.c
> @@ -181,8 +181,15 @@ static void siw_rtr_data_ready(struct sock *sk)
>  		siw_cm_upcall(cep, IW_CM_EVENT_ESTABLISHED, 0);
>  out:
>  	read_unlock(&sk->sk_callback_lock);
> -	if (qp)
> -		siw_qp_socket_assoc(cep, qp);
> +	if (qp) {
> +		write_lock_bh(&sk->sk_callback_lock);
> +		if (sk_to_cep(sk) == cep && cep->qp == qp) {
> +			qp->attrs.sk = cep->sock;
> +			sk->sk_data_ready = siw_qp_llp_data_ready;
> +			sk->sk_write_space = siw_qp_llp_write_space;
> +		}
> +		write_unlock_bh(&sk->sk_callback_lock);
> +	}
>  }

[Severity: High]
Can this race with siw_cm_work_handler() to leave a dangling socket pointer
in qp->attrs.sk or write to a freed qp?

If the incoming RTR frame is malformed and siw_tcp_rx_data() calls
siw_qp_cm_drop(qp, 1), qp->rx_stream.rx_suspend is set and
SIW_CM_WORK_CLOSE_LLP is queued on siw_cm_wq, yet siw_rtr_data_ready() still
falls through to the if (qp) block after dropping sk_callback_lock.

In siw_cm_work_handler(), the release_cep path closes the QP and drops the
CEP's QP reference before disassociating the socket under sk_callback_lock:

drivers/infiniband/sw/siw/siw_cm.c:siw_cm_work_handler() {
    ...
		if (cep->qp) {
			struct siw_qp *qp = cep->qp;
    ...
			siw_qp_llp_close(qp);
			siw_qp_put(qp);

			siw_cep_set_inuse(cep);
			cep->qp = NULL;
			siw_qp_put(qp);
		}
		if (s) {
			siw_socket_disassoc(s);
			sock_release(s);
		}
    ...
}

This allows the following interleaving:

<softirq>                         kworker
siw_rtr_data_ready()
  tcp_read_sock()
    ...
      siw_qp_cm_drop(qp, 1)
  read_unlock(&sk_callback_lock)
                                  siw_cm_work_handler()
                                    siw_qp_llp_close(qp)
                                      down_write(&qp->state_lock)
                                      qp->attrs.sk = NULL
                                      up_write(&qp->state_lock)
  write_lock_bh(&sk_callback_lock)
  if (sk_to_cep(sk) == cep &&
      cep->qp == qp)
                                    cep->qp = NULL
                                    siw_qp_put(qp)
    qp->attrs.sk = cep->sock
  write_unlock_bh(&sk_callback_lock)
                                    siw_socket_disassoc(s)
                                    sock_release(s)  <-- qp->attrs.sk dangles

Because siw_rtr_data_ready() sets qp->attrs.sk without holding
qp->state_lock, it overwrites the NULL written by siw_qp_llp_close() right
before sock_release(s) frees the socket.  Also, because cep->qp is cleared
and siw_qp_put(qp) is called without holding sk_callback_lock, the last QP
reference can drop right after cep->qp == qp is checked, making the write to
qp->attrs.sk a use-after-free if siw_destroy_qp() is waiting on qp->qp_free.

Note that siw_accept() already sets qp->attrs.sk = cep->sock via
siw_qp_modify() before installing the RTR callbacks.  Skipping the callback
reassignment when qp->rx_stream.rx_suspend is set, and disassociating the
socket in siw_cm_work_handler() before closing and releasing cep->qp (as
siw_qp_cm_drop() does in its immediate path), would avoid both races.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128140843.59029-1-bugs@stellman-greene.com?part=1

      reply	other threads:[~2026-11-28 14:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 14:08 [PATCH rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback Andrew Stellman
2026-11-28 14:21 ` 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-238765@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bugs@stellman-greene.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