Netdev List
 help / color / mirror / Atom feed
From: Hidayathulla Khan I <hidayath@linux.ibm.com>
To: Breno Leitao <leitao@debian.org>
Cc: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com,
	sidraya@linux.ibm.com, mjambigi@linux.ibm.com,
	andrew+netdev@lunn.ch, tonylu@linux.alibaba.com,
	guwen@linux.alibaba.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, pasic@linux.ibm.com,
	linux-s390@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net] net/smc: fix socket refcount leak in smc_switch_conns()
Date: Tue, 4 Aug 2026 20:27:19 +0530	[thread overview]
Message-ID: <af5f206a-1fde-4f55-b506-c37cf168ee19@linux.ibm.com> (raw)
In-Reply-To: <anGqEX1JOYlTczQ6@gmail.com>


On 04/08/26 2:36 pm, Breno Leitao wrote:
> On Tue, Aug 04, 2026 at 10:28:00AM +0200, Hidayath Khan wrote:
>> smc_switch_conns() takes a reference on the SMC socket before dropping
>> lgr->conns_lock, so the connection stays alive while the CDC slot is
>> fetched:
>>
>>          sock_hold(&smc->sk);
>>          read_unlock_bh(&lgr->conns_lock);
>>          /* pre-fetch buffer outside of send_lock, might sleep */
>>          rc = smc_cdc_get_free_slot(conn, to_lnk, &wr_buf, NULL, &pend);
>>          if (rc)
>>                  goto err_out;
>>
>> The err_out label only drops the wr_tx link reference, so this early exit
>> returns without the matching sock_put().  The second error exit is not
>> affected because sock_put() has already run by then:
>>
>>          rc = smc_switch_cursor(smc, pend, wr_buf);
>>          spin_unlock_bh(&conn->send_lock);
>>          sock_put(&smc->sk);
>>          if (rc)
>>                  goto err_out;
>>
>> A leaked sk_refcnt means the smc_sock is never destroyed.  Its send and
>> receive buffers stay allocated, and for a user socket the reference held
>> on the network namespace is never released, so the netns can no longer be
>> torn down.
>>
>> smc_cdc_get_free_slot() fails when the target link goes down or when the
>> connection has been killed while the switch is in progress.  Both are
>> reachable during the link failover this function implements, so the leak
>> is triggered by the same hardware events that make smc_switch_conns() run
>> in the first place.
>>
>> Drop the reference on the early error path.
>>
>> Fixes: 95f7f3e7dc6b ("net/smc: improved fix wait on already cleared link")
>> Cc: stable@vger.kernel.org
>> Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
>> Signed-off-by: Hidayath Khan <hidayath@linux.ibm.com>
> Reviewed-by: Breno Leitao <leitao@debian.org>
>
>> ---
>>   net/smc/smc_core.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
>> index b4208cb186c5..c0027d2fe4e8 100644
>> --- a/net/smc/smc_core.c
>> +++ b/net/smc/smc_core.c
>> @@ -1148,8 +1148,10 @@ struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
>>   		read_unlock_bh(&lgr->conns_lock);
>>   		/* pre-fetch buffer outside of send_lock, might sleep */
>>   		rc = smc_cdc_get_free_slot(conn, to_lnk, &wr_buf, NULL, &pend);
> Do you need sock_hold(smc->sk) to call smc_cdc_get_free_slot ? Otherwise
> you can move the sock_hold() after the exit.

Thanks for the review.

Yes.  conns_lock is what pins the socket. The reference is taken in
smc_lgr_register_conn() and dropped in __smc_lgr_unregister_conn(), both
under that lock.  After read_unlock_bh() a concurrent close can free it,
and smc_cdc_get_free_slot() reads conn->killed after a sleeping
wait_event_interruptible_timeout().  Moving the hold later would turn the
leak into a use-after-free.


      reply	other threads:[~2026-08-04 14:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  8:28 [PATCH net] net/smc: fix socket refcount leak in smc_switch_conns() Hidayath Khan
2026-08-04  9:06 ` Breno Leitao
2026-08-04 14:57   ` Hidayathulla Khan I [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=af5f206a-1fde-4f55-b506-c37cf168ee19@linux.ibm.com \
    --to=hidayath@linux.ibm.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=edumazet@google.com \
    --cc=guwen@linux.alibaba.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjambigi@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=sidraya@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    /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