]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
netfilter: nfnetlink: reset nlh pointer during batch replay
authorFernando Fernandez Mancera <fmancera@suse.de>
Fri, 19 Sep 2025 12:40:43 +0000 (14:40 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Oct 2025 10:00:16 +0000 (12:00 +0200)
[ Upstream commit 09efbac953f6f076a07735f9ba885148d4796235 ]

During a batch replay, the nlh pointer is not reset until the parsing of
the commands. Since commit bf2ac490d28c ("netfilter: nfnetlink: Handle
ACK flags for batch messages") that is problematic as the condition to
add an ACK for batch begin will evaluate to true even if NLM_F_ACK
wasn't used for batch begin message.

If there is an error during the command processing, netlink is sending
an ACK despite that. This misleads userspace tools which think that the
return code was 0. Reset the nlh pointer to the original one when a
replay is triggered.

Fixes: bf2ac490d28c ("netfilter: nfnetlink: Handle ACK flags for batch messages")
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nfnetlink.c

index 7784ec094097bc7166cc2065229d36363ece2aa4..f12d0d229aaa5334c14ed7ad43a332ca16003243 100644 (file)
@@ -376,6 +376,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
        const struct nfnetlink_subsystem *ss;
        const struct nfnl_callback *nc;
        struct netlink_ext_ack extack;
+       struct nlmsghdr *onlh = nlh;
        LIST_HEAD(err_list);
        u32 status;
        int err;
@@ -386,6 +387,7 @@ replay:
        status = 0;
 replay_abort:
        skb = netlink_skb_clone(oskb, GFP_KERNEL);
+       nlh = onlh;
        if (!skb)
                return netlink_ack(oskb, nlh, -ENOMEM, NULL);