hv_utils: 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 indexing off the end of the icversion_data array in vmbus_prep_negotiate_resp(). Signed-off-by: Andres Beltran <lkmlabelt@gmail.com> Co-developed-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com> Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/20201109100704.9152-1-parri.andrea@gmail.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
This commit is contained in:
@@ -1480,6 +1480,7 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size);
|
||||
#define ICMSGTYPE_SHUTDOWN 3
|
||||
#define ICMSGTYPE_TIMESYNC 4
|
||||
#define ICMSGTYPE_VSS 5
|
||||
#define ICMSGTYPE_FCOPY 7
|
||||
|
||||
#define ICMSGHDRFLAG_TRANSACTION 1
|
||||
#define ICMSGHDRFLAG_REQUEST 2
|
||||
@@ -1523,6 +1524,12 @@ struct icmsg_hdr {
|
||||
u8 reserved[2];
|
||||
} __packed;
|
||||
|
||||
#define IC_VERSION_NEGOTIATION_MAX_VER_COUNT 100
|
||||
#define ICMSG_HDR (sizeof(struct vmbuspipe_hdr) + sizeof(struct icmsg_hdr))
|
||||
#define ICMSG_NEGOTIATE_PKT_SIZE(icframe_vercnt, icmsg_vercnt) \
|
||||
(ICMSG_HDR + offsetof(struct icmsg_negotiate, icversion_data) + \
|
||||
(((icframe_vercnt) + (icmsg_vercnt)) * sizeof(struct ic_version)))
|
||||
|
||||
struct icmsg_negotiate {
|
||||
u16 icframe_vercnt;
|
||||
u16 icmsg_vercnt;
|
||||
@@ -1578,7 +1585,7 @@ struct hyperv_service_callback {
|
||||
};
|
||||
|
||||
#define MAX_SRV_VER 0x7ffffff
|
||||
extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf,
|
||||
extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf, u32 buflen,
|
||||
const int *fw_version, int fw_vercnt,
|
||||
const int *srv_version, int srv_vercnt,
|
||||
int *nego_fw_version, int *nego_srv_version);
|
||||
|
||||
Reference in New Issue
Block a user