mirror of
https://github.com/torvalds/linux.git
synced 2026-09-28 03:52:02 +02:00
bpf, net: Introduce skb_pointer_if_linear().
Network drivers always call skb_header_pointer() with non-null buffer. Remove !buffer check to prevent accidental misuse of skb_header_pointer(). Introduce skb_pointer_if_linear() instead. Reported-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20230718234021.43640-1-alexei.starovoitov@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
41ee0145a4
commit
6f5a630d7c
|
|
@ -4023,7 +4023,7 @@ __skb_header_pointer(const struct sk_buff *skb, int offset, int len,
|
||||||
if (likely(hlen - offset >= len))
|
if (likely(hlen - offset >= len))
|
||||||
return (void *)data + offset;
|
return (void *)data + offset;
|
||||||
|
|
||||||
if (!skb || !buffer || unlikely(skb_copy_bits(skb, offset, buffer, len) < 0))
|
if (!skb || unlikely(skb_copy_bits(skb, offset, buffer, len) < 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
@ -4036,6 +4036,14 @@ skb_header_pointer(const struct sk_buff *skb, int offset, int len, void *buffer)
|
||||||
skb_headlen(skb), buffer);
|
skb_headlen(skb), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void * __must_check
|
||||||
|
skb_pointer_if_linear(const struct sk_buff *skb, int offset, int len)
|
||||||
|
{
|
||||||
|
if (likely(skb_headlen(skb) - offset >= len))
|
||||||
|
return skb->data + offset;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* skb_needs_linearize - check if we need to linearize a given skb
|
* skb_needs_linearize - check if we need to linearize a given skb
|
||||||
* depending on the given device features.
|
* depending on the given device features.
|
||||||
|
|
|
||||||
|
|
@ -2263,7 +2263,10 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset
|
||||||
case BPF_DYNPTR_TYPE_RINGBUF:
|
case BPF_DYNPTR_TYPE_RINGBUF:
|
||||||
return ptr->data + ptr->offset + offset;
|
return ptr->data + ptr->offset + offset;
|
||||||
case BPF_DYNPTR_TYPE_SKB:
|
case BPF_DYNPTR_TYPE_SKB:
|
||||||
return skb_header_pointer(ptr->data, ptr->offset + offset, len, buffer__opt);
|
if (buffer__opt)
|
||||||
|
return skb_header_pointer(ptr->data, ptr->offset + offset, len, buffer__opt);
|
||||||
|
else
|
||||||
|
return skb_pointer_if_linear(ptr->data, ptr->offset + offset, len);
|
||||||
case BPF_DYNPTR_TYPE_XDP:
|
case BPF_DYNPTR_TYPE_XDP:
|
||||||
{
|
{
|
||||||
void *xdp_ptr = bpf_xdp_pointer(ptr->data, ptr->offset + offset, len);
|
void *xdp_ptr = bpf_xdp_pointer(ptr->data, ptr->offset + offset, len);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user