From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379058; b=SD4IX0hLVyZPimYNcJQDiuDIUR7mZzCSqGVM+yTSZY5hqMoA9o7nhf/rrbEwVPqH9S9+ EqH0tjmYP6NrqeSDleUPTp4Uasr1AmJ9nghMTFA3IV/rGpoTG7U6gnlrAzc4N9U2sUA88 0FKzKES6s+6d401UujzWOwIskr0/Hq1C+9aePRyu1zzaFOCY5qpLcgJxWQGBjeBzNy3RS QDzuaVDTvoyffbHhqmrcS8mMb75H5DnfKE+sZqK1higAvRJreOnj+mQBt56nqaSbRaJqz bFpcb6/CGMOJyNWqJiALdKDHKdpZGpzqnlYRV6asB5MeGvXd8lRZwEj0js1kVCL3Row== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379058; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=FMCe3F3q15eUPYf+6K7da5pOWyaFUywuyRbbrz5bT8A=; b=sy66RwvGweE/3Ack05LN4Yninc0uwH072nJtBXMgPM2U7a/AyG/ckmLx4far2Qh9/dHp +6aD9xRK6vqWEU9Jy8+sxssvKejjBpx0/4iorB6aUdhyQp18a0EtyOnEYrKRzbL8bgiuJ Fa+iJmmnMdKGSonoGjmoYZ98E47xL5VZKPUk5m5GQxQ10HTun8WudKsBgS+7GjH/IMbED vHjBSZ45vJkx9BLRKf1Va9GVYxhljKy7lehiwCma/UBdNrwQVyBvgPDY8G1SZOI2iq1we lm0NR3Od9CuTIdpJYJFhATGiVFcsc+oCdOT3EMHoQPHoh21KqjLMkY+qLNO1yTBmHAQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UKgQdZi4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D4C1606A32D; Fri, 4 Dec 2026 10:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UKgQdZi4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0B8D1F00931; Fri, 4 Dec 2026 10:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379058; bh=FMCe3F3q15eUPYf+6K7da5pOWyaFUywuyRbbrz5bT8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UKgQdZi4pR+A0W6jkY2BKPB1HVxdXKjHUK7Y8us6ojHYG8GuC2MblAffL2Zng4F+q FAgNs8Rsr2B5spf0xa0KgKClHrXNCnS6gvnkASTO5oaiIaKxrf0i+Z0JuqDI3UeKzo cTUioxlcKNCu38W1N2+9UcWZRTm9fVcAsxgVCzn4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuan Tan , Yifan Wu , Juefei Pu , Xin Liu , Sabrina Dubroca , Jakub Kicinski , Artem Dinaburg , Sasha Levin Subject: [PATCH 6.18 002/703] mpls: add seqcount to protect the platform_label{,s} pair Date: Fri, 4 Dec 2026 18:58:21 +0900 Message-ID: <20261204100627.596676734@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sabrina Dubroca [ Upstream commit 629ec78ef8608d955ce217880cdc3e1873af3a15 ] The RCU-protected codepaths (mpls_forward, mpls_dump_routes) can have an inconsistent view of platform_labels vs platform_label in case of a concurrent resize (resize_platform_label_table, under platform_mutex). This can lead to OOB accesses. This patch adds a seqcount, so that we get a consistent snapshot. Note that mpls_label_ok is also susceptible to this, so the check against RTA_DST in rtm_to_route_config, done outside platform_mutex, is not sufficient. This value gets passed to mpls_label_ok once more in both mpls_route_add and mpls_route_del, so there is no issue, but that additional check must not be removed. Reported-by: Yuan Tan Reported-by: Yifan Wu Reported-by: Juefei Pu Reported-by: Xin Liu Fixes: 7720c01f3f590 ("mpls: Add a sysctl to control the size of the mpls label table") Fixes: dde1b38e873c ("mpls: Convert mpls_dump_routes() to RCU.") Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/cd8fca15e3eb7e212b094064cd83652e20fd9d31.1774284088.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski [ Backport to 6.18.y: 6.18.y has neither the per-netns platform_mutex (upstream e833eb25161a) nor the RCU conversion of mpls_dump_routes() (upstream dde1b38e873c); resize_platform_label_table() is serialized by RTNL. Use a plain seqcount_t instead of seqcount_mutex_t and disable preemption explicitly around the write section, since local_bh_disable() does not do so on PREEMPT_RT. Keep rcu_dereference_rtnl() in the helper because mpls_getroute() reaches it under RTNL without rcu_read_lock(). mpls_dump_routes() still runs under RTNL, so it is left unchanged. ] Signed-off-by: Artem Dinaburg Signed-off-by: Sasha Levin --- include/net/netns/mpls.h | 2 ++ net/mpls/af_mpls.c | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/net/netns/mpls.h b/include/net/netns/mpls.h index 19ad2574b267c..9b83b7f43d83b 100644 --- a/include/net/netns/mpls.h +++ b/include/net/netns/mpls.h @@ -7,6 +7,7 @@ #define __NETNS_MPLS_H__ #include +#include struct mpls_route; struct ctl_table_header; @@ -16,6 +17,7 @@ struct netns_mpls { int default_ttl; size_t platform_labels; struct mpls_route __rcu * __rcu *platform_label; + seqcount_t platform_label_seq; struct ctl_table_header *ctl; }; diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c index 608c43a4602d6..9ed136931c4f1 100644 --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -75,16 +75,31 @@ static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt, struct nlmsghdr *nlh, struct net *net, u32 portid, unsigned int nlm_flags); +static struct mpls_route __rcu **mpls_platform_label_rcu(struct net *net, size_t *platform_labels) +{ + struct mpls_route __rcu **platform_label; + unsigned int sequence; + + do { + sequence = read_seqcount_begin(&net->mpls.platform_label_seq); + platform_label = rcu_dereference_rtnl(net->mpls.platform_label); + *platform_labels = net->mpls.platform_labels; + } while (read_seqcount_retry(&net->mpls.platform_label_seq, sequence)); + + return platform_label; +} + static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index) { - struct mpls_route *rt = NULL; + struct mpls_route __rcu **platform_label; + size_t platform_labels; - if (index < net->mpls.platform_labels) { - struct mpls_route __rcu **platform_label = - rcu_dereference_rtnl(net->mpls.platform_label); - rt = rcu_dereference_rtnl(platform_label[index]); - } - return rt; + platform_label = mpls_platform_label_rcu(net, &platform_labels); + + if (index >= platform_labels) + return NULL; + + return rcu_dereference_rtnl(platform_label[index]); } bool mpls_output_possible(const struct net_device *dev) @@ -2582,8 +2597,14 @@ static int resize_platform_label_table(struct net *net, size_t limit) } /* Update the global pointers */ + local_bh_disable(); + preempt_disable(); + write_seqcount_begin(&net->mpls.platform_label_seq); net->mpls.platform_labels = limit; rcu_assign_pointer(net->mpls.platform_label, labels); + write_seqcount_end(&net->mpls.platform_label_seq); + preempt_enable(); + local_bh_enable(); rtnl_unlock(); @@ -2664,6 +2685,8 @@ static int mpls_net_init(struct net *net) struct ctl_table *table; int i; + seqcount_init(&net->mpls.platform_label_seq); + net->mpls.platform_labels = 0; net->mpls.platform_label = NULL; net->mpls.ip_ttl_propagate = 1; -- 2.53.0