netfilter: fix regression in looped (broad|multi)cast's MAC handling
authorIgnacy Gawędzki <ignacy.gawedzki@green-communications.fr>
Fri, 10 Dec 2021 15:31:27 +0000 (16:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Dec 2021 11:25:55 +0000 (12:25 +0100)
[ Upstream commit ebb966d3bdfed581ecccbb4a7432341baf7619b4 ]

In commit 5648b5e1169f ("netfilter: nfnetlink_queue: fix OOB when mac
header was cleared"), the test for non-empty MAC header introduced in
commit 2c38de4c1f8da7 ("netfilter: fix looped (broad|multi)cast's MAC
handling") has been replaced with a test for a set MAC header.

This breaks the case when the MAC header has been reset (using
skb_reset_mac_header), as is the case with looped-back multicast
packets.  As a result, the packets ending up in NFQUEUE get a bogus
hwaddr interpreted from the first bytes of the IP header.

This patch adds a test for a non-empty MAC header in addition to the
test for a set MAC header.  The same two tests are also implemented in
nfnetlink_log.c, where the initial code of commit 2c38de4c1f8da7
("netfilter: fix looped (broad|multi)cast's MAC handling") has not been
touched, but where supposedly the same situation may happen.

Fixes: 5648b5e1169f ("netfilter: nfnetlink_queue: fix OOB when mac header was cleared")
Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nfnetlink_log.c
net/netfilter/nfnetlink_queue.c

index b35e8d9a5b37ec14cc6eb39e55d0c1ade1791da8..33c13edbca4bbf9e9406bf3bc86b80d0bdf8ed9e 100644 (file)
@@ -557,7 +557,8 @@ __build_packet_message(struct nfnl_log_net *log,
                goto nla_put_failure;
 
        if (indev && skb->dev &&
-           skb->mac_header != skb->network_header) {
+           skb_mac_header_was_set(skb) &&
+           skb_mac_header_len(skb) != 0) {
                struct nfulnl_msg_packet_hw phw;
                int len;
 
index 98994fe677fe940e585378c56741662fec5e016c..b0358f30947ea80b6aa715bd515d652538ee785e 100644 (file)
@@ -562,7 +562,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
                goto nla_put_failure;
 
        if (indev && entskb->dev &&
-           skb_mac_header_was_set(entskb)) {
+           skb_mac_header_was_set(entskb) &&
+           skb_mac_header_len(entskb) != 0) {
                struct nfqnl_msg_packet_hw phw;
                int len;