From 9e61accbedb7a2a971fe9df63e1ef8b8fae79324 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Fri, 18 May 2018 18:57:12 +0800 Subject: [PATCH] DM: add spanning devices check for i/o access - i/o access whose handler is not registered should not be allowed. Signed-off-by: Yonghua Huang --- devicemodel/core/inout.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/devicemodel/core/inout.c b/devicemodel/core/inout.c index ae801cf66..651064cbf 100644 --- a/devicemodel/core/inout.c +++ b/devicemodel/core/inout.c @@ -99,19 +99,26 @@ emulate_inout(struct vmctx *ctx, int *pvcpu, struct pio_request *pio_request, int bytes, flags, in, port; inout_func_t handler; void *arg; - int retval; + int i, retval; bytes = pio_request->size; in = (pio_request->direction == REQUEST_READ); port = pio_request->address; - assert(port < MAX_IOPORTS); + assert(port + bytes - 1 < MAX_IOPORTS); assert(bytes == 1 || bytes == 2 || bytes == 4); handler = inout_handlers[port].handler; - if (strict && handler == default_inout) - return -1; + if (strict) { + if (handler == default_inout) + return -1; + + for (i = 1; i < bytes; i++) { + if (inout_handlers[port + i].handler != handler) + return -1; + } + } flags = inout_handlers[port].flags; arg = inout_handlers[port].arg;