From: Paolo Abeni <pabeni@redhat.com> Date: 2021-09-08 11:42:39
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: 0a0be13b8fe2 ("vhost_net: batch submitting XDP buffers to underlayer sockets")
Suggested-by: Jason Wang <redacted>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
Note: my understanding is that this should go through MST's tree, please
educate me otherwise, thanks!
---
drivers/vhost/net.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
@@ -476,6 +476,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,+*keepitsimpleandavoidmorecomplexbulkupdateforthe+*usedpages+*/+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;}
From: Jason Wang <hidden> Date: 2021-09-09 02:53:16
On Wed, Sep 8, 2021 at 7:42 PM Paolo Abeni [off-list ref] wrote:
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: 0a0be13b8fe2 ("vhost_net: batch submitting XDP buffers to underlayer sockets")
Suggested-by: Jason Wang <redacted>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
Note: my understanding is that this should go through MST's tree, please
educate me otherwise, thanks!
---
@@ -476,6 +476,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,+*keepitsimpleandavoidmorecomplexbulkupdateforthe+*usedpages+*/+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;}--
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Wed, 8 Sep 2021 13:42:09 +0200 you wrote:
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.
[...]