From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D85E2E093A; Mon, 20 Apr 2026 15:49:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700168; cv=none; b=YaIYzygbvJsJfqYEfZqExGVx7+JgiZmt7afSfSJjp09BAHwn1vxgueQQe5Te1VikdSXDXa222YLo9ZoGjMfxdVncj40xQcdzijxmmiRy9iITqIPga/PlJpgeB86iQYvLBQw86bMQA2i4GOHf6qtAVaoa+rikJeWqt6zN2TH6ehE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700168; c=relaxed/simple; bh=GCb12z3+6p3VxUnetaFsvduhDsLkDBAh6eBfl1Zve8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b6dEom6NlghH+5ZRo+hh4f0Jb5n/3Sj/+CfkJf3zmbz5vdnrmSNqtloY1LOtMveln4VN5bgB2lClZfgowYEi0AcRdLWoNdgV9Gios92/pMYVHExhioICjGKntfHarJ5JPQw41rgJwt3/rnmjUcJJZ+JkWHaJ2xvc/ZjRL3BQzq8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sEaSnafv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sEaSnafv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 755F9C2BCB6; Mon, 20 Apr 2026 15:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776700167; bh=GCb12z3+6p3VxUnetaFsvduhDsLkDBAh6eBfl1Zve8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEaSnafvkUJVfeq8X9lO9g7gi9tEuHCoPqFQcXUUY0vPSq6JH/yu5g9dFV0lkj1zm rywlWTXt1uTdWutmc/kbuf5WERz72nSuHBsVsG8OWg1JgcyjMjsmDhlynwpnLpiMb6 /oA9Z8YhAdg1KQrdz+OkuGzebgyI5MOIcpkAi0Oo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Keenan Dong , Steffen Klassert , Sasha Levin Subject: [PATCH 6.19 067/220] xfrm: account XFRMA_IF_ID in aevent size calculation Date: Mon, 20 Apr 2026 17:40:08 +0200 Message-ID: <20260420153936.453421052@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260420153934.013228280@linuxfoundation.org> References: <20260420153934.013228280@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Keenan Dong [ Upstream commit 7081d46d32312f1a31f0e0e99c6835a394037599 ] xfrm_get_ae() allocates the reply skb with xfrm_aevent_msgsize(), then build_aevent() appends attributes including XFRMA_IF_ID when x->if_id is set. xfrm_aevent_msgsize() does not include space for XFRMA_IF_ID. For states with if_id, build_aevent() can fail with -EMSGSIZE and hit BUG_ON(err < 0) in xfrm_get_ae(), turning a malformed netlink interaction into a kernel panic. Account XFRMA_IF_ID in the size calculation unconditionally and replace the BUG_ON with normal error unwinding. Fixes: 7e6526404ade ("xfrm: Add a new lookup key to match xfrm interfaces.") Reported-by: Keenan Dong Signed-off-by: Keenan Dong Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 306e4f65ce264..1ddcf2a1eff7a 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -2668,7 +2668,8 @@ static inline unsigned int xfrm_aevent_msgsize(struct xfrm_state *x) + nla_total_size(4) /* XFRM_AE_RTHR */ + nla_total_size(4) /* XFRM_AE_ETHR */ + nla_total_size(sizeof(x->dir)) /* XFRMA_SA_DIR */ - + nla_total_size(4); /* XFRMA_SA_PCPU */ + + nla_total_size(4) /* XFRMA_SA_PCPU */ + + nla_total_size(sizeof(x->if_id)); /* XFRMA_IF_ID */ } static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct km_event *c) @@ -2780,7 +2781,12 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, c.portid = nlh->nlmsg_pid; err = build_aevent(r_skb, x, &c); - BUG_ON(err < 0); + if (err < 0) { + spin_unlock_bh(&x->lock); + xfrm_state_put(x); + kfree_skb(r_skb); + return err; + } err = nlmsg_unicast(net->xfrm.nlsk, r_skb, NETLINK_CB(skb).portid); spin_unlock_bh(&x->lock); -- 2.53.0