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 AB7343AD526 for ; Thu, 17 Sep 2026 03:35:51 +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=1789616160; cv=none; b=Qd777ztbw0FjDR04ag7qUejGsIzhxON7TUfwhovpUaBYnfy6qLXvCcRyRVijoibplZ8NyPsmy3HfYJjsjC/cFosiNc8/gjVkozyms3GaHookCoqzkePHuKWioJsa1etMqBkTksuskkxn9y1tcTsnDdZbzjY9Nktk6BpaUh78fds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789616160; c=relaxed/simple; bh=trV7e63ezLYqpFjO+r7CadxaqvLlvahvUp6hcV4BEQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UvEJXZZ7uelLescXx43IgZXEubnrXHQaXohCiLaIahFzdwxYRcCzphYBgJ9OqNcb0pQu9KDA98vq/m64F2IbhltHiHwgLzXwNadBGt/fYqkN5eK/lF4Xb8NE/xShTRkYdOMtOsJD6AhSgVkQ67gVvjDPYbq6YMaUwPeB+CDZMoU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DyEMITKF; 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="DyEMITKF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC5901F0089E; Thu, 17 Sep 2026 03:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789616142; bh=eavrvn4m9eFDh53Ot0j/T6rBnmbvWCGmaT2D2Al7BCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DyEMITKFpI+MqS4QNdJ0XP8CwqSyhSZsTXlU+O5hRGYEBZTv69VrZJrmIjaC0e2K5 OSxhZf7W/LAHAw5Du8KcZnHbvp22aglANpSVWJAcoQsvuZDceSw37ayq7C7jK/fWq0 Y/B5x7ao/VHYgHHMvrGRmIaWZ6td9HO/Twbx/fygMFLdxIhkWRRLRNBB8dzRgHgJyu 23Yq/T5vkErKouxcJqB7hFXtJBDUwFETcvn56o+WZxK+e7rvwDH3t3D5+oAYwVLP0K GDnXNzXVauEyLXmxj4MkS9iV70HBR1AZnnLgtMo9z7aPiU8386EicahXElyAt9Q0vv knk8nmUoealsw== From: Sasha Levin To: stable@vger.kernel.org Cc: Qing Luo , "Matthieu Baerts (NGI0)" , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1.y 5/5] mptcp: pm: userspace: fix address ID overflow Date: Wed, 16 Sep 2026 23:35:36 -0400 Message-ID: <20260917033537.4044281-5-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260917033537.4044281-1-sashal@kernel.org> References: <2026091628-sevenfold-cursive-c662@gregkh> <20260917033537.4044281-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: Qing Luo [ Upstream commit f9f0068e8813d8c10d016b030fc3a320d0b6767c ] When all MPTCP address IDs (1-255) are exhausted in the userspace PM, find_next_zero_bit() returns MPTCP_PM_MAX_ADDR_ID + 1 (256). This value overflows when stored in the u8 field e->addr.id, resulting in ID 0 being stored and the entry being incorrectly added to the list. ID 0 is reserved for the initial connection in MPTCP, so this overflow can cause address conflicts. Note: the in-kernel PM already has an 'endpoints == MPTCP_PM_MAX_ADDR_ID' check in mptcp_pm_nl_append_new_local_addr() that returns -ERANGE before reaching find_next_zero_bit(), preventing this overflow. So this fix only addresses the userspace PM path. Check the find_next_zero_bit() result against MPTCP_PM_MAX_ADDR_ID and return -ENOSPC if all IDs are truly exhausted. Move the ID allocation check before the memory allocation so that the error path does not need to free the allocated entry. Fixes: 4638de5aefe5 ("mptcp: handle local addrs announced by userspace PMs") Cc: stable@vger.kernel.org Signed-off-by: Qing Luo Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20260908-net-mptcp-misc-fixes-7-3-rc1-v2-8-df1de70348b6@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/mptcp/pm_userspace.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 1bc270276db46..a455303d2ed64 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -67,6 +67,19 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, } if (!addr_match && !id_match) { + unsigned int id; + + if (!entry->addr.id && needs_id) { + id = find_next_zero_bit(id_bitmap, + MPTCP_PM_MAX_ADDR_ID + 1, 1); + if (id > MPTCP_PM_MAX_ADDR_ID) { + ret = -ENOSPC; + goto append_err; + } + } else { + id = entry->addr.id; + } + /* Memory for the entry is allocated from the * sock option buffer. */ @@ -76,10 +89,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, goto append_err; } - if (!e->addr.id && needs_id) - e->addr.id = find_next_zero_bit(id_bitmap, - MPTCP_PM_MAX_ADDR_ID + 1, - 1); + e->addr.id = id; list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); msk->pm.local_addr_used++; ret = e->addr.id; -- 2.53.0