Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D5926334C3D for ; Mon, 24 Aug 2026 23:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787615445; cv=none; b=ah5lXZO8u/2Uz8+pjzXX3whaHjru2IwoNfWQqwWX3ddFtORVSk/nTqAGugqShbOtv8n0ramNYWcI7jCzh2xYzGoktVhp/qpxhaqdprtKJQkZdCWd32QKAeNkoXi86XVIOJ0iaBkWErvAJ1Ra60gMI47Ibf88z22mVDOWzs6lv38= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787615445; c=relaxed/simple; bh=S+kF/Qs7mW0Q8LB9IaWea8vwI57ANaMMhLsCn860+Ck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CNUMXxq221NH/oYy7Y0uJPwmvw2RaVDFEeMBLVDQ3T1lUPmMewSjYN2EN4UXfZGMdD2YnQSYjNuaK3X0Rv0AwXtxZLyAtZ1gYVQjiuOg1bPISX/0ureLttyIza6foUOshfDUsBB8R1GjqyDSUSX/5gjk2noS7mXKzZy2By2+xqA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P14KqDa3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P14KqDa3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33D031F00A3A; Mon, 24 Aug 2026 23:50:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787615443; bh=nAFULoBrsHk6XOw8YgNkjPgDegUggFsSx9Wt8rPppIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P14KqDa3iIlxtuLismDSbZZbw7YuSJYYgvRA3OhzBIIfuAkDRtt7x/tmDXy/VQ45d k5B6XpCl882uKerkvikYcRVutUel/vDcerEkVj7Uqy15Y2TbhSVg5pLFGod7OsmfiJ DjJWXdL0sqeTt30hh8CMB7MAXnq2Tkn5ie7PAsWIChZ9p6oFbi6xh8HTq4b8FVm9L2 G9Bgvro2Nc9i9s8DPvmm27VvgmnttDSrcSmGG2npjNQw/QA+3bCPyNgaLRRDRhwwvp 47oa/0cy1jDUc3XghG72SIGTxW71FKHo8bzl8mAIX44orzy/3E0Xdrv7hTMHGpanEW ycaMBnIbGTYrA== From: Sasha Levin To: stable@vger.kernel.org Cc: "Matthieu Baerts (NGI0)" , Mat Martineau , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1.y 2/3] mptcp: pm: ADD_ADDR rtx: free sk if last Date: Mon, 24 Aug 2026 19:50:39 -0400 Message-ID: <20260824235040.730038-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260824235040.730038-1-sashal@kernel.org> References: <2026082025-sitter-talisman-7358@gregkh> <20260824235040.730038-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Matthieu Baerts (NGI0)" [ Upstream commit b7b9a461569734d33d3259d58d2507adfac107ed ] 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) Link: https://patch.msgid.link/20260505-net-mptcp-pm-fixes-7-1-rc3-v1-5-fca8091060a4@kernel.org Signed-off-by: Jakub Kicinski Stable-dep-of: a7aad5b69d3b ("mptcp: pm: fix data race in add_addr timer callback") Signed-off-by: Sasha Levin --- net/mptcp/pm_netlink.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 9f20c789cde53..495ec8e584035 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -28,6 +28,7 @@ struct mptcp_pm_add_entry { struct timer_list add_timer; struct mptcp_sock *sock; u8 retrans_times; + bool timer_done; struct rcu_head rcu; }; @@ -305,22 +306,22 @@ static void mptcp_pm_add_timer(struct timer_list *timer) struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer); struct mptcp_sock *msk = entry->sock; struct sock *sk = (struct sock *)msk; - unsigned int timeout; + unsigned int timeout = 0; pr_debug("msk=%p\n", msk); + bh_lock_sock(sk); if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE)) - goto exit; + goto out; - bh_lock_sock(sk); if (sock_owned_by_user(sk)) { /* Try again later. */ - sk_reset_timer(sk, timer, jiffies + HZ / 20); + timeout = HZ / 20; goto out; } if (mptcp_pm_should_add_signal_addr(msk)) { - sk_reset_timer(sk, timer, jiffies + HZ); + timeout = HZ; goto out; } @@ -343,9 +344,8 @@ static void mptcp_pm_add_timer(struct timer_list *timer) entry->retrans_times++; } - if (entry->retrans_times < ADD_ADDR_RETRANS_MAX) - sk_reset_timer(sk, timer, - jiffies + timeout); + if (entry->retrans_times >= ADD_ADDR_RETRANS_MAX) + timeout = 0; spin_unlock_bh(&msk->pm.lock); @@ -353,9 +353,13 @@ static void mptcp_pm_add_timer(struct timer_list *timer) mptcp_pm_subflow_established(msk); 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 = true; bh_unlock_sock(sk); -exit: - __sock_put(sk); + sock_put(sk); } struct mptcp_pm_add_entry * @@ -423,6 +427,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0); reset_timer: + add_entry->timer_done = false; timeout = mptcp_get_add_addr_timeout(net); if (timeout) sk_reset_timer(sk, &add_entry->add_timer, jiffies + timeout); @@ -443,7 +448,8 @@ void mptcp_pm_free_anno_list(struct mptcp_sock *msk) spin_unlock_bh(&msk->pm.lock); 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); } } -- 2.53.0