Skip to content

Commit 34fad54

Browse files
Eric Dumazetdavem330
authored andcommitted
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: a6e544b ("flow_dissector: Jump to exit code in __skb_flow_dissect") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Yibin Yang <[email protected] Acked-by: Alexander Duyck <[email protected]> Acked-by: Willem de Bruijn <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 79774d6 commit 34fad54

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/core/flow_dissector.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
122122
struct flow_dissector_key_keyid *key_keyid;
123123
bool skip_vlan = false;
124124
u8 ip_proto = 0;
125-
bool ret = false;
125+
bool ret;
126126

127127
if (!data) {
128128
data = skb->data;
@@ -549,12 +549,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
549549
out_good:
550550
ret = true;
551551

552-
out_bad:
552+
key_control->thoff = (u16)nhoff;
553+
out:
553554
key_basic->n_proto = proto;
554555
key_basic->ip_proto = ip_proto;
555-
key_control->thoff = (u16)nhoff;
556556

557557
return ret;
558+
559+
out_bad:
560+
ret = false;
561+
key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
562+
goto out;
558563
}
559564
EXPORT_SYMBOL(__skb_flow_dissect);
560565

0 commit comments

Comments
 (0)