Skip to content

Commit 97e19cc

Browse files
netoptimizerborkmann
authored andcommitted
bpf: reserve xdp_frame size in xdp headroom
Commit 6dfb970 ("xdp: avoid leaking info stored in frame data on page reuse") tried to allow user/bpf_prog to (re)use area used by xdp_frame (stored in frame headroom), by memset clearing area when bpf_xdp_adjust_head give bpf_prog access to headroom area. The mentioned commit had two bugs. (1) Didn't take bpf_xdp_adjust_meta into account. (2) a combination of bpf_xdp_adjust_head calls, where xdp->data is moved into xdp_frame section, can cause clearing xdp_frame area again for area previously granted to bpf_prog. After discussions with Daniel, we choose to implement a simpler solution to the problem, which is to reserve the headroom used by xdp_frame info. This also avoids the situation where bpf_prog is allowed to adjust/add headers, and then XDP_REDIRECT later drops the packet due to lack of headroom for the xdp_frame. This would likely confuse the end-user. Fixes: 6dfb970 ("xdp: avoid leaking info stored in frame data on page reuse") Signed-off-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 7f3249f commit 97e19cc

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

net/core/filter.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,20 +2694,13 @@ BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset)
26942694
{
26952695
void *xdp_frame_end = xdp->data_hard_start + sizeof(struct xdp_frame);
26962696
unsigned long metalen = xdp_get_metalen(xdp);
2697-
void *data_start = xdp->data_hard_start + metalen;
2697+
void *data_start = xdp_frame_end + metalen;
26982698
void *data = xdp->data + offset;
26992699

27002700
if (unlikely(data < data_start ||
27012701
data > xdp->data_end - ETH_HLEN))
27022702
return -EINVAL;
27032703

2704-
/* Avoid info leak, when reusing area prev used by xdp_frame */
2705-
if (data < xdp_frame_end) {
2706-
unsigned long clearlen = xdp_frame_end - data;
2707-
2708-
memset(data, 0, clearlen);
2709-
}
2710-
27112704
if (metalen)
27122705
memmove(xdp->data_meta + offset,
27132706
xdp->data_meta, metalen);
@@ -2751,12 +2744,13 @@ static const struct bpf_func_proto bpf_xdp_adjust_tail_proto = {
27512744

27522745
BPF_CALL_2(bpf_xdp_adjust_meta, struct xdp_buff *, xdp, int, offset)
27532746
{
2747+
void *xdp_frame_end = xdp->data_hard_start + sizeof(struct xdp_frame);
27542748
void *meta = xdp->data_meta + offset;
27552749
unsigned long metalen = xdp->data - meta;
27562750

27572751
if (xdp_data_meta_unsupported(xdp))
27582752
return -ENOTSUPP;
2759-
if (unlikely(meta < xdp->data_hard_start ||
2753+
if (unlikely(meta < xdp_frame_end ||
27602754
meta > xdp->data))
27612755
return -EINVAL;
27622756
if (unlikely((metalen & (sizeof(__u32) - 1)) ||

0 commit comments

Comments
 (0)