🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19662

Re: [PATCH net] net: af_key: fix use-after-free in dump_sp() on policy migrate

#19662
From: Steffen Klassert
Date: Fri, 20 Nov 2026 07:13
67 lines
12712 bytes
On Thu, Nov 19, 2026 at 12:32:46PM +0100, Paolo Abeni wrote:
> On 11/14/26 23:35, Daniel Wade wrote:
> > pfkey_xfrm_policy2msg_size() derives an exported policy's message length
> > from xfrm_vec[].encap_family. dump_sp() derives it twice: once through
> > pfkey_xfrm_policy2msg_prep(), which allocates the skb, and again in
> > pfkey_xfrm_policy2msg(), which fills it in.
> > 
> > dump_sp() holds net->xfrm.xfrm_policy_lock rather than pol->lock, so
> > xfrm_policy_migrate() can rewrite encap_family between the two
> > derivations. The second length is then up to 24 bytes per template
> > larger than the first, and pfkey_xfrm_policy2msg() opens with
> > memset(hdr, 0, size), clearing the difference into the skb's shared
> > info. Four BEET templates put 80 bytes there, which reaches dataref:
> > alloc_skb() had set it to 1, the memset makes it 0, and the skb_clone()
> > in pfkey_broadcast_one() leaves two skbs sharing one head with a dataref
> > of 1. Freeing the original releases a head the queued clone still points
> > at, so recvmsg() copies freed memory to user space and consume_skb()
> > frees it a second time. The CAP_NET_ADMIN that pfkey_create() and the
> > xfrm netlink receive path check is namespace-relative, so an
> > unprivileged user can reach this. SLUB's double-free check fires within
> > a second of starting the reproducer; the oops kills a task, or panics
> > the machine when the corruption lands in softirq context.
> > 
> > Racing SADB_X_SPDDUMP against XFRM_MSG_MIGRATE as an ordinary user gave
> > 4585 use-after-free reports and 765 double-frees in 300s on mainline
> > with KASAN and 8 CPUs. The reads reach user space (addresses trimmed):
> > 
> >    BUG: KASAN: slab-use-after-free in _copy_to_iter+0x1d8/0x1430
> >    Read of size 240 at addr ffff88810f98d140 by task pfkey_dataref_o/433
> >    CPU: 3 UID: 65534 PID: 433 Comm: pfkey_dataref_o Not tainted 7.4.0-rc2
> >    Call Trace:
> >     <TASK>
> >     dump_stack_lvl+0x66/0xa0
> >     print_report+0xd0/0x600
> >     kasan_report+0xc6/0x100
> >     kasan_check_range+0x105/0x1b0
> >     _copy_to_iter+0x1d8/0x1430
> >     __skb_datagram_iter+0xf8/0x820
> >     skb_copy_datagram_iter+0x6c/0x1a0
> >     pfkey_recvmsg+0x1ff/0x500
> >     sock_recvmsg+0x15e/0x1a0
> >     __sys_recvfrom+0x182/0x260
> >     do_syscall_64+0x10b/0x5f0
> >     entry_SYSCALL_64_after_hwframe+0x77/0x7f
> >    Allocated by task 433:
> >     kmalloc_reserve+0x108/0x2b0
> >     __alloc_skb+0x123/0x5b0
> >     dump_sp+0xdf/0x490
> >     xfrm_policy_walk+0x1d9/0x6c0
> >     pfkey_do_dump+0x61/0x420
> >     pfkey_recvmsg+0x358/0x500
> > 
> > Take xp->lock for reading across both calls, so both derivations see the
> > same encap_family. xfrm_policy_walk() already calls dump_sp() under
> > spin_lock_bh(), so the plain reader suffices, as in xfrm_policy_timer().
> > The other callers of this pair are already serialized against migrate by
> > net->xfrm.xfrm_cfg_mutex.
> > 
> > Fixes: 80c9abaabf42 ("[XFRM]: Extension for dynamic update of endpoint address(es)")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Daniel Wade <danjwade95@gmail.com>
> @Steffen: do you prefer we take this one directly into the net tree?

I'm Ok with taking it directly into the net tree. PFKEY
is dead anyway, I plan to remove the implementation at
the beginning of the next year.
Technical Details
Message-ID: <av_zInP3LgU0gdIr@gauss4>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367730-linux-kernel-netdev=dewy.ru
References: <20261114223529.1791-1-danjwade95@gmail.com> <99480e51-50f7-425b-b8e9-95b7734c64bf@redhat.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367730-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: af_key: fix use-after-free in dump_sp() on
 policy migrate
Date: Fri, 20 Nov 2026 08:13:38 +0100
Organization: Usenet Network
Message-ID: <av_zInP3LgU0gdIr@gauss4>
References: <20261114223529.1791-1-danjwade95@gmail.com>
 <99480e51-50f7-425b-b8e9-95b7734c64bf@redhat.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Injection-Info: usenet.network;
	logging-data="3091416"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DxLRXYSQVNiPdQ/sm7cH4Ov16g8= sha256:/lSbxkREFu9gWNfil5buBSQjUERkhQIpLo/fe8XHPMk=
	sha1:2D327EDfy2Z+TyeHaF+625avHaU= sha256:xolrlzgtkb5/A1x/GrR/+J90knOD1LGOnqTD43DxSIQ=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CEDD81158E0; Fri, 20 Nov 2026 10:14:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=secunet.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 5p1Gef9xEMu8;
	Fri, 20 Nov 2026 10:14:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367730-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4B6DF1158DC; Fri, 20 Nov 2026 10:13:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id F3DF7CA08C; Fri, 20 Nov 2026 07:13:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795158830;
	b=3HpgJldhdc0OFvG7QqBUlGa0mZeKJJmu42/71gsLw9fLDA1R+ftIoG+2hbYMNUeK77R+
	 Ou+Fb4Ehd3N1L+1FgS6KdbUkXEmHgmJpSYEYH0YFmn34e7QtLIeqMjhmxzTeEhevhdSCo
	 njm518UBz2F0DxUZ2Z5JK9/M8JIvCd47VWckxQLMhwc5ke3hXIhmwF6ttxneLMKE4boxp
	 Gt+XmmpQtIdDaETTBr1/rmXgyNNtTZK5n69jA6e2NMywU1A9lBCbkkbbc2pNWVJlO606H
	 aIDZhdkffo85Kf8UCiH3TqoJw7wfm7xoc74DyNAmEBR45zpTfZcn6s8cPW4YqXkNHvQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795158830;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:Date:
	 From:To:CC:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:
	 X-ClientProxiedBy;
	bh=LB9wymtVohhmpOcRNEMKuhiXQ1mq5XK/YUMlCRu5VHU=;
	b=lvn0LcecGL3Hxkjej4RPMTCzMiUaZ+lthZrPgL7v/6xuIT8L7s9y8mQ6qHqIXeHzz5X/
	 zhD6FyLTKOchdHZmQCq5gGA3ppAMvOngwXoqNFtxqz3p7BCbypymHPil3nUBSrNgsBuwK
	 9EBHEq+hqifRYP8S1LFvqVC6KeBMQBwYu7FRZUY4kY4ztxBdEG3KoU4LevgVFBrpfb9om
	 1p6YyCyZmddSDE0ZWgABXr4/TGyak2gm6E9dxJ5JxZtshbNagm+NoJvalclhxVT9wCHAH
	 /guKaN8o6bQGS6/QE0/CljG0JzUddBudhknmorkEcG+H+LBg/GwzzD/aHQULd/B3+jw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=SmBCME1G;
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id CA671606A335;
	Fri, 20 Nov 2026 07:13:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=SmBCME1G
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795158825;
	b=fcpp2BfwXDuQ6FTm5KnODejpPoiKd6gazwnnUlJmdg8DebFAQAPht7XuTtkIc9hxZUuq
	 K1WNuq7mtzHlQjmaRRpB5p6CA44ESr7dZD8BiRS3AlrEtGuga3WGcExRGhDf39YRTw3bL
	 JB6DurTWFxZKj+SkG9WhpGOwOHT5o9VCczmaFQgOs9R7O3p5v5v+dSD5xzD+H7TBQtrNJ
	 cjLqHcnkRMFeEgfTevhpD3X6SP8ZH3WlHvTa6fQo8jFHKutsHFC63AJ+FFhPpQeTdF+9b
	 VzacSXGeLbC0NxC+mjCfDoA8dEaFGDm0GLjahJ4FBfRohx//XwPQnJgOSgXPwbDg/nQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795158825;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:Date:From:To:CC:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:
	 X-ClientProxiedBy;
	bh=LB9wymtVohhmpOcRNEMKuhiXQ1mq5XK/YUMlCRu5VHU=;
	b=czUxY0MEaQU61QSrb2uL9VnjhCkguY5vAt5UdTZt7UJkLqY++ZQojWYmaXVjU5hrIK7h
	 TVQvZLC1rt1lzCURDpyd7xBDIqIqqYDrBCScbMw26/+UQ8K7wuQ55q2a/nH9nfjHvgfhN
	 wxJrG1qqAXRoTfYqTpPqjU37HEDLpPGZlV2jV8qS92AkuoTVdRJhOZs/UvZ0coSH7jcJy
	 HsqFn9Km1Tf8hYUNytgJJ3Px5Kigr8t9vrXmVirsc2EQN/DKjs/63nsuo1xSKNUX7c9Vs
	 2zbzqOs/t4xOCWy1MBsGgSw46jhlIMGBqsdnAX0oyv6zB7lnvI3jOkfQVopb3IOw/4A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=SmBCME1G;
	arc=none smtp.remote-ip=62.96.220.36
X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2254F606A320;
	Fri, 20 Nov 2026 07:13:43 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2254F606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com
X-Received: from localhost (localhost [127.0.0.1])
	by mx1.secunet.com (Postfix) with ESMTP id 21E38207D8;
	Fri, 20 Nov 2026 08:13:42 +0100 (CET)
X-Virus-Scanned: by secunet
X-Received: from mx1.secunet.com ([127.0.0.1])
 by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id pKVg5zZ_qty8; Fri, 20 Nov 2026 08:13:41 +0100 (CET)
X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mx1.secunet.com (Postfix) with ESMTPS id 7AE48206D0;
	Fri, 20 Nov 2026 08:13:41 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 7AE48206D0
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1795158821;
	bh=LB9wymtVohhmpOcRNEMKuhiXQ1mq5XK/YUMlCRu5VHU=;
	h=Date:From:To:CC:Subject:References:In-Reply-To:From;
	b=SmBCME1GUjFJo2FT6pN9ojDF62kXxceM1TKgtTlbSlecg90SJiOn45q6Q3s4edxWy
	 CKd9LRdGINW3CRx722ACJByOb9zyHmIZZ1afEtuqLaIZKQFpd2KLAQZ0PQkmipQUF2
	 1ztlZsGDwmqy8j3AJpgsGI6iM/xBSd+pMRHF+s/FcZN/U2EGNVP1rr+W9Mk6dWKQGl
	 QzavQldlzObeOJgXKOap43FKPQnryvXWFDhhEdkyGXE1XU0kAzOQRwTsTMHiHU+DPE
	 0orBFf51TqNt+uAOlIX0eRx2Ry08dPc6pDyg/bij9+qLDuqSBNjQRjeFrIZdBXRlLX
	 xSranQSAfNPoA==
X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Fri, 20 Nov
 2026 08:13:39 +0100
X-Received: (nullmailer pid 1694731 invoked by uid 1000);
	Fri, 20 Nov 2026 07:13:38 -0000
X-CC: Daniel Wade <danjwade95@gmail.com>, Herbert Xu
	<herbert@gondor.apana.org.au>, Eric Dumazet <edumazet@kernel.org>, Jakub
 Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, "David S. Miller"
	<davem@davemloft.net>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <99480e51-50f7-425b-b8e9-95b7734c64bf@redhat.com>
X-ClientProxiedBy: EXCH-03.secunet.de (10.32.0.183) To EXCH-01.secunet.de
 (10.32.0.171)