HID: hid-uclogic-params: Fix NULL pointer dereferences
cover HID: hid-uclogic-params: Fix NULL pointer dereferences
Hi everyone,
This series fixes 4 possible NULL pointer dereference errors present in hid-uclogic-params.c found by Coverity.
Even though the fixes are small and very similar I made them in 4 patches to include the Coverity ID on each of them and make Coverity happy.
I didn't find any code calling the functions with invalid params, but since the check is there, it's better to make sure that it's doing its job.
Thanks,
José Expósito
José Expósito (4):
HID: hid-uclogic-params: Invalid parameter check in
uclogic_params_init
HID: hid-uclogic-params: Invalid parameter check in
uclogic_params_get_str_desc
HID: hid-uclogic-params: Invalid parameter check in
uclogic_params_huion_init
HID: hid-uclogic-params: Invalid parameter check in
uclogic_params_frame_init_v1_buttonpad
drivers/hid/hid-uclogic-params.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 HID: hid-uclogic-params: Invalid parameter check in uclogic_params_init
The function performs a check on its input parameters, however, the hdev parameter is used before the check.
Initialize the stack variables after checking the input parameters to avoid a possible NULL pointer dereference.
Addresses-Coverity-ID: 1443831 ("Null pointer dereference")
--- drivers/hid/hid-uclogic-params.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/hid/hid-uclogic-params.c +9 -4
@@ -834,10 +834,10 @@ int uclogic_params_init(struct uclogic_params *params, struct hid_device *hdev) {int rc; -struct usb_device *udev =hid_to_usb_dev (hdev); -__u8 bNumInterfaces = udev->config->desc.bNumInterfaces; -struct usb_interface *iface =to_usb_interface (hdev->dev.parent); -__u8 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; +struct usb_device *udev; +__u8 bNumInterfaces; +struct usb_interface *iface; +__u8 bInterfaceNumber;bool found;/* The resulting parameters (noop) */ struct uclogic_params p = {0 , };
@@ -848,6 +848,11 @@ int uclogic_params_init(struct uclogic_params *params, goto cleanup; } + udev =hid_to_usb_dev (hdev); + bNumInterfaces = udev->config->desc.bNumInterfaces; + iface =to_usb_interface (hdev->dev.parent); + bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; +/* * Set replacement report descriptor if the original matches the * specified size. Otherwise keep interface unchanged.
Signature · 1 line
2.25.1
PATCH 2/4 HID: hid-uclogic-params: Invalid parameter check in uclogic_params_get_str_desc
In reply to José ExpósitoThe function performs a check on the hdev input parameters, however, it is used before the check.
Initialize the udev variable after the sanity check to avoid a possible NULL pointer dereference.
Addresses-Coverity-ID: 1443827 ("Null pointer dereference")
--- drivers/hid/hid-uclogic-params.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-uclogic-params.c +3 -1
@@ -66,7 +66,7 @@ static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev, __u8 idx, size_t len) {int rc; -struct usb_device *udev =hid_to_usb_dev (hdev); +struct usb_device *udev;__u8 *buf =NULL ;/* Check arguments */
@@ -75,6 +75,8 @@ static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev, goto cleanup; } + udev =hid_to_usb_dev (hdev); + buf =kmalloc (len,GFP_KERNEL );if (buf ==NULL ) { rc = -ENOMEM ;
Signature · 1 line
2.25.1
PATCH 3/4 HID: hid-uclogic-params: Invalid parameter check in uclogic_params_huion_init
In reply to José ExpósitoThe function performs a check on its input parameters, however, the hdev parameter is used before the check.
Initialize the stack variables after checking the input parameters to avoid a possible NULL pointer dereference.
Addresses-Coverity-ID: 1443804 ("Null pointer dereference")
--- drivers/hid/hid-uclogic-params.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/hid/hid-uclogic-params.c +7 -3
@@ -709,9 +709,9 @@ static int uclogic_params_huion_init(struct uclogic_params *params, struct hid_device *hdev) {int rc; -struct usb_device *udev =hid_to_usb_dev (hdev); -struct usb_interface *iface =to_usb_interface (hdev->dev.parent); -__u8 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; +struct usb_device *udev; +struct usb_interface *iface; +__u8 bInterfaceNumber;bool found;/* The resulting parameters (noop) */ struct uclogic_params p = {0 , };
@@ -725,6 +725,10 @@ static int uclogic_params_huion_init(struct uclogic_params *params, goto cleanup; } + udev =hid_to_usb_dev (hdev); + iface =to_usb_interface (hdev->dev.parent); + bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; +/* If it's not a pen interface */ if (bInterfaceNumber !=0 ) {/* TODO: Consider marking the interface invalid */
Signature · 1 line
2.25.1
PATCH 4/4 HID: hid-uclogic-params: Invalid parameter check in uclogic_params_frame_init_v1_buttonpad
In reply to José ExpósitoThe function performs a check on the hdev input parameters, however, it is used before the check.
Initialize the udev variable after the sanity check to avoid a possible NULL pointer dereference.
Addresses-Coverity-ID: 1443763 ("Null pointer dereference")
--- drivers/hid/hid-uclogic-params.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-uclogic-params.c +3 -1
@@ -452,7 +452,7 @@ static int uclogic_params_frame_init_v1_buttonpad( {int rc;bool found = false; -struct usb_device *usb_dev =hid_to_usb_dev (hdev); +struct usb_device *usb_dev;char *str_buf =NULL ;const size_t str_len =16 ;
@@ -462,6 +462,8 @@ static int uclogic_params_frame_init_v1_buttonpad( goto cleanup; } + usb_dev =hid_to_usb_dev (hdev); +/* * Enable generic button mode */
Signature · 1 line
2.25.1
Jiri Kosina
maintainerQuoted 5 lines · José Expósito
Hi everyone,
This series fixes 4 possible NULL pointer dereference errors present in
hid-uclogic-params.cfound by Coverity.
Quoted 7 lines
Even though the fixes are small and very similar I made them in 4 patches to include the Coverity ID on each of them and make Coverity happy.
I didn't find any code calling the functions with invalid params, but since the check is there, it's better to make sure that it's doing its job.
Thanks, I've queued the series.
Signature · 2 lines
Jiri Kosina SUSE Labs