]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
netfilter: flowtable: validate vlan header
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 13 Aug 2024 10:39:46 +0000 (12:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Aug 2024 15:36:00 +0000 (17:36 +0200)
[ Upstream commit 6ea14ccb60c8ab829349979b22b58a941ec4a3ee ]

Ensure there is sufficient room to access the protocol field of the
VLAN header, validate it once before the flowtable lookup.

=====================================================
BUG: KMSAN: uninit-value in nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32
 nf_flow_offload_inet_hook+0x45a/0x5f0 net/netfilter/nf_flow_table_inet.c:32
 nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline]
 nf_hook_slow+0xf4/0x400 net/netfilter/core.c:626
 nf_hook_ingress include/linux/netfilter_netdev.h:34 [inline]
 nf_ingress net/core/dev.c:5440 [inline]

Fixes: 4cd91f7c290f ("netfilter: flowtable: add vlan support")
Reported-by: syzbot+8407d9bb88cd4c6bf61a@syzkaller.appspotmail.com
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nf_flow_table_inet.c
net/netfilter/nf_flow_table_ip.c

index 6eef15648b7b0853fb249288bf4545dca3a2cf85..b0f199171932414bdeddc2f7e33a5cd469cb10c5 100644 (file)
@@ -17,6 +17,9 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
 
        switch (skb->protocol) {
        case htons(ETH_P_8021Q):
+               if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth)))
+                       return NF_ACCEPT;
+
                veth = (struct vlan_ethhdr *)skb_mac_header(skb);
                proto = veth->h_vlan_encapsulated_proto;
                break;
index c2c005234dcd385a1377f3ab34c27f82d9b18b0c..98edcaa37b38d46f8236dd5ef1dff569581b8777 100644 (file)
@@ -281,6 +281,9 @@ static bool nf_flow_skb_encap_protocol(struct sk_buff *skb, __be16 proto,
 
        switch (skb->protocol) {
        case htons(ETH_P_8021Q):
+               if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth)))
+                       return false;
+
                veth = (struct vlan_ethhdr *)skb_mac_header(skb);
                if (veth->h_vlan_encapsulated_proto == proto) {
                        *offset += VLAN_HLEN;