]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
xfrm: account XFRMA_IF_ID in aevent size calculation
authorKeenan Dong <keenanat2000@gmail.com>
Thu, 26 Mar 2026 12:36:39 +0000 (20:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Apr 2026 11:30:35 +0000 (13:30 +0200)
[ 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 <keenanat2000@gmail.com>
Signed-off-by: Keenan Dong <keenanat2000@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/xfrm/xfrm_user.c

index 306e4f65ce264c3cd10f3a4e49787aa21afef84b..1ddcf2a1eff7a58f4f421d6926e0c94feeeda683 100644 (file)
@@ -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);