veth: Adjust hard_start offset on redirect XDP frames
[ Upstream commit 5c8572251fabc5bb49fd623c064e95a9daf6a3e3 ]
When native XDP redirect into a veth device, the frame arrives in the
xdp_frame structure. It is then processed in veth_xdp_rcv_one(),
which can run a new XDP bpf_prog on the packet. Doing so requires
converting xdp_frame to xdp_buff, but the tricky part is that
xdp_frame memory area is located in the top (data_hard_start) memory
area that xdp_buff will point into.
The current code tried to protect the xdp_frame area, by assigning
xdp_buff.data_hard_start past this memory. This results in 32 bytes
less headroom to expand into via BPF-helper bpf_xdp_adjust_head().
This protect step is actually not needed, because BPF-helper
bpf_xdp_adjust_head() already reserve this area, and don't allow
BPF-prog to expand into it. Thus, it is safe to point data_hard_start
directly at xdp_frame memory area.
Fixes: 9fc8d518d9 ("veth: Handle xdp_frames in xdp napi ring")
Reported-by: Mao Wenan <maowenan@huawei.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/158945338331.97035.5923525383710752178.stgit@firesoul
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
868b8e43a0
commit
b6c90a7d0a
@@ -377,13 +377,15 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
|
|||||||
unsigned int *xdp_xmit)
|
unsigned int *xdp_xmit)
|
||||||
{
|
{
|
||||||
void *hard_start = frame->data - frame->headroom;
|
void *hard_start = frame->data - frame->headroom;
|
||||||
void *head = hard_start - sizeof(struct xdp_frame);
|
|
||||||
int len = frame->len, delta = 0;
|
int len = frame->len, delta = 0;
|
||||||
struct xdp_frame orig_frame;
|
struct xdp_frame orig_frame;
|
||||||
struct bpf_prog *xdp_prog;
|
struct bpf_prog *xdp_prog;
|
||||||
unsigned int headroom;
|
unsigned int headroom;
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
|
|
||||||
|
/* bpf_xdp_adjust_head() assures BPF cannot access xdp_frame area */
|
||||||
|
hard_start -= sizeof(struct xdp_frame);
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
xdp_prog = rcu_dereference(rq->xdp_prog);
|
xdp_prog = rcu_dereference(rq->xdp_prog);
|
||||||
if (likely(xdp_prog)) {
|
if (likely(xdp_prog)) {
|
||||||
@@ -405,7 +407,6 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
|
|||||||
break;
|
break;
|
||||||
case XDP_TX:
|
case XDP_TX:
|
||||||
orig_frame = *frame;
|
orig_frame = *frame;
|
||||||
xdp.data_hard_start = head;
|
|
||||||
xdp.rxq->mem = frame->mem;
|
xdp.rxq->mem = frame->mem;
|
||||||
if (unlikely(veth_xdp_tx(rq->dev, &xdp) < 0)) {
|
if (unlikely(veth_xdp_tx(rq->dev, &xdp) < 0)) {
|
||||||
trace_xdp_exception(rq->dev, xdp_prog, act);
|
trace_xdp_exception(rq->dev, xdp_prog, act);
|
||||||
@@ -417,7 +418,6 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
|
|||||||
goto xdp_xmit;
|
goto xdp_xmit;
|
||||||
case XDP_REDIRECT:
|
case XDP_REDIRECT:
|
||||||
orig_frame = *frame;
|
orig_frame = *frame;
|
||||||
xdp.data_hard_start = head;
|
|
||||||
xdp.rxq->mem = frame->mem;
|
xdp.rxq->mem = frame->mem;
|
||||||
if (xdp_do_redirect(rq->dev, &xdp, xdp_prog)) {
|
if (xdp_do_redirect(rq->dev, &xdp, xdp_prog)) {
|
||||||
frame = &orig_frame;
|
frame = &orig_frame;
|
||||||
@@ -437,7 +437,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
|
|||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
|
||||||
headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
|
headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
|
||||||
skb = veth_build_skb(head, headroom, len, 0);
|
skb = veth_build_skb(hard_start, headroom, len, 0);
|
||||||
if (!skb) {
|
if (!skb) {
|
||||||
xdp_return_frame(frame);
|
xdp_return_frame(frame);
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
Reference in New Issue
Block a user