Netdev List
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Martin KaFai Lau <kafai@fb.com>, Mathieu Xhonneux <m.xhonneux@gmail.com>
Cc: netdev@vger.kernel.org, alexei.starovoitov@gmail.com
Subject: Re: [PATCH bpf-next] bpf: add End.DT6 action to bpf_lwt_seg6_action helper
Date: Wed, 25 Jul 2018 07:40:14 +0200	[thread overview]
Message-ID: <3219cdfd-a6b5-8db7-a397-891e6d017d89@iogearbox.net> (raw)
In-Reply-To: <20180724171423.xjm4ikr6nfhkisms@kafai-mbp>

On 07/24/2018 07:14 PM, Martin KaFai Lau wrote:
> On Tue, Jul 24, 2018 at 04:59:54PM +0000, Mathieu Xhonneux wrote:
>> The seg6local LWT provides the End.DT6 action, which allows to
>> decapsulate an outer IPv6 header containing a Segment Routing Header
>> (SRH), full specification is available here:
>>
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__tools.ietf.org_html_draft-2Dfilsfils-2Dspring-2Dsrv6-2Dnetwork-2Dprogramming-2D05&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=VQnoQ7LvghIj0gVEaiQSUw&m=c61PGnhPMmCUcL5lpyBsxOmsBU2mU5KFY0-Ioo-pBC4&s=mzShtRc5ofzfknAuqoehbGN1ifA17aKihiVLJVfkuZ8&e=
>>
>> This patch adds this action now to the seg6local BPF
>> interface. Since it is not mandatory that the inner IPv6 header also
>> contains a SRH, seg6_bpf_srh_state has been extended with a pointer to
>> a possible SRH of the outermost IPv6 header. This helps assessing if the
>> validation must be triggered or not, and avoids some calls to
>> ipv6_find_hdr.
>>
>> Signed-off-by: Mathieu Xhonneux <m.xhonneux@gmail.com>
[...]
>> +
>>  static int input_action_end_bpf(struct sk_buff *skb,
>>  				struct seg6_local_lwt *slwt)
>>  {
>>  	struct seg6_bpf_srh_state *srh_state =
>>  		this_cpu_ptr(&seg6_bpf_srh_states);
>> -	struct seg6_bpf_srh_state local_srh_state;
>>  	struct ipv6_sr_hdr *srh;
>> -	int srhoff = 0;
>>  	int ret;
>>  
>>  	srh = get_and_validate_srh(skb);
>> @@ -478,6 +499,7 @@ static int input_action_end_bpf(struct sk_buff *skb,
>>  	 * which is also accessed by the bpf_lwt_seg6_* helpers
>>  	 */
>>  	preempt_disable();
>> +	srh_state->srh = srh;
>>  	srh_state->hdrlen = srh->hdrlen << 3;
>>  	srh_state->valid = 1;
>>  
>> @@ -486,9 +508,6 @@ static int input_action_end_bpf(struct sk_buff *skb,
>>  	ret = bpf_prog_run_save_cb(slwt->bpf.prog, skb);
>>  	rcu_read_unlock();
>>  
>> -	local_srh_state = *srh_state;
>> -	preempt_enable();
>> -
>>  	switch (ret) {
>>  	case BPF_OK:
>>  	case BPF_REDIRECT:
>> @@ -500,24 +519,17 @@ static int input_action_end_bpf(struct sk_buff *skb,
>>  		goto drop;
>>  	}
>>  
>> -	if (unlikely((local_srh_state.hdrlen & 7) != 0))
>> -		goto drop;
>> -
>> -	if (ipv6_find_hdr(skb, &srhoff, IPPROTO_ROUTING, NULL, NULL) < 0)
>> -		goto drop;
>> -	srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);
>> -	srh->hdrlen = (u8)(local_srh_state.hdrlen >> 3);
>> -
>> -	if (!local_srh_state.valid &&
>> -	    unlikely(!seg6_validate_srh(srh, (srh->hdrlen + 1) << 3)))
>> +	if (srh_state->srh && !seg6_bpf_has_valid_srh(skb))
>>  		goto drop;
>>  
>> +	preempt_enable();
>>  	if (ret != BPF_REDIRECT)
>>  		seg6_lookup_nexthop(skb, NULL, 0);
>>  
>>  	return dst_input(skb);
>>  
>>  drop:
>> +	preempt_enable();
> For this drop case at the beginning of this function:
> 
> 	srh = get_and_validate_srh(skb);
> 	if (!srh)
> 		goto drop;
> 
> preempt_disable() was not called yet?

Agree, this is buggy.

  reply	other threads:[~2018-07-25  6:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-24 16:59 [PATCH bpf-next] bpf: add End.DT6 action to bpf_lwt_seg6_action helper Mathieu Xhonneux
2018-07-24 17:14 ` Martin KaFai Lau
2018-07-25  5:40   ` Daniel Borkmann [this message]
2018-07-25 10:21     ` Mathieu Xhonneux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3219cdfd-a6b5-8db7-a397-891e6d017d89@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=alexei.starovoitov@gmail.com \
    --cc=kafai@fb.com \
    --cc=m.xhonneux@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox