From 9ce2c85a5c7104829269b904836201ccab6949f1 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 13 Jun 2022 17:02:42 +0300 Subject: executor: fix out of bounds write in lookup_connect_response_in() gcc 12.1 reports the following -Werror=array-bounds error: /// In function 'bool lookup_connect_response_in(...)' executor/common_usb.h:632:66: error: array subscript 'usb_qualifier_descriptor[0]' is partly outside array bounds of 'char [8]' [-Werror=array-bounds] | 632 | qual->bNumConfigurations = index->dev->bNumConfigurations; | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'volatile long int syz_usb_connect_impl(...)': executor/common_usb_linux.h:332:23: note: object 'response_data' of size 8 | 332 | char* response_data = NULL; | ^~~~~~~~~~~~~ ... In function 'bool lookup_connect_response_in(...)', executor/common_usb.h:633:57: error: array subscript 'usb_qualifier_descriptor[0]' is partly outside array bounds of 'char [8]' [-Werror=array-bounds] | 633 | qual->bRESERVED = 0; | ~~~~~~~~~~~~~~~~^~~ In function 'volatile long int syz_usb_connect_impl(...)': executor/common_usb_linux.h:332:23: note: object 'response_data' of size 8 332 | char* response_data = NULL; | ^~~~~~~~~~~~~ /// Current code in USB_DT_DEVICE_QUALIFIER case treats respose_data as a buffer, but in reality it is just a pointer, as detailed in the error trace above. In order to allow passing a usb_qualifier_descriptor struct back to the caller (via response_data), add a new parameter to lookup_connect_response_in(). Build tested only. Fixes: 0c00210ff32 ("executor: always provide DEVICE_QUALIFIER USB descriptor") Signed-off-by: Ovidiu Panait --- executor/common_usb_netbsd.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'executor/common_usb_netbsd.h') diff --git a/executor/common_usb_netbsd.h b/executor/common_usb_netbsd.h index 986555321..8705856d9 100644 --- a/executor/common_usb_netbsd.h +++ b/executor/common_usb_netbsd.h @@ -250,10 +250,11 @@ static volatile long syz_usb_connect_impl(int fd, uint64 speed, uint64 dev_len, char* response_data = NULL; uint32 response_length = 0; + struct usb_qualifier_descriptor qual; char data[4096]; if (req.u.ctrl.bmRequestType & UE_DIR_IN) { - if (!lookup_connect_response_in(fd, descs, (const struct usb_ctrlrequest*)&req.u.ctrl, &response_data, &response_length)) { + if (!lookup_connect_response_in(fd, descs, (const struct usb_ctrlrequest*)&req.u.ctrl, &qual, &response_data, &response_length)) { debug("syz_usb_connect: unknown control IN request\n"); return -1; } -- cgit mrf-deployment