From mboxrd@z Thu Jan 1 00:00:00 1970 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 5A72A47278D for ; Fri, 7 Aug 2026 11:48:19 +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=1786103308; cv=none; b=UV72avJZuvGWGhf2YDzll1QJBwUrKK1JWl0HO4saCBsUOgBCbuZ3MPB2VsvXPjLym1U5LkWCnpy3FHcwUx/wFN/IDoVn2PEIvJSElrhFsWDE3ZofG/y17m0oM7ydT/nsB8aQwhceZD5z83pQUYixa/J3hD3p7yVovO+Cdy3WZT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786103308; c=relaxed/simple; bh=gk1cL/Wi5UXWqyABBvm1IjE6GW5Rosmr8RyG75Ap9IY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KwOX141nu3QwExxI5xPQ3catKYHLCEoN5LN2+RIga/2xEohHMYUOGMsTuRYK6cdV4LHDm6uDtDWHU5nAvDDFQPlVTa6mwqmaUKwQ+Wjz/RzmwQGfGEaRZlRgx363jzEb5vsHiPf1iS2Ijj/fvN6dziEr4D+Bn1M9inc9PGGp2Yo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E2K2ihsB; 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="E2K2ihsB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C84A91F00ACF; Fri, 7 Aug 2026 11:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786103298; bh=uUMMNCnf8i33mVUUzW0WHXlFPPT8nMCxi6orsl5f4Vo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E2K2ihsBuxLGSgKGUL+RFJWYrdeJqJJaqknGUOv88La2x/mjd77kpboi1elWLHTQS 3H0/qIE+vbruX62mzF1WX5+qlx0CWUDgvH9WnVZrCRSLQlr4VX2QLiWQA0rG++M0kd XgSScmNoEIi5bhlY/FuoZhd4sX8nr2oJFFP11CvbpAQA1zfwSp3xqLuxRVrsHvxr7b A48O/APOkDFZfUg1dfyeKdnT5vpu07nR5Gb4/sOGmmRqzxDIeZLokaDbYGL6dQ90cb XDfl8OO2oOrnJlfPv4nzkx1yp8MhmCKfU7n8zIoIt5Bp25SVKQqh3K7bL65spr8YYy x5hG7EQxQZn2A== From: Sasha Levin To: stable@vger.kernel.org Cc: Geliang Tang , Xuanqiang Luo , "Matthieu Baerts (NGI0)" , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6.y 4/4] mptcp: pm: userspace: fix use-after-free in get_local_id Date: Fri, 7 Aug 2026 07:48:13 -0400 Message-ID: <20260807114813.2056374-4-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260807114813.2056374-1-sashal@kernel.org> References: <2026072920-budding-prescribe-9ea0@gregkh> <20260807114813.2056374-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: Geliang Tang [ Upstream commit 9bc6d5e4ca9f3cbb41d43400b3a31cb0403796c9 ] In mptcp_pm_userspace_get_local_id(), the address entry is looked up under spinlock, but its id is read after dropping the lock. A concurrent deletion can free the entry between the unlock and the read, leading to UAF. The race window is narrow. It was reproduced only with a locally constructed stress test that repeatedly overlaps an MP_JOIN SYN with a MPTCP_PM_CMD_SUBFLOW_DESTROY request. However, the KASAN report below confirms that the race is reachable: [ 666.319376] BUG: KASAN: slab-use-after-free in mptcp_userspace_pm_get_local_id+0x1dc/0x1f0 [ 666.319386] Read of size 1 at addr ffff888124845610 by task swapper/0/0 ... [ 666.319401] Call Trace: [ 666.319405] [ 666.319408] dump_stack_lvl+0x53/0x70 [ 666.319412] print_address_description.constprop.0+0x2c/0x3b0 [ 666.319418] print_report+0xbe/0x2b0 [ 666.319421] ? mptcp_userspace_pm_get_local_id+0x1dc/0x1f0 [ 666.319423] kasan_report+0xce/0x100 [ 666.319426] ? mptcp_userspace_pm_get_local_id+0x1dc/0x1f0 [ 666.319429] mptcp_userspace_pm_get_local_id+0x1dc/0x1f0 [ 666.319433] mptcp_pm_get_local_id+0x371/0x440 ... [ 666.319821] Allocated by task 45539: [ 666.319844] kasan_save_stack+0x33/0x60 [ 666.319855] kasan_save_track+0x14/0x30 [ 666.319858] __kasan_kmalloc+0x8f/0xa0 [ 666.319863] __kmalloc_noprof+0x1e7/0x520 [ 666.319867] sock_kmalloc+0xdf/0x130 [ 666.319885] sock_kmemdup+0x1b/0x40 [ 666.319888] mptcp_userspace_pm_append_new_local_addr+0x261/0x500 [ 666.319910] mptcp_pm_nl_announce_doit+0x16a/0x610 ... [ 666.319967] Freed by task 45560: [ 666.319988] kasan_save_stack+0x33/0x60 [ 666.319991] kasan_save_track+0x14/0x30 [ 666.319994] kasan_save_free_info+0x3b/0x60 [ 666.319998] __kasan_slab_free+0x43/0x70 [ 666.320000] kfree+0x166/0x440 [ 666.320003] sock_kfree_s+0x1d/0x50 [ 666.320007] mptcp_userspace_pm_delete_local_addr.isra.0+0x157/0x200 [ 666.320011] mptcp_pm_nl_subflow_destroy_doit+0x51d/0xea0 Fix by copying the id into a local variable while still holding the lock, and use -1 as a "not found" sentinel. Fixes: f012d796a6de ("mptcp: check addrs list in userspace_pm_get_local_id") Cc: stable@vger.kernel.org Signed-off-by: Geliang Tang Tested-by: Xuanqiang Luo Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260722-net-mptcp-misc-fixes-7-2-rc5-v1-2-6fb595bc86ef@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/mptcp/pm_userspace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 31d45b1db3903..ded7a4d416919 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -153,12 +153,15 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; struct mptcp_pm_addr_entry *entry; + int id; spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr(msk, &skc->addr); + id = entry ? entry->addr.id : -1; spin_unlock_bh(&msk->pm.lock); - if (entry) - return entry->addr.id; + + if (id != -1) + return id; if (skc->addr.port == msk_sport) skc->addr.port = 0; -- 2.53.0