Skip to content

Commit a6e544b

Browse files
tomratbertdavem330
authored andcommitted
flow_dissector: Jump to exit code in __skb_flow_dissect
Instead of returning immediately (on a parsing failure for instance) we jump to cleanup code. This always sets protocol values in key_control (even on a failure there is still valid information in the key_tags that was set before the problem was hit). Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c6cc1ca commit a6e544b

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

net/core/flow_dissector.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
130130
struct flow_dissector_key_tags *key_tags;
131131
struct flow_dissector_key_keyid *key_keyid;
132132
u8 ip_proto = 0;
133+
bool ret = false;
133134

134135
if (!data) {
135136
data = skb->data;
@@ -171,7 +172,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
171172
ip:
172173
iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
173174
if (!iph || iph->ihl < 5)
174-
return false;
175+
goto out_bad;
175176
nhoff += iph->ihl * 4;
176177

177178
ip_proto = iph->protocol;
@@ -197,7 +198,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
197198
ipv6:
198199
iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
199200
if (!iph)
200-
return false;
201+
goto out_bad;
201202

202203
ip_proto = iph->nexthdr;
203204
nhoff += sizeof(struct ipv6hdr);
@@ -234,7 +235,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
234235

235236
vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan);
236237
if (!vlan)
237-
return false;
238+
goto out_bad;
238239

239240
if (skb_flow_dissector_uses_key(flow_dissector,
240241
FLOW_DISSECTOR_KEY_VLANID)) {
@@ -256,7 +257,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
256257
} *hdr, _hdr;
257258
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
258259
if (!hdr)
259-
return false;
260+
goto out_bad;
260261
proto = hdr->proto;
261262
nhoff += PPPOE_SES_HLEN;
262263
switch (proto) {
@@ -265,7 +266,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
265266
case htons(PPP_IPV6):
266267
goto ipv6;
267268
default:
268-
return false;
269+
goto out_bad;
269270
}
270271
}
271272
case htons(ETH_P_TIPC): {
@@ -275,9 +276,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
275276
} *hdr, _hdr;
276277
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
277278
if (!hdr)
278-
return false;
279-
key_basic->n_proto = proto;
280-
key_control->thoff = (u16)nhoff;
279+
goto out_bad;
281280

282281
if (skb_flow_dissector_uses_key(flow_dissector,
283282
FLOW_DISSECTOR_KEY_TIPC_ADDRS)) {
@@ -287,7 +286,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
287286
key_addrs->tipcaddrs.srcnode = hdr->srcnode;
288287
key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC_ADDRS;
289288
}
290-
return true;
289+
goto out_good;
291290
}
292291

293292
case htons(ETH_P_MPLS_UC):
@@ -297,7 +296,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
297296
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data,
298297
hlen, &_hdr);
299298
if (!hdr)
300-
return false;
299+
goto out_bad;
301300

302301
if ((ntohl(hdr[0].entry) & MPLS_LS_LABEL_MASK) >>
303302
MPLS_LS_LABEL_SHIFT == MPLS_LABEL_ENTROPY) {
@@ -310,21 +309,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
310309
htonl(MPLS_LS_LABEL_MASK);
311310
}
312311

313-
key_basic->n_proto = proto;
314-
key_basic->ip_proto = ip_proto;
315-
key_control->thoff = (u16)nhoff;
316-
317-
return true;
312+
goto out_good;
318313
}
319314

320-
return true;
315+
goto out_good;
321316
}
322317

323318
case htons(ETH_P_FCOE):
324319
key_control->thoff = (u16)(nhoff + FCOE_HEADER_LEN);
325320
/* fall through */
326321
default:
327-
return false;
322+
goto out_bad;
328323
}
329324

330325
ip_proto_again:
@@ -337,7 +332,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
337332

338333
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
339334
if (!hdr)
340-
return false;
335+
goto out_bad;
341336
/*
342337
* Only look inside GRE if version zero and no
343338
* routing
@@ -357,7 +352,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
357352
data, hlen, &_keyid);
358353

359354
if (!keyid)
360-
return false;
355+
goto out_bad;
361356

362357
if (skb_flow_dissector_uses_key(flow_dissector,
363358
FLOW_DISSECTOR_KEY_GRE_KEYID)) {
@@ -378,7 +373,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
378373
sizeof(_eth),
379374
data, hlen, &_eth);
380375
if (!eth)
381-
return false;
376+
goto out_bad;
382377
proto = eth->h_proto;
383378
nhoff += sizeof(*eth);
384379
}
@@ -395,7 +390,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
395390
opthdr = __skb_header_pointer(skb, nhoff, sizeof(_opthdr),
396391
data, hlen, &_opthdr);
397392
if (!opthdr)
398-
return false;
393+
goto out_bad;
399394

400395
ip_proto = opthdr[0];
401396
nhoff += (opthdr[1] + 1) << 3;
@@ -415,10 +410,6 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
415410
break;
416411
}
417412

418-
key_basic->n_proto = proto;
419-
key_basic->ip_proto = ip_proto;
420-
key_control->thoff = (u16)nhoff;
421-
422413
if (skb_flow_dissector_uses_key(flow_dissector,
423414
FLOW_DISSECTOR_KEY_PORTS)) {
424415
key_ports = skb_flow_dissector_target(flow_dissector,
@@ -428,7 +419,15 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
428419
data, hlen);
429420
}
430421

431-
return true;
422+
out_good:
423+
ret = true;
424+
425+
out_bad:
426+
key_basic->n_proto = proto;
427+
key_basic->ip_proto = ip_proto;
428+
key_control->thoff = (u16)nhoff;
429+
430+
return ret;
432431
}
433432
EXPORT_SYMBOL(__skb_flow_dissect);
434433

0 commit comments

Comments
 (0)