From nobody Wed Jun 24 19:23:23 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E2DF39B952; Tue, 5 May 2026 15:01:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777993299; cv=none; b=ZWmKXC+0e4BxbctOR5iQrz0FC0i3mcH4twAk38NAaOChJhw4fXM+ymtpu1s3o5+xxGlIfQJ57oYdFCGTEuyFeX0tTU2P9oAdEZbbTBnNji+sYnyuuuG+r9B64r/EaJbgJuWwvwWVZehSAuNBM/90QiloKaW9+Tl63A/KDOIZ4qQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777993299; c=relaxed/simple; bh=O2/nglzrTC4QlrYsuJQMIVGAnjK+kDOV3GAZgDGe7ik=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KG1UKxuYvipmBxpENGhQvU9bFsZ/TSQI976qxQzi0uA+MRfE5qjBMtc5JaWJVFFipstgetOIHXA/DGPJazHbX+2oZJc3ycjK0NTpXXiwmsLBf15U3QgY7buI/cn47MQsWzSUNSVqkNabkL3+xhK87QCxWfDyTJCZgoNI230ij44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TN9f7RGM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TN9f7RGM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7DA5C2BCF4; Tue, 5 May 2026 15:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777993298; bh=O2/nglzrTC4QlrYsuJQMIVGAnjK+kDOV3GAZgDGe7ik=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TN9f7RGM+8GkHyVGzYX5Vjv5N2DsyfHpjyZpQ90mrB/LEEhkqe0jLGiTr9JGtUlTX BMaSMJ6qwjpCpsmB2G/UFuue5COUiTfBnX/FQvPHBMD1YLEHSfuampaMT9vooG1RcY TS6D+hMT3pbCR7JHupX3q+AIMiaffYWuPzlGcCnOnv5KQ1yQkkC2nmRKTI2KZCLO5d B0I9sa2b522NrfpMAnxY6KTy+MjmuSk5j0lCtmDFIM49BEigu0B52MwYOkMl/0jMpF 0vuDf74GAydlaVqim3rqDvv+UC+i6F5Vlx1TlV+GYZSjmY1fF0r3E2zcBCV8Y7rRya S4z+Mch2lEyNw== From: "Matthieu Baerts (NGI0)" Date: Tue, 05 May 2026 17:00:53 +0200 Subject: [PATCH net 05/11] mptcp: pm: ADD_ADDR rtx: free sk if last Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260505-net-mptcp-pm-fixes-7-1-rc3-v1-5-fca8091060a4@kernel.org> References: <20260505-net-mptcp-pm-fixes-7-1-rc3-v1-0-fca8091060a4@kernel.org> In-Reply-To: <20260505-net-mptcp-pm-fixes-7-1-rc3-v1-0-fca8091060a4@kernel.org> To: Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Christoph Paasch Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , stable@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3439; i=matttbe@kernel.org; h=from:subject:message-id; bh=O2/nglzrTC4QlrYsuJQMIVGAnjK+kDOV3GAZgDGe7ik=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJ/sdnJfrCzrHDjPu40NfR+o1t36dsH13hOBEe8j7eP3 b8+RsKpo5SFQYyLQVZMkUW6LTJ/5vMq3hIvPwuYOaxMIEMYuDgFYCLylYwMlwy8hDauWbZk7saK B/WZP9mt1wSt3nVvzS73wFVfPc7MiWP4p7T+9UXnVU/iNvutaFc9tIJhoWjfgnOFs7uzj1RdX/B clAkA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 When an ADD_ADDR is retransmitted, the sk is held in sk_reset_timer(), and released at the end. If at that moment, it was the last reference being held, the sk would not be freed. sock_put() should then be called instead of __sock_put(). But that's not enough: if it is the last reference, sock_put() will call sk_free(), which will end up calling sk_stop_timer_sync() on the same timer, and waiting indefinitely to finish. So it is needed to mark that the timer is done at the end of the timer handler when it has not been rescheduled, not to call sk_stop_timer_sync() on "itself". Fixes: 00cfd77b9063 ("mptcp: retransmit ADD_ADDR when timeout") Cc: stable@vger.kernel.org Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 2a01bf1b5bfd..8899327e59a1 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -16,6 +16,7 @@ struct mptcp_pm_add_entry { struct list_head list; struct mptcp_addr_info addr; u8 retrans_times; + bool timer_done; struct timer_list add_timer; struct mptcp_sock *sock; struct rcu_head rcu; @@ -327,22 +328,22 @@ static void mptcp_pm_add_timer(struct timer_list *tim= er) add_timer); struct mptcp_sock *msk =3D entry->sock; struct sock *sk =3D (struct sock *)msk; - unsigned int timeout; + unsigned int timeout =3D 0; =20 pr_debug("msk=3D%p\n", msk); =20 - if (unlikely(inet_sk_state_load(sk) =3D=3D TCP_CLOSE)) - goto exit; - bh_lock_sock(sk); + if (unlikely(inet_sk_state_load(sk) =3D=3D TCP_CLOSE)) + goto out; + if (sock_owned_by_user(sk)) { /* Try again later. */ - sk_reset_timer(sk, timer, jiffies + HZ / 20); + timeout =3D HZ / 20; goto out; } =20 if (mptcp_pm_should_add_signal_addr(msk)) { - sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX / 8); + timeout =3D TCP_RTO_MAX / 8; goto out; } =20 @@ -360,8 +361,9 @@ static void mptcp_pm_add_timer(struct timer_list *timer) } =20 if (entry->retrans_times < ADD_ADDR_RETRANS_MAX) - sk_reset_timer(sk, timer, - jiffies + (timeout << entry->retrans_times)); + timeout <<=3D entry->retrans_times; + else + timeout =3D 0; =20 spin_unlock_bh(&msk->pm.lock); =20 @@ -369,9 +371,13 @@ static void mptcp_pm_add_timer(struct timer_list *time= r) mptcp_pm_subflow_established(msk); =20 out: + if (timeout) + sk_reset_timer(sk, timer, jiffies + timeout); + else + /* if sock_put calls sk_free: avoid waiting for this timer */ + entry->timer_done =3D true; bh_unlock_sock(sk); -exit: - __sock_put(sk); + sock_put(sk); } =20 struct mptcp_pm_add_entry * @@ -434,6 +440,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, =20 timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0); reset_timer: + add_entry->timer_done =3D false; timeout =3D mptcp_adjust_add_addr_timeout(msk); if (timeout) sk_reset_timer(sk, &add_entry->add_timer, jiffies + timeout); @@ -454,7 +461,8 @@ static void mptcp_pm_free_anno_list(struct mptcp_sock *= msk) spin_unlock_bh(&msk->pm.lock); =20 list_for_each_entry_safe(entry, tmp, &free_list, list) { - sk_stop_timer_sync(sk, &entry->add_timer); + if (!entry->timer_done) + sk_stop_timer_sync(sk, &entry->add_timer); kfree_rcu(entry, rcu); } } --=20 2.53.0