Skip to content

Commit eefed76

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: policy: fix layer 4 flowi decoding
The commit shipped with two bugs: fl4->fl4_icmp_type = flkeys->icmp.type; fl4->fl4_icmp_type = flkeys->icmp.code; ~~~~ should have been "code". But the more severe bug is that I got fooled by flowi member defines: fl4_icmp_type, fl4_gre_key and fl4_dport share the same union/address. Fix typo and make gre/icmp key setting depend on the l4 protocol. Fixes: 7a02070 ("xfrm: policy: replace session decode with flow dissector") Reported-and-tested-by: Antony Antony <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 53a5b4f commit eefed76

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

net/xfrm/xfrm_policy.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,11 +3400,18 @@ decode_session4(const struct xfrm_flow_keys *flkeys, struct flowi *fl, bool reve
34003400
fl4->fl4_dport = flkeys->ports.dst;
34013401
}
34023402

3403+
switch (flkeys->basic.ip_proto) {
3404+
case IPPROTO_GRE:
3405+
fl4->fl4_gre_key = flkeys->gre.keyid;
3406+
break;
3407+
case IPPROTO_ICMP:
3408+
fl4->fl4_icmp_type = flkeys->icmp.type;
3409+
fl4->fl4_icmp_code = flkeys->icmp.code;
3410+
break;
3411+
}
3412+
34033413
fl4->flowi4_proto = flkeys->basic.ip_proto;
34043414
fl4->flowi4_tos = flkeys->ip.tos;
3405-
fl4->fl4_icmp_type = flkeys->icmp.type;
3406-
fl4->fl4_icmp_type = flkeys->icmp.code;
3407-
fl4->fl4_gre_key = flkeys->gre.keyid;
34083415
}
34093416

34103417
#if IS_ENABLED(CONFIG_IPV6)
@@ -3427,10 +3434,17 @@ decode_session6(const struct xfrm_flow_keys *flkeys, struct flowi *fl, bool reve
34273434
fl6->fl6_dport = flkeys->ports.dst;
34283435
}
34293436

3437+
switch (flkeys->basic.ip_proto) {
3438+
case IPPROTO_GRE:
3439+
fl6->fl6_gre_key = flkeys->gre.keyid;
3440+
break;
3441+
case IPPROTO_ICMPV6:
3442+
fl6->fl6_icmp_type = flkeys->icmp.type;
3443+
fl6->fl6_icmp_code = flkeys->icmp.code;
3444+
break;
3445+
}
3446+
34303447
fl6->flowi6_proto = flkeys->basic.ip_proto;
3431-
fl6->fl6_icmp_type = flkeys->icmp.type;
3432-
fl6->fl6_icmp_type = flkeys->icmp.code;
3433-
fl6->fl6_gre_key = flkeys->gre.keyid;
34343448
}
34353449
#endif
34363450

0 commit comments

Comments
 (0)