diff mbox series

[net,3/3] netfilter: flowtable: validate vlan header

Message ID 20240822001707.2116-4-pablo@netfilter.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net,1/3] netfilter: nft_counter: Disable BH in nft_counter_offload_stats(). | expand

Checks

Context Check Description
netdev/series_format success Pull request is its own cover letter
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: coreteam@netfilter.org kadlec@netfilter.org
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-22--03-00 (tests: 711)

Commit Message

Pablo Neira Ayuso Aug. 22, 2024, 12:17 a.m. UTC
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>
---
 net/netfilter/nf_flow_table_inet.c | 3 +++
 net/netfilter/nf_flow_table_ip.c   | 3 +++
 2 files changed, 6 insertions(+)

Comments

Eric Dumazet Aug. 22, 2024, 6:39 a.m. UTC | #1
On Thu, Aug 22, 2024 at 2:17 AM Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>
> 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>
> ---
>  net/netfilter/nf_flow_table_inet.c | 3 +++
>  net/netfilter/nf_flow_table_ip.c   | 3 +++
>  2 files changed, 6 insertions(+)
>
> diff --git a/net/netfilter/nf_flow_table_inet.c b/net/netfilter/nf_flow_table_inet.c
> index 88787b45e30d..dd9a392052ee 100644
> --- a/net/netfilter/nf_flow_table_inet.c
> +++ b/net/netfilter/nf_flow_table_inet.c
> @@ -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, VLAN_HLEN))
> +                       return NF_ACCEPT;
> +
>                 veth = (struct vlan_ethhdr *)skb_mac_header(skb);

Is skb_mac_header(skb) always pointing at skb->data - 14 at this stage ?

Otherwise, using

  if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth))  would be safer.
Pablo Neira Ayuso Aug. 22, 2024, 10:21 a.m. UTC | #2
On Thu, Aug 22, 2024 at 08:39:56AM +0200, Eric Dumazet wrote:
> On Thu, Aug 22, 2024 at 2:17 AM Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> >
> > 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>
> > ---
> >  net/netfilter/nf_flow_table_inet.c | 3 +++
> >  net/netfilter/nf_flow_table_ip.c   | 3 +++
> >  2 files changed, 6 insertions(+)
> >
> > diff --git a/net/netfilter/nf_flow_table_inet.c b/net/netfilter/nf_flow_table_inet.c
> > index 88787b45e30d..dd9a392052ee 100644
> > --- a/net/netfilter/nf_flow_table_inet.c
> > +++ b/net/netfilter/nf_flow_table_inet.c
> > @@ -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, VLAN_HLEN))
> > +                       return NF_ACCEPT;
> > +
> >                 veth = (struct vlan_ethhdr *)skb_mac_header(skb);
> 
> Is skb_mac_header(skb) always pointing at skb->data - 14 at this stage ?
> 
> Otherwise, using
> 
>   if (!pskb_may_pull(skb, skb_mac_offset(skb) + sizeof(*veth))  would be safer.

That looks consistent. Done and I just sent a new PR. Thanks.
diff mbox series

Patch

diff --git a/net/netfilter/nf_flow_table_inet.c b/net/netfilter/nf_flow_table_inet.c
index 88787b45e30d..dd9a392052ee 100644
--- a/net/netfilter/nf_flow_table_inet.c
+++ b/net/netfilter/nf_flow_table_inet.c
@@ -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, VLAN_HLEN))
+			return NF_ACCEPT;
+
 		veth = (struct vlan_ethhdr *)skb_mac_header(skb);
 		proto = veth->h_vlan_encapsulated_proto;
 		break;
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index c2c005234dcd..9a9031e9ea1c 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -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, VLAN_HLEN))
+			return false;
+
 		veth = (struct vlan_ethhdr *)skb_mac_header(skb);
 		if (veth->h_vlan_encapsulated_proto == proto) {
 			*offset += VLAN_HLEN;