提交 5b7ecbc9 编写于 作者: P Paolo Abeni 提交者: Zheng Zengkai

vhost_net: fix OoB on sendmsg() failure.

stable inclusion
from stable-5.10.68
commit cad96d0e50e4149758d43bcc3bd13f6381312362
bugzilla: 182671 https://gitee.com/openeuler/kernel/issues/I4EWUH

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=cad96d0e50e4149758d43bcc3bd13f6381312362

--------------------------------

commit 3c4cea8f upstream.

If the sendmsg() call in vhost_tx_batch() fails, both the 'batched_xdp'
and 'done_idx' indexes are left unchanged. If such failure happens
when batched_xdp == VHOST_NET_BATCH, the next call to
vhost_net_build_xdp() will access and write memory outside the xdp
buffers area.

Since sendmsg() can only error with EBADFD, this change addresses the
issue explicitly freeing the XDP buffers batch on error.

Fixes: 0a0be13b ("vhost_net: batch submitting XDP buffers to underlayer sockets")
Suggested-by: NJason Wang <jasowang@redhat.com>
Signed-off-by: NPaolo Abeni <pabeni@redhat.com>
Acked-by: NJason Wang <jasowang@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 05137c1c
......@@ -466,7 +466,7 @@ static void vhost_tx_batch(struct vhost_net *net,
.num = nvq->batched_xdp,
.ptr = nvq->xdp,
};
int err;
int i, err;
if (nvq->batched_xdp == 0)
goto signal_used;
......@@ -475,6 +475,15 @@ static void vhost_tx_batch(struct vhost_net *net,
err = sock->ops->sendmsg(sock, msghdr, 0);
if (unlikely(err < 0)) {
vq_err(&nvq->vq, "Fail to batch sending packets\n");
/* free pages owned by XDP; since this is an unlikely error path,
* keep it simple and avoid more complex bulk update for the
* used pages
*/
for (i = 0; i < nvq->batched_xdp; ++i)
put_page(virt_to_head_page(nvq->xdp[i].data));
nvq->batched_xdp = 0;
nvq->done_idx = 0;
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部