From 5a404946700fc485ddc81aa41a97bbe6333ac014 Mon Sep 17 00:00:00 2001 From: markj Date: Sat, 12 Jan 2019 17:00:54 +0000 Subject: [PATCH] MFC r342787: Add a bounds check to the tws(4) passthrough ioctl handler. admbug: 825 --- sys/dev/tws/tws_user.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/dev/tws/tws_user.c b/sys/dev/tws/tws_user.c index 5c93a4b93f78..f3eb09201ba6 100644 --- a/sys/dev/tws/tws_user.c +++ b/sys/dev/tws/tws_user.c @@ -90,9 +90,13 @@ tws_passthru(struct tws_softc *sc, void *buf) struct tws_request *req; struct tws_ioctl_no_data_buf *ubuf = (struct tws_ioctl_no_data_buf *)buf; int error; + u_int32_t buffer_length; u_int16_t lun4; - + buffer_length = roundup2(ubuf->driver_pkt.buffer_length, 512); + if ( buffer_length > TWS_MAX_IO_SIZE ) { + return(EINVAL); + } if ( tws_get_state(sc) != TWS_ONLINE) { return(EBUSY); } @@ -116,7 +120,7 @@ tws_passthru(struct tws_softc *sc, void *buf) } } while(1); - req->length = (ubuf->driver_pkt.buffer_length + 511) & ~511; + req->length = buffer_length; TWS_TRACE_DEBUG(sc, "datal,rid", req->length, req->request_id); if ( req->length ) { req->data = sc->ioctl_data_mem;