From: Henry Martin <bsdhenrymartin@gmail.com>
To: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org
Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev,
Henry Martin <bsdhenrymartin@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH net] pfkey: fix kernel stack leak in pfkey_migrate()
Date: Fri, 20 Nov 2026 13:28:14 +0800 [thread overview]
Message-ID: <20261120052814.3686573-1-bsdhenrymartin@gmail.com> (raw)
pfkey_migrate() declares struct xfrm_migrate m[XFRM_MAX_DEPTH] on the
stack without initializing it. For AF_INET endpoints
pfkey_sockaddr_extract() writes only the 4-byte a4 member, leaving
the remaining 12 bytes of each xfrm_address_t as stack residue.
xfrm_state_clone_and_setup() then memcpy()s the full 16-byte
new_daddr and new_saddr into the cloned xfrm_state, and a subsequent
XFRM_MSG_GETSA dump copies them back to userspace as-is. Each
migrated SA leaks 24 bytes of kernel stack, which can contain kernel
pointers. The same uninitialized bytes also feed the 16-byte memcmp()
in xfrm_migrate_check(), making duplicate detection unreliable.
Zero-initialize the array, as xfrm_do_migrate() in xfrm_user.c
already does.
This issue was discovered by Tencent CodeBuddy Security.
Cc: stable@vger.kernel.org
Fixes: 08de61beab8a ("[PFKEYV2]: Extension for dynamic update of endpoint address(es)")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
net/key/af_key.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index d215b33b7492..6d116862b20d 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -2571,7 +2571,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
struct sadb_x_policy *pol;
struct sadb_x_ipsecrequest *rq;
struct xfrm_selector sel;
- struct xfrm_migrate m[XFRM_MAX_DEPTH];
+ struct xfrm_migrate m[XFRM_MAX_DEPTH] = {};
struct xfrm_kmaddress k;
struct net *net = sock_net(sk);
--
2.43.7
next reply other threads:[~2026-11-20 5:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 5:28 Henry Martin [this message]
2026-11-20 5:33 ` [PATCH net] pfkey: fix kernel stack leak in pfkey_migrate() netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120052814.3686573-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=ipsec@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox