2018-04-26 14:14:21

by Ahmed Abdelsalam

[permalink] [raw]
Subject: [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel"

The seg6_make_flowlabel() is used by seg6_do_srh_encap() to compute the
flowlabel from a given skb. It relies on skb_get_hash() which eventually
calls __skb_flow_dissect() to extract the flow_keys struct values from
the skb.

In case of IPv4 traffic, calling seg6_make_flowlabel() after skb_push(),
skb_reset_network_header(), and skb_mac_header_rebuild() will results in
flow_keys struct of all key values set to zero.

This patch calls seg6_make_flowlabel() before resetting the headers of skb
to get the right key values.

Extracted Key values are based on the type inner packet as follows:
1) IPv6 traffic: src_IP, dst_IP, L4 proto, and flowlabel of inner packet.
2) IPv4 traffic: src_IP, dst_IP, L4 proto, src_port, and dst_port
3) L2 traffic: depends on what kind of traffic carried into the L2
frame. IPv6 and IPv4 traffic works as discussed 1) and 2)

Signed-off-by: Ahmed Abdelsalam <[email protected]>
---
net/ipv6/seg6_iptunnel.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index 9898926..0df83c0 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -119,6 +119,9 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
int hdrlen, tot_len, err;
__be32 flowlabel;

+ inner_hdr = ipv6_hdr(skb);
+ flowlabel = seg6_make_flowlabel(net, skb, inner_hdr);
+
hdrlen = (osrh->hdrlen + 1) << 3;
tot_len = hdrlen + sizeof(*hdr);

@@ -126,8 +129,6 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
if (unlikely(err))
return err;

- inner_hdr = ipv6_hdr(skb);
-
skb_push(skb, tot_len);
skb_reset_network_header(skb);
skb_mac_header_rebuild(skb);
@@ -138,7 +139,6 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
* decapsulation will overwrite inner hlim with outer hlim
*/

- flowlabel = seg6_make_flowlabel(net, skb, inner_hdr);
if (skb->protocol == htons(ETH_P_IPV6)) {
ip6_flow_hdr(hdr, ip6_tclass(ip6_flowinfo(inner_hdr)),
flowlabel);
--
2.1.4



2018-04-27 18:00:39

by David Miller

[permalink] [raw]
Subject: Re: [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel"

From: Ahmed Abdelsalam <[email protected]>
Date: Thu, 26 Apr 2018 16:11:11 +0200

> @@ -119,6 +119,9 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
> int hdrlen, tot_len, err;
> __be32 flowlabel;
>
> + inner_hdr = ipv6_hdr(skb);

You have to make this assignment after, not before, the skb_cow_header()
call. Otherwise this point can be pointing to freed up memory.

2018-04-28 10:22:14

by Ahmed Abdelsalam

[permalink] [raw]
Subject: Re: [net-next] ipv6: sr: Extract the right key values for "seg6_make_flowlabel"

On Fri, 27 Apr 2018 13:59:07 -0400 (EDT)
David Miller <[email protected]> wrote:

> From: Ahmed Abdelsalam <[email protected]>
> Date: Thu, 26 Apr 2018 16:11:11 +0200
>
> > @@ -119,6 +119,9 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
> > int hdrlen, tot_len, err;
> > __be32 flowlabel;
> >
> > + inner_hdr = ipv6_hdr(skb);
>
> You have to make this assignment after, not before, the skb_cow_header()
> call. Otherwise this point can be pointing to freed up memory.

Ok!
I fixed and sent you a v2 of the patch.

--
Ahmed Abdelsalam <[email protected]>