FAILED: patch "[PATCH] mctp: route: iterate socket tag list in" failed to apply to 6.6-stable tree
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 26cc0e69cce062cd3aa6fae33074684669c35a71
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092919-dawdler-dodge-debe@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 26cc0e69cce062cd3aa6fae33074684669c35a71 Mon Sep 17 00:00:00 2001
From: Hui Peng <[email protected]>
Date: Mon, 21 Sep 2026 05:10:01 +0000
Subject: [PATCH] mctp: route: iterate socket tag list in
mctp_lookup_prealloc_tag()
When a socket transmits a packet with MCTP_TAG_PREALLOC set, mctp_lookup_prealloc_tag() iterates over the per-netns &mns->keys list and matches netid, req_tag, peer_addr, and manual_alloc, without checking whether tmp->sk == &msk->sk. This allows any MCTP socket in the same network namespace to use and consume another socket's preallocated tag.
Iterate the socket's own tag list (&msk->keys via sklist) instead of the namespace-wide &mns->keys list in mctp_lookup_prealloc_tag(), ensuring that only tags allocated by msk are matched.
Tested in QEMU against Linux 7.3.0-rc3 by allocating a manual tag (0x18) on socket A via SIOCMCTPALLOCTAG for peer EID 9 and sending a 4-byte message with MCTP_TAG_PREALLOC from socket B in the same network namespace. On the unfixed kernel, sendto(sock_b) using socket A's preallocated tag succeeds (ret = 4); with this patch applied, sendto(sock_b) fails with -ENOENT (errno = 2) while sendto(sock_a) succeeds (ret = 4).
net/mctp/route.c +1 -1
@@ -825,7 +825,7 @@ static struct mctp_sk_key *mctp_lookup_prealloc_tag(struct mctp_sock *msk,spin_lock_irqsave (&mns->keys_lock, flags); -hlist_for_each_entry (tmp, &mns->keys, hlist) { +hlist_for_each_entry (tmp, &msk->keys, sklist) {if (tmp->net != netid)continue ;
Sasha Levin
maintainerPATCH 1/4 net: mctp: avoid confusion over local/peer dest/source addresses
From: Jeremy Kerr <[email protected]>
[ Upstream commit ee076b73e576b0a052d5686d873346b285ae50ea ]
We have a double-swap of local and peer addresses in mctp_alloc_local_tag; the arguments in both call sites are swapped, but there is also a swap in the implementation of alloc_local_tag. This is opaque because we're using source/dest address references, which don't match the local/peer semantics.
Avoid this confusion by naming the arguments as 'local' and 'peer', and remove the double swap. The calling order now matches mctp_key_alloc.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- include/net/mctp.h | 4 ++-- net/mctp/af_mctp.c | 2 +- net/mctp/route.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-)
include/net/mctp.h +2 -2
@@ -90,7 +90,7 @@ struct mctp_sock { };/* Key for matching incoming packets to sockets or reassembly contexts. -* Packets are matched on (src,dest,tag). +* Packets are matched on (peer EID, local EID, tag). * * Lifetime / locking requirements: *
@@ -258,7 +258,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,void mctp_key_unref (struct mctp_sk_key *key);struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, -mctp_eid_t daddr,mctp_eid_t saddr, +mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp);/* routing <--> device interface */
net/mctp/af_mctp.c +1 -1
@@ -366,7 +366,7 @@ static int mctp_ioctl_alloctag(struct mctp_sock *msk, unsigned long arg)if (ctl.flags)return -EINVAL ; - key =mctp_alloc_local_tag (msk, ctl.peer_addr,MCTP_ADDR_ANY , + key =mctp_alloc_local_tag (msk,MCTP_ADDR_ANY , ctl.peer_addr, true, &tag);if (IS_ERR (key))return PTR_ERR (key);
net/mctp/route.c +8 -8
@@ -619,11 +619,11 @@ static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,refcount_inc (&key->refs); } -/* Allocate a locally-owned tag value for (saddr, daddr), and reserve +/* Allocate a locally-owned tag value for (local, peer), and reserve * it for the socket msk */ struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, -mctp_eid_t daddr,mctp_eid_t saddr, +mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp) {struct net *net =sock_net (&msk->sk);
@@ -633,11 +633,11 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,u8 tagbits;/* for NULL destination EIDs, we may get a response from any peer */ -if (daddr ==MCTP_ADDR_NULL ) - daddr =MCTP_ADDR_ANY ; +if (peer ==MCTP_ADDR_NULL ) + peer =MCTP_ADDR_ANY ;/* be optimistic, alloc now */ - key =mctp_key_alloc (msk, saddr, daddr,0 ,GFP_KERNEL ); + key =mctp_key_alloc (msk, local, peer,0 ,GFP_KERNEL );if (!key)return ERR_PTR (-ENOMEM );
@@ -658,8 +658,8 @@ struct mctp_sk_key *mctp_alloc_local_tag(struct mctp_sock *msk,if (tmp->tag &MCTP_HDR_FLAG_TO )continue ; -if (!(mctp_address_matches (tmp->peer_addr, daddr) && -mctp_address_matches (tmp->local_addr, saddr))) +if (!(mctp_address_matches (tmp->peer_addr, peer) && +mctp_address_matches (tmp->local_addr, local)))continue ;spin_lock (&tmp->lock);
@@ -951,7 +951,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, key =mctp_lookup_prealloc_tag (msk, daddr, req_tag, &tag); else - key =mctp_alloc_local_tag (msk, daddr, saddr, + key =mctp_alloc_local_tag (msk, saddr, daddr, false, &tag);if (IS_ERR (key)) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 net: mctp: Add some detail on the key allocation implementation
From: Jeremy Kerr <[email protected]>
[ Upstream commit aee6479a458e2c5027e558cfe26c60c37f8efc80 ]
We could do with a little more comment on where MCTP_ADDR_ANY will match in the key allocations.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- net/mctp/route.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
net/mctp/route.c +37 -0
@@ -73,6 +73,40 @@ static struct mctp_sock *mctp_lookup_bind(struct net *net, struct sk_buff *skb)return NULL ; } +/* A note on the key allocations. +* +* struct net->mctp.keys contains our set of currently-allocated keys for +* MCTP tag management. The lookup tuple for these is the peer EID, +* local EID and MCTP tag. +* +* In some cases, the peer EID may be MCTP_EID_ANY: for example, when a +* broadcast message is sent, we may receive responses from any peer EID. +* Because the broadcast dest address is equivalent to ANY, we create +* a key with (local = local-eid, peer = ANY). This allows a match on the +* incoming broadcast responses from any peer. +* +* We perform lookups when packets are received, and when tags are allocated +* in two scenarios: +* +* - when a packet is sent, with a locally-owned tag: we need to find an +* unused tag value for the (local, peer) EID pair. +* +* - when a tag is manually allocated: we need to find an unused tag value +* for the peer EID, but don't have a specific local EID at that stage. +* +* in the latter case, on successful allocation, we end up with a tag with +* (local = ANY, peer = peer-eid). +* +* So, the key set allows both a local EID of ANY, as well as a peer EID of +* ANY in the lookup tuple. Both may be ANY if we prealloc for a broadcast. +* The matching (in mctp_key_match()) during lookup allows the match value to +* be ANY in either the dest or source addresses. +* +* When allocating (+ inserting) a tag, we need to check for conflicts amongst +* the existing tag set. This requires macthing either exactly on the local +* and peer addresses, or either being ANY. +*/ +static bool mctp_key_match (struct mctp_sk_key *key,mctp_eid_t local,mctp_eid_t peer,u8 tag) {
@@ -380,6 +414,9 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)* key lookup to find the socket, but don't use this * key for reassembly - we'll create a more specific * one for future packets if required (ie, !EOM). +* +* this lookup requires key->peer to be MCTP_ADDR_ANY, +* it doesn't match just any key->peer. */ any_key =mctp_lookup_key (net, skb,MCTP_ADDR_ANY , &f);if (any_key) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 net: mctp: separate key correlation across nets
In reply to Sasha LevinFrom: Jeremy Kerr <[email protected]>
[ Upstream commit 43e6795574f5d75284a3cb21f5b76a5ffb98e8e6 ]
Currently, we lookup sk_keys from the entire struct net_namespace, which may contain multiple MCTP net IDs. In those cases we want to distinguish between endpoints with the same EID but different net ID.
Add the net ID data to the struct mctp_sk_key, populate on add and filter on this during route lookup.
For the ioctl interface, we use a default net of MCTP_INITIAL_DEFAULT_NET (ie., what will be in use for single-net configurations), but we'll extend the ioctl interface to provide net-specific tag allocation in an upcoming change.
Stable-dep-of: 26cc0e69cce0 ("mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()")
--- include/net/mctp.h | 2 ++ net/mctp/af_mctp.c | 4 ++-- net/mctp/route.c | 43 +++++++++++++++++++++++++++----------- net/mctp/test/route-test.c | 7 +++++-- 4 files changed, 40 insertions(+), 16 deletions(-)
include/net/mctp.h +2 -0
@@ -136,6 +136,7 @@ struct mctp_sock {* - through an expiry timeout, on a per-socket timer */ struct mctp_sk_key { +unsigned int net;mctp_eid_t peer_addr;mctp_eid_t local_addr;/* MCTP_ADDR_ANY for local owned tags */ __u8 tag;/* incoming tag match; invert TO for local */
@@ -258,6 +259,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,void mctp_key_unref (struct mctp_sk_key *key);struct mctp_sk_key *mctp_alloc_local_tag (struct mctp_sock *msk, +unsigned int netid,mctp_eid_t local,mctp_eid_t peer,bool manual,u8 *tagp);
net/mctp/af_mctp.c +2 -2
@@ -366,8 +366,8 @@ static int mctp_ioctl_alloctag(struct mctp_sock *msk, unsigned long arg)if (ctl.flags)return -EINVAL ; - key =mctp_alloc_local_tag (msk,MCTP_ADDR_ANY , ctl.peer_addr, - true, &tag); + key =mctp_alloc_local_tag (msk,MCTP_INITIAL_DEFAULT_NET , +MCTP_ADDR_ANY , ctl.peer_addr, true, &tag);if (IS_ERR (key))return PTR_ERR (key);
net/mctp/route.c +31 -12
160 lines not on this page · raw message
net/mctp/test/route-test.c +5 -2
@@ -544,6 +544,7 @@ static void mctp_test_route_input_sk_keys(struct kunit *test)struct mctp_sock *msk;struct socket *sock;unsigned long flags; +unsigned int net;int rc;u8 c;
@@ -551,6 +552,7 @@ static void mctp_test_route_input_sk_keys(struct kunit *test) dev =mctp_test_create_dev ();KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + net =READ_ONCE (dev->mdev->net); rt =mctp_test_create_route (&init_net, dev->mdev,8 ,68 );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt);
@@ -562,8 +564,9 @@ static void mctp_test_route_input_sk_keys(struct kunit *test) mns = &sock_net (sock->sk)->mctp;/* set the incoming tag according to test params */ - key =mctp_key_alloc (msk, params->key_local_addr, params->key_peer_addr, - params->key_tag,GFP_KERNEL ); + key =mctp_key_alloc (msk, net, params->key_local_addr, + params->key_peer_addr, params->key_tag, +GFP_KERNEL );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, key);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 mctp: route: iterate socket tag list in mctp_lookup_prealloc_tag()
In reply to Sasha LevinFrom: Hui Peng <[email protected]>
[ Upstream commit 26cc0e69cce062cd3aa6fae33074684669c35a71 ]
When a socket transmits a packet with MCTP_TAG_PREALLOC set, mctp_lookup_prealloc_tag() iterates over the per-netns &mns->keys list and matches netid, req_tag, peer_addr, and manual_alloc, without checking whether tmp->sk == &msk->sk. This allows any MCTP socket in the same network namespace to use and consume another socket's preallocated tag.
Iterate the socket's own tag list (&msk->keys via sklist) instead of the namespace-wide &mns->keys list in mctp_lookup_prealloc_tag(), ensuring that only tags allocated by msk are matched.
Tested in QEMU against Linux 7.3.0-rc3 by allocating a manual tag (0x18) on socket A via SIOCMCTPALLOCTAG for peer EID 9 and sending a 4-byte message with MCTP_TAG_PREALLOC from socket B in the same network namespace. On the unfixed kernel, sendto(sock_b) using socket A's preallocated tag succeeds (ret = 4); with this patch applied, sendto(sock_b) fails with -ENOENT (errno = 2) while sendto(sock_a) succeeds (ret = 4).
--- net/mctp/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mctp/route.c +1 -1
@@ -758,7 +758,7 @@ static struct mctp_sk_key *mctp_lookup_prealloc_tag(struct mctp_sock *msk,spin_lock_irqsave (&mns->keys_lock, flags); -hlist_for_each_entry (tmp, &mns->keys, hlist) { +hlist_for_each_entry (tmp, &msk->keys, sklist) {if (tmp->net != netid)continue ;
Signature · 1 line
2.53.0