Commit 34fad54c authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: __skb_flow_dissect() must cap its return value

After Tom patch, thoff field could point past the end of the buffer,
this could fool some callers.

If an skb was provided, skb->len should be the upper limit.
If not, hlen is supposed to be the upper limit.

Fixes: a6e544b0 ("flow_dissector: Jump to exit code in __skb_flow_dissect")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reported-by: Yibin Yang <yibyang@cisco.com
Acked-by: default avatarAlexander Duyck <alexander.h.duyck@intel.com>
Acked-by: default avatarWillem de Bruijn <willemb@google.com>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 79774d6b
...@@ -122,7 +122,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -122,7 +122,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
struct flow_dissector_key_keyid *key_keyid; struct flow_dissector_key_keyid *key_keyid;
bool skip_vlan = false; bool skip_vlan = false;
u8 ip_proto = 0; u8 ip_proto = 0;
bool ret = false; bool ret;
if (!data) { if (!data) {
data = skb->data; data = skb->data;
...@@ -549,12 +549,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -549,12 +549,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
out_good: out_good:
ret = true; ret = true;
out_bad: key_control->thoff = (u16)nhoff;
out:
key_basic->n_proto = proto; key_basic->n_proto = proto;
key_basic->ip_proto = ip_proto; key_basic->ip_proto = ip_proto;
key_control->thoff = (u16)nhoff;
return ret; return ret;
out_bad:
ret = false;
key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
goto out;
} }
EXPORT_SYMBOL(__skb_flow_dissect); EXPORT_SYMBOL(__skb_flow_dissect);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment