> -----Original Message----- > From: Florian Westphal <fw@xxxxxxxxx> > Sent: Tuesday, August 9, 2022 9:07 AM > To: Alexander Duyck <alexanderduyck@xxxxxx> > Cc: Florian Westphal <fw@xxxxxxxxx>; netfilter-devel@xxxxxxxxxxxxxxx; > edumazet@xxxxxxxxxx > Subject: Re: [PATCH nf 3/4] netfilter: conntrack_ftp: prefer skb_linearize > Alexander Duyck <alexanderduyck@xxxxxx> wrote: > > > - spin_lock_bh(&nf_ftp_lock); > > > - fb_ptr = skb_header_pointer(skb, dataoff, datalen, ftp_buffer); > > > - if (!fb_ptr) { > > > - spin_unlock_bh(&nf_ftp_lock); > > > - return NF_ACCEPT; > > > - } > > > + spin_lock_bh(&ct->lock); > > > + fb_ptr = skb->data + dataoff; > > > > > > ends_in_nl = (fb_ptr[datalen - 1] == '\n'); > > > seq = ntohl(th->seq) + datalen; > > > > Rather than using skb_header_pointer/skb_linearize is there any reason > why you couldn't use pskb_may_pull? It seems like that would be much > closer to what you are looking for here rather than linearizing the entire > buffer. With that you would have access to all the same headers you did with > the skb_header_pointer approach and in most cases the copy should just be > skipped since the headlen is already in the skb->data buffer. > > This helper is written with the assumption that everything is searchable via > 'const char *'. > > I'm not going to submit a patch to -net that rewrites this, and I'm not sure its > worth it to spend time on it for -next either. My bad, I misread it. I thought it was looking at the headers, instead this is looking at everything after the headers. I am honestly surprised it is using this approach since copying the entire buffer over to a linear buffer would be really expensive. I am assuming this code isn't exercised often? If so I guess skb_linearize works here, but it will be much more prone to failure for larger buffers as the higher order memory allocations will be likely to fail as memory gets more fragmented over time.