diff options
author | Andrea Parri (Microsoft) <parri.andrea@gmail.com> | 2022-04-28 16:51:05 +0200 |
---|---|---|
committer | Wei Liu <wei.liu@kernel.org> | 2022-04-28 17:01:14 +0200 |
commit | dbde6d0c7a5a462a1767a07c28eadd2c3dd08fb2 (patch) | |
tree | d2b87afa54493c0b2277319578fd8efbe0d151e9 /net/vmw_vsock | |
parent | hv_sock: Copy packets sent by Hyper-V out of the ring buffer (diff) | |
download | linux-dbde6d0c7a5a462a1767a07c28eadd2c3dd08fb2.tar.xz linux-dbde6d0c7a5a462a1767a07c28eadd2c3dd08fb2.zip |
hv_sock: Add validation for untrusted Hyper-V values
For additional robustness in the face of Hyper-V errors or malicious
behavior, validate all values that originate from packets that Hyper-V
has sent to the guest in the host-to-guest ring buffer. Ensure that
invalid values cannot cause data being copied out of the bounds of the
source buffer in hvs_stream_dequeue().
Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20220428145107.7878-4-parri.andrea@gmail.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Diffstat (limited to 'net/vmw_vsock')
-rw-r--r-- | net/vmw_vsock/hyperv_transport.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c index 8c37d07017fc..fd98229e3db3 100644 --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -577,12 +577,18 @@ static bool hvs_dgram_allow(u32 cid, u32 port) static int hvs_update_recv_data(struct hvsock *hvs) { struct hvs_recv_buf *recv_buf; - u32 payload_len; + u32 pkt_len, payload_len; + + pkt_len = hv_pkt_len(hvs->recv_desc); + + if (pkt_len < HVS_HEADER_LEN) + return -EIO; recv_buf = (struct hvs_recv_buf *)(hvs->recv_desc + 1); payload_len = recv_buf->hdr.data_size; - if (payload_len > HVS_MTU_SIZE) + if (payload_len > pkt_len - HVS_HEADER_LEN || + payload_len > HVS_MTU_SIZE) return -EIO; if (payload_len == 0) |