Skip to content

Commit c8741e2

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
xdp: Allow bpf_xdp_adjust_tail() to grow packet size
Finally, after all drivers have a frame size, allow BPF-helper bpf_xdp_adjust_tail() to grow or extend packet size at frame tail. Remember that helper/macro xdp_data_hard_end have reserved some tailroom. Thus, this helper makes sure that the BPF-prog don't have access to this tailroom area. V2: Remove one chicken check and use WARN_ONCE for other Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/158945348530.97035.12577148209134239291.stgit@firesoul
1 parent d628ee4 commit c8741e2

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎include/uapi/linux/bpf.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,8 +2015,8 @@ union bpf_attr {
20152015
* int bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
20162016
* Description
20172017
* Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
2018-
* only possible to shrink the packet as of this writing,
2019-
* therefore *delta* must be a negative integer.
2018+
* possible to both shrink and grow the packet tail.
2019+
* Shrink done via *delta* being a negative integer.
20202020
*
20212021
* A call to this helper is susceptible to change the underlying
20222022
* packet buffer. Therefore, at load time, all checks on pointers

‎net/core/filter.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,12 +3411,19 @@ static const struct bpf_func_proto bpf_xdp_adjust_head_proto = {
34113411

34123412
BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
34133413
{
3414+
void *data_hard_end = xdp_data_hard_end(xdp); /* use xdp->frame_sz */
34143415
void *data_end = xdp->data_end + offset;
34153416

3416-
/* only shrinking is allowed for now. */
3417-
if (unlikely(offset >= 0))
3417+
/* Notice that xdp_data_hard_end have reserved some tailroom */
3418+
if (unlikely(data_end > data_hard_end))
34183419
return -EINVAL;
34193420

3421+
/* ALL drivers MUST init xdp->frame_sz, chicken check below */
3422+
if (unlikely(xdp->frame_sz > PAGE_SIZE)) {
3423+
WARN_ONCE(1, "Too BIG xdp->frame_sz = %d\n", xdp->frame_sz);
3424+
return -EINVAL;
3425+
}
3426+
34203427
if (unlikely(data_end < xdp->data + ETH_HLEN))
34213428
return -EINVAL;
34223429

0 commit comments

Comments
 (0)