ip6mr: Serialize multicast router socket ownership
Subsystems (3)
PATCH 1/1 ip6mr: Serialize multicast router socket ownership
MRT6_TABLE checks whether the socket owns its current table before acquiring RTNL. MRT6_INIT also looks up its table before taking RTNL. Consequently, concurrent TABLE and INIT calls can initialize the old table and then change the socket's selected table. Another INIT can register the same socket in the new table.
rawv6_close() calls ip6mr_sk_done(), which clears only the first table owned by the socket. After the socket's RCU-delayed free, the other table retains a dangling mroute_sk pointer. A subsequent multicast cache report passes that pointer to sock_queue_rcv_skb_reason(). This produces a KASAN slab-use-after-free in sk_filter_trim_cap().
Look up the selected table in ip6mr_sk_init() after acquiring RTNL. Likewise, re-read the current table and check its owner under RTNL in MRT6_TABLE before updating the selection. This preserves the single-table ownership invariant shared with ip6mr_sk_done(), without changing the locking of the other multicast socket options.
---
I have a reproducer for this issue and can share via DM
net/ipv6/ip6mr.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
net/ipv6/ip6mr.c +25 -11
@@ -1623,12 +1623,20 @@ static void mroute_clean_tables(struct mr_table *mrt, int flags, } } -static int ip6mr_sk_init (struct mr_table *mrt,struct sock *sk) +static int ip6mr_sk_init (struct sock *sk) { -int err =0 ;struct net *net =sock_net (sk); +struct mr_table *mrt; +int err =0 ;rtnl_lock (); + mrt =__ip6mr_get_table (net, +raw6_sk (sk)->ip6mr_table ? :RT6_TABLE_DFLT ); +if (!mrt) { + err = -ENOENT ; + goto out_unlock; + } +spin_lock (&mrt_lock);if (rtnl_dereference (mrt->mroute_sk)) { err = -EADDRINUSE ;
@@ -1644,6 +1652,7 @@ static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk)NETCONFA_MC_FORWARDING ,NETCONFA_IFINDEX_ALL , net->ipv6.devconf_all); +out_unlock:rtnl_unlock ();return err;
@@ -1745,7 +1754,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval,if (optlen <sizeof (int ))return -EINVAL ; -return ip6mr_sk_init (mrt, sk); +return ip6mr_sk_init (sk);case MRT6_DONE :return ip6mr_sk_done (sk);
@@ -1872,16 +1881,21 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval,/* "pim6reg%u" should not exceed 16 bytes (IFNAMSIZ) */ if (v !=RT_TABLE_DEFAULT && v >=100000000 )return -EINVAL ; -if (sk ==rcu_access_pointer (mrt->mroute_sk)) -return -EBUSY ; -rtnl_lock (); ret =0 ; - mrt =ip6mr_new_table (net, v); -if (IS_ERR (mrt)) - ret =PTR_ERR (mrt); -else -raw6_sk (sk)->ip6mr_table = v; + mrt =__ip6mr_get_table (net, +raw6_sk (sk)->ip6mr_table ? :RT6_TABLE_DFLT ); +if (!mrt) { + ret = -ENOENT ; + }else if (sk ==rtnl_dereference (mrt->mroute_sk)) { + ret = -EBUSY ; + }else { + mrt =ip6mr_new_table (net, v); +if (IS_ERR (mrt)) + ret =PTR_ERR (mrt); +else +raw6_sk (sk)->ip6mr_table = v; + }rtnl_unlock ();return ret; }
base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
Signature · 1 line
2.56.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 12 lines · Kyle Zeng
MRT6_TABLEchecks whether the socket owns its current table before acquiring RTNL.MRT6_INITalso looks up its table before taking RTNL. Consequently, concurrent TABLE and INIT calls can initialize the old table and then change the socket's selected table. Another INIT can register the same socket in the new table.
rawv6_close()callsip6mr_sk_done(), which clears only the first table owned by the socket. After the socket's RCU-delayed free, the other table retains a danglingmroute_skpointer. A subsequent multicast cache report passes that pointer tosock_queue_rcv_skb_reason(). This produces a KASAN slab-use-after-free insk_filter_trim_cap().
Quoted 8 lines
Look up the selected table in
ip6mr_sk_init()after acquiring RTNL. Likewise, re-read the current table and check its owner under RTNL inMRT6_TABLEbefore updating the selection. This preserves the single-table ownership invariant shared withip6mr_sk_done(), without changing the locking of the other multicast socket options.Fixes d1db275dd3f6 ("ipv6: ip6mr: support multiple tables")Signed-off-by Kyle Zeng <[email protected]>
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Thu, 29 Oct 2026 21:22:21 -0700 you wrote:
MRT6_TABLEchecks whether the socket owns its current table before acquiring RTNL.MRT6_INITalso looks up its table before taking RTNL. Consequently, concurrent TABLE and INIT calls can initialize the old table and then change the socket's selected table. Another INIT can register the same socket in the new table.
Quoted 7 lines
rawv6_close()callsip6mr_sk_done(), which clears only the first table owned by the socket. After the socket's RCU-delayed free, the other table retains a danglingmroute_skpointer. A subsequent multicast cache report passes that pointer tosock_queue_rcv_skb_reason(). This produces a KASAN slab-use-after-free insk_filter_trim_cap().[...]
Here is the summary with links:
- ip6mr: Serialize multicast router socket ownership
https://git.kernel.org/netdev/net/c/c6b41de4dd9f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html