Subject: Re: [PATCH bpf 1/2] bpf: pull before calling skb_postpull_rcsum()

From: Jakub Kicinski <[email-masked]>
Date: Mon, 19 Dec 2022 17:45:05 -0800

On Mon, 19 Dec 2022 17:21:27 -0800 Stanislav Fomichev wrote:
> > -       skb_postpull_rcsum(skb, skb->data + off, len);
> > -       memmove(skb->data + len, skb->data, off);
> > +       old_data = skb->data;
> >         __skb_pull(skb, len);  
> 
> [..]

Very counter-productively trimmed ;)

> > +       skb_postpull_rcsum(skb, old_data + off, len);  
> 
> Are you sure about the 'old_data + off' part here (for
> CHECKSUM_COMPLETE)? Shouldn't it be old_data?

AFAIU before:

      old_data (aka skb->data before)
     /
    / off  len 
   V-----><--->
[ .=======xxxxx... buffer ...... ]
          ^
           \
            the xxx part is what we delete

after:
          skb->data (after)
         /
        v
[ .yyyyy=======... buffer ...... ]
   <---><----->
    len   off  
   ^
    \
     the yyy part is technically the old values of === but now "outside"
     of the valid packet data

> I'm assuming we need to negate the old parts that we've pulled?

Yes.

> Maybe safer/more correct to do the following?
> 
> skb_pull_rcsum(skb, off);

This just pulls from the front, we need to skip over various L2/L3
headers thanks to off. Hopefully the diagrams help, LMK if they are
wrong.

> memmove(skb->data, skb->data-off, off);