From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E1C13F3282 for ; Tue, 4 Aug 2026 06:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785823841; cv=none; b=iKL4asU9/u6WZEosXXb6D57Otv3tW65wO/z6v2mCG41mZA4a19+kz0pfJ9mXg7xFBFdCHniubPOiUwC7DoWojmlYiIGK/YCQ+qujP56hYqky0cigJ4/E2Wzlp3XpBkEwz7IwtV5YrzwILM/BbwNdYuH35CtNSdFdEAcefsvQ0X0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785823841; c=relaxed/simple; bh=2ssuQ+04nuLTDZGNqzMTsPtwevqZk/aT3YoTKb0B1Ck=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=aQlfdAh+m/egqXXbwI7sAJwcTpFXMDONwpjbyWzJle/egjaByv0ZFRRPdIu4qRWOcRwRRynbPl39AYYozW5RmcyRTcql7fBXndRD3s+ARj2Mtbi9bhc6+rk005DPBaKDP+ppgnv+eDvAC84k4qg7znDhzfEx+o0dRlPkhp7BTLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=AZXORupP; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="AZXORupP" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-92e99ef0902so215213885a.2 for ; Mon, 03 Aug 2026 23:10:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1785823839; x=1786428639; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=2xu34PAC/Hx6+EVv4uPY0+/AxgtysgEZZSu+zkxMA6E=; b=AZXORupPXEyW5UejGOB/TBTu9UB61VS2/mol9se+DJP7mOUzR7oqCkDiTh93sjEQFG f68nRRihEJLXmmvrGCf998NYVwA6HJj3eHEd57dBKETkJAbFYE6NNDqPIlYXx3/ZUrbS x550maXC+Zd2SNAF4omT1gJLNymP7N3pFPNONQJzitbaGZrW7DBX8GpO+YxjgKHxALiH nvH7fFEY/yh2AuRBgpQtO+UnvaBUjBTi+S5pKAkGKIXe64e+QsmnnTjaMCh4reRKm64e 84jMhEVSS2VE57Nnhqwb6vc4tCq+uViwbWkLJeSX5hh4bMK2cWmYEX7WnqqMjcd6gmpl P+yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785823839; x=1786428639; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2xu34PAC/Hx6+EVv4uPY0+/AxgtysgEZZSu+zkxMA6E=; b=o6i43TKSWM4ECDFdNpWQ/RIievlsAlMTC1K3+pjTi3OqjOuczttNBNoNb3ol53WWP8 1PFuSyM3NBqcaw3xFaDcKg5dyE9u9dqWeRxSvIytLrjjh4c3bTVx8Cypa8yG56+Nd8Gt 7Jss5yBh9RAAIF25BGiiUfDfhOKrp4A0Al7xZAoBShYQ8vuzr33s3g/VAs8shbLz3j++ +4hobH7AIhxqVfyv9PyGj8lGvHK/lO3y3otBlEh4fFt4N20jmGN5ft7fk220WsVELIoo 3eT3qSpzajtWsgO/I+u6yU42u4rJ9LjRjnLyZAbQslK+IzpGoT7vttTFjY+CNFGkHwpS azww== X-Forwarded-Encrypted: i=1; AHgh+RqHYIHG+fVo6TQwMH42DiLtBEbgg2gMOwYx0J/nfqmRJK9hvM7rLd5IAeXLOyXswuY5Y8vh6vzTcSehksY=@vger.kernel.org X-Gm-Message-State: AOJu0Yya22ypc0e5IkZdiQq7tNKOh8ZF2PsBLktpBJiJAIvVFftETbZA nhqhRzetlPFSZpfCjXxV7B/lmpI9amYtEURtF1edW0spfPx0Ps9nUqLuE+pmhDcnZjo= X-Gm-Gg: AR+sD11cMGo5b3TMcVjDQQhT+0/GXg6LMWs48zRMERYJtrr/ce/TNsXPFHKK/NUl+Mo puwWS6//z3DuOKz+fNGSbpCxvwnC5xrfDA9lji0CteD7D47PdvmhItqkjQKQWhXGj1juN4PW8jZ in3wCMB2uzgQSfFxU31XW9DyX0WVFLD/mwnzLCrkHx3R5nkRtnwGVA6D2bQEUsXkQsy49C5jxm9 dop1QD6s3vhAuz5oUwWIV5AgCs6K+M7nkTPeoBkz/u3XzfLfWzFvcNBWrgfqzT79uA+avvdt19h ScaoLNoulwc4oZ4eTNOuJYf+bru0Z/pqnZir1x9DGhA2mhYPntZCigmSdbrk8YLU0B6fRo3vs7R LBOpAtI9DuF71DYRKggbF/EIDRMgJi4HefmnrDrbZnyZAyBI4g343LyvpmKwZuc3VhNGnPHp+JG SYQqouWCDdw5cWyP+c1+tTkuOHyQXpTMHWGypvHtHgh2b6cZ9Swm18XegpEh3leu+8UQ== X-Received: by 2002:a05:620a:890a:b0:92e:eeb6:b879 with SMTP id af79cd13be357-934a0aa8aa1mr2755397885a.41.1785823839294; Mon, 03 Aug 2026 23:10:39 -0700 (PDT) Received: from localhost ([146.190.222.192]) by smtp.gmail.com with UTF8SMTPSA id af79cd13be357-936418ae7b9sm3848785a.28.2026.08.03.23.10.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Aug 2026 23:10:39 -0700 (PDT) From: David Lee To: steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: Kyle Zeng , Dominik 'Disconnect3d' Czarnota , Sven Eckelmann , horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, David Lee Subject: [PATCH ipsec v2] xfrm: fix compat ALLOCSPI request use-after-free Date: Tue, 4 Aug 2026 06:10:37 +0000 Message-ID: <20260804061038.711373-1-david.lee@trailofbits.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kyle Zeng xfrm_state_netlink() builds the ALLOCSPI response with dump_one_state(), which already calls alloc_compat() with the response skb and header. xfrm_alloc_userspi() then calls alloc_compat() again, but passes the original request skb and its header. For a compat request, the translator therefore interprets the 228-byte compat xfrm_userspi_info as the 232-byte native layout and reads four bytes past the declared payload. It also publishes the translated child through the request's frag_list. A multicast clone of the request shares skb_shared_info and can observe that child. xfrm_user_rcv_msg() frees it after the request handler returns, racing a compat receiver which may still be copying from it and resulting in a use-after-free. Remove the redundant conversion. The response keeps its correct compat translation from dump_one_state(), and no child is attached to the inbound request. Fixes: 5f3eea6b7e8f ("xfrm/compat: Attach xfrm dumps to 64=>32 bit translator") Assisted-by: Codex:gpt-5.6-sol Codex:gpt-5.5-cyber Signed-off-by: Kyle Zeng Co-developed-by: David Lee Signed-off-by: David Lee --- Changes in v2: - Add the ipsec tree prefix to the subject. - Restore Kyle Zeng as the patch author and correct the sign-off chain. - Move the research credit below the commit-message separator. v1: https://lore.kernel.org/netdev/20260731140658.566571-1-david.lee@trailofbits.com/ Bug found and triaged by OpenAI Security Research and validated by Trail of Bits. Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can share if needed. net/xfrm/xfrm_user.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index d6db63304ba6bd5bbd9c09c665170936e1107ced..a7f35a123648d3946aae88674c7bead5666c9eb3 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -1877,7 +1877,6 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, struct net *net = sock_net(skb->sk); struct xfrm_state *x; struct xfrm_userspi_info *p; - struct xfrm_translator *xtr; struct sk_buff *resp_skb; xfrm_address_t *daddr; int family; @@ -1943,17 +1942,6 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } - xtr = xfrm_get_translator(); - if (xtr) { - err = xtr->alloc_compat(skb, nlmsg_hdr(skb)); - - xfrm_put_translator(xtr); - if (err) { - kfree_skb(resp_skb); - goto out; - } - } - err = nlmsg_unicast(xfrm_net_nlsk(net, skb), resp_skb, NETLINK_CB(skb).portid); out: -- 2.53.0