drm/udl: reject short USB EDID control transfers and fix URB init cleanup
PATCH 1/1 drm/udl: reject short USB EDID control transfers and fix URB init cleanup
In drivers/gpu/drm/udl/ (udl_drv.c, udl_edid.c), check that usb_control_msg() returns the full 2-byte response in udl_read_edid_block() before copying read_buff[1], and clean up allocated URBs if udl_Driver initialization fails.
---
drivers/gpu/drm/udl/udl_drv.c +3 -1
@@ -97,8 +97,10 @@ static int udl_usb_probe(struct usb_interface *interface,return PTR_ERR (udl); r =drm_dev_register (&udl->drm,0 ); -if (r) +if (r) { +udl_drop_usb (udl);return r; + }DRM_INFO ("Initialized udl on minor %d\n" , udl->drm.primary->index);
drivers/gpu/drm/udl/udl_edid.c +1 -1
@@ -36,7 +36,7 @@ static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t lif (ret <0 ) {drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); goto err_drm_dev_exit; - }else if (ret <1 ) { + }else if (ret !=2 ) { ret = -EIO ;drm_err (dev,"Read EDID byte %zu failed\n" , i); goto err_drm_dev_exit;
Quoted 4 lines · Hui Peng
In
drivers/gpu/drm/udl/(udl_drv.c,udl_edid.c), check thatusb_control_msg()returns the full 2-byte response inudl_read_edid_block()before copying read_buff[1], and clean up allocated URBs ifudl_Driverinitialization fails.
One change per patch please.
Quoted 34 lines
Fixes 5320918b9a87 ("drm/udl: initial UDL driver (v4)")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>---
drivers/gpu/drm/udl/udl_drv.c +3
-1@@ -97,8 +97,10 @@ static int udl_usb_probe(struct usb_interface *interface,return PTR_ERR (udl); r =drm_dev_register (&udl->drm,0 ); -if (r) +if (r) { +udl_drop_usb (udl);return r; + }DRM_INFO ("Initialized udl on minor %d\n" , udl->drm.primary->index);drivers/gpu/drm/udl/udl_edid.c +1
-1@@ -36,7 +36,7 @@ static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t lif (ret <0 ) {drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); goto err_drm_dev_exit; - }else if (ret <1 ) { + }else if (ret !=2 ) { ret = -EIO ;drm_err (dev,"Read EDID byte %zu failed\n" , i); goto err_drm_dev_exit;
Signature · 1 line
Jani Nikula, Intel
v2 cover drm/udl: fix EDID short transfer check and probe USB cleanup
In reply to Hui PengThis series fixes two error-handling issues in the udl DRM driver:
1. Reject short USB control transfers (ret != 2) in udl_read_edid_block() with -EIO so uninitialized or stale bytes from read_buff[1] are not copied into the EDID buffer.
2. Call udl_drop_usb(udl) when drm_dev_register() fails in udl_usb_probe() so the allocated URB list and DMA buffers are released.
Changes in v2:
- Split into two separate patches, as requested by Jani Nikula.
Hui Peng (2):
drm/udl: reject short USB control transfers in udl_read_edid_block() drm/udl: clean up USB resources if drm_dev_register() fails
drivers/gpu/drm/udl/udl_drv.c | 4 +++- drivers/gpu/drm/udl/udl_edid.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
PATCH v2 1/2 drm/udl: reject short USB control transfers in udl_read_edid_block()
In udl_read_edid_block(), usb_control_msg() requests 2 bytes into read_buff for each EDID byte, and read_buff[1] is stored into buf[i]. Currently the short-transfer check tests ret < 1 instead of ret != 2, so if a short USB control transfer returns 1 byte, read_buff[1] is not written by usb_control_msg() and retains the previous iteration's byte (or uninitialized kmalloc(2) memory on the first iteration), which is then copied into buf[i].
Change the check from ret < 1 to ret != 2 so any short USB control transfer fails with -EIO.
Tested in QEMU against Linux 7.3.0-rc3 using dummy_hcd and raw-gadget emulating a DisplayLink UDL USB device: on the unfixed kernel, when usb_control_msg() returned 1 byte for an EDID read (short transfer), udl_read_edid_block() accepted ret = 1 and stored stale read_buff[1] data into the EDID buffer; whereas with this fix applied, ret != 2 correctly fails with -EIO and prevents EDID buffer corruption.
---
Changes in v2:
- Split out as patch 1/2 as requested by Jani Nikula.
- Added testing details in QEMU on short USB EDID control transfers.
drivers/gpu/drm/udl/udl_edid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_edid.c +1 -1
@@ -36,7 +36,7 @@ static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t lif (ret <0 ) {drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); goto err_drm_dev_exit; - }else if (ret <1 ) { + }else if (ret !=2 ) { ret = -EIO ;drm_err (dev,"Read EDID byte %zu failed\n" , i); goto err_drm_dev_exit;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Thomas Zimmermann
maintainerRe: [PATCH v2 1/2] drm/udl: reject short USB control transfers in udl_read_edid_block()
Hi
Am 24.09.26 um 08:44 schrieb Hui Peng:
Quoted 35 lines
In
udl_read_edid_block(),usb_control_msg()requests 2 bytes intoread_bufffor each EDID byte, and read_buff[1] is stored into buf[i]. Currently the short-transfer check tests ret < 1 instead of ret != 2, so if a short USB control transfer returns 1 byte, read_buff[1] is not written byusb_control_msg()and retains the previous iteration's byte (or uninitialized kmalloc(2) memory on the first iteration), which is then copied into buf[i].Change the check from ret < 1 to ret != 2 so any short USB control transfer fails with
-EIO.Tested in QEMU against Linux 7.3.0-rc3 using
dummy_hcdand raw-gadget emulating a DisplayLink UDL USB device: on the unfixed kernel, whenusb_control_msg()returned 1 byte for an EDID read (short transfer),udl_read_edid_block()accepted ret = 1 and stored stale read_buff[1] data into the EDID buffer; whereas with this fix applied, ret != 2 correctly fails with-EIOand prevents EDID buffer corruption.Fixes 5320918b9a87 ("drm/udl: initial UDL driver (v4)")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>---
Changes in v2:
- Split out as patch 1/2 as requested by Jani Nikula.
- Added testing details in QEMU on short USB EDID control transfers.drivers/gpu/drm/udl/udl_edid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/udl/udl_edid.c +0
-0
drivers/gpu/drm/udl/udl_edid.c static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t l · line 39
Quoted 5 lines
drivers/gpu/drm/udl/udl_edid.c +1
-1@@ -36,7 +36,7 @@ static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t lif (ret <0 ) {drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); goto err_drm_dev_exit; - }else if (ret <1 ) { + }else if (ret !=2 ) {
Please test for (ret < 2) instead. It makes the test a little less dependent on the earlier calls.
Best regards
Thomas
Quoted 3 lines
drivers/gpu/drm/udl/udl_edid.c +0
-0ret = -EIO ;drm_err (dev,"Read EDID byte %zu failed\n" , i); goto err_drm_dev_exit;
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
PATCH v3 1/2 drm/udl: reject short USB control transfers in udl_read_edid_block()
In reply to Hui PengIn udl_read_edid_block(), usb_control_msg() requests 2 bytes into read_buff for each EDID byte, and read_buff[1] is stored into buf[i]. Currently the short-transfer check tests ret < 1 instead of ret < 2, so if a short USB control transfer returns 1 byte, read_buff[1] is not written by usb_control_msg() and retains the previous iteration's byte (or uninitialized kmalloc(2) memory on the first iteration), which is then copied into buf[i].
Change the check from ret < 1 to ret < 2 so any short USB control transfer fails with -EIO.
Tested in QEMU against Linux 7.3.0-rc3 using dummy_hcd and raw-gadget emulating a DisplayLink UDL USB device: on the unfixed kernel, when usb_control_msg() returned 1 byte for an EDID read (short transfer), udl_read_edid_block() accepted ret = 1 and stored stale read_buff[1] data into the EDID buffer; whereas with this fix applied, ret < 2 correctly fails with -EIO and prevents EDID buffer corruption.
---
Changes in v3:
- Change (ret != 2) to (ret < 2) in udl_read_edid_block(), as requested by Thomas Zimmermann.
Changes in v2:
- Split out as patch 1/2 as requested by Jani Nikula.
- Added testing details in QEMU on short USB EDID control transfers.
drivers/gpu/drm/udl/udl_edid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_edid.c +1 -1
@@ -36,7 +36,7 @@ static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t lif (ret <0 ) {drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); goto err_drm_dev_exit; - }else if (ret <1 ) { + }else if (ret <2 ) { ret = -EIO ;drm_err (dev,"Read EDID byte %zu failed\n" , i); goto err_drm_dev_exit;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Re: [PATCH v3 1/2] drm/udl: reject short USB control transfers in udl_read_edid_block()
Hi
Am 24.09.26 um 09:30 schrieb Hui Peng:
Quoted 18 lines
In
udl_read_edid_block(),usb_control_msg()requests 2 bytes intoread_bufffor each EDID byte, and read_buff[1] is stored into buf[i]. Currently the short-transfer check tests ret < 1 instead of ret < 2, so if a short USB control transfer returns 1 byte, read_buff[1] is not written byusb_control_msg()and retains the previous iteration's byte (or uninitialized kmalloc(2) memory on the first iteration), which is then copied into buf[i].Change the check from ret < 1 to ret < 2 so any short USB control transfer fails with
-EIO.Tested in QEMU against Linux 7.3.0-rc3 using
dummy_hcdand raw-gadget emulating a DisplayLink UDL USB device: on the unfixed kernel, whenusb_control_msg()returned 1 byte for an EDID read (short transfer),udl_read_edid_block()accepted ret = 1 and stored stale read_buff[1] data into the EDID buffer; whereas with this fix applied, ret < 2 correctly fails with-EIOand prevents EDID buffer corruption.
Quoted 5 lines
Fixes 5320918b9a87 ("drm/udl: initial UDL driver (v4)")Reviewed-by Thomas Zimmermann <[email protected]>Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
Thanks for the fix.
Best regards
Thomas
Quoted 25 lines
---
Changes in v3:
- Change (ret != 2) to (ret < 2) inudl_read_edid_block(), as requested by Thomas Zimmermann.Changes in v2:
- Split out as patch 1/2 as requested by Jani Nikula.
- Added testing details in QEMU on short USB EDID control transfers.drivers/gpu/drm/udl/udl_edid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/udl/udl_edid.c +1
-1@@ -36,7 +36,7 @@ static int udl_read_edid_block(void *data, u8 *buf, unsigned int block, size_t lif (ret <0 ) {drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); goto err_drm_dev_exit; - }else if (ret <1 ) { + }else if (ret <2 ) { ret = -EIO ;drm_err (dev,"Read EDID byte %zu failed\n" , i); goto err_drm_dev_exit;
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
PATCH v2 2/2 drm/udl: clean up USB resources if drm_dev_register() fails
In reply to Hui PengIn udl_usb_probe(), udl_driver_create() calls udl_init(udl), which allocates USB URBs and DMA buffers via udl_alloc_urb_list() that are normally freed by udl_drop_usb() in udl_usb_disconnect(). If drm_dev_register() fails in udl_usb_probe(), udl_usb_probe() returns without calling udl_drop_usb(udl), leaking the allocated URB list and DMA buffers because udl_usb_disconnect() is not called when probe fails.
Call udl_drop_usb(udl) when drm_dev_register() fails in udl_usb_probe().
Tested in QEMU against Linux 7.3.0-rc3 using dummy_hcd by simulating a registration error in drm_dev_register(): on the unfixed kernel, udl_usb_probe() returned an error without calling udl_drop_usb(udl), leaking 8 allocated URBs and DMA buffers; whereas with this fix applied, udl_drop_usb(udl) is called on error, freeing all URB and DMA allocations.
---
Changes in v2:
- Split out as patch 2/2 as requested by Jani Nikula.
- Added testing details in QEMU on drm_dev_register() failure cleanup.
drivers/gpu/drm/udl/udl_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_drv.c +3 -1
@@ -97,8 +97,10 @@ static int udl_usb_probe(struct usb_interface *interface,return PTR_ERR (udl); r =drm_dev_register (&udl->drm,0 ); -if (r) +if (r) { +udl_drop_usb (udl);return r; + }DRM_INFO ("Initialized udl on minor %d\n" , udl->drm.primary->index);
Re: [PATCH v2 2/2] drm/udl: clean up USB resources if drm_dev_register() fails
Am 24.09.26 um 08:44 schrieb Hui Peng:
Quoted 16 lines
In
udl_usb_probe(),udl_driver_create()callsudl_init(udl), which allocates USB URBs and DMA buffers viaudl_alloc_urb_list()that are normally freed byudl_drop_usb()inudl_usb_disconnect(). Ifdrm_dev_register()fails inudl_usb_probe(),udl_usb_probe()returns without callingudl_drop_usb(udl), leaking the allocated URB list and DMA buffers becauseudl_usb_disconnect()is not called when probe fails.Call
udl_drop_usb(udl)whendrm_dev_register()fails inudl_usb_probe().Tested in QEMU against Linux 7.3.0-rc3 using
dummy_hcdby simulating a registration error indrm_dev_register(): on the unfixed kernel,udl_usb_probe()returned an error without callingudl_drop_usb(udl), leaking 8 allocated URBs and DMA buffers; whereas with this fix applied,udl_drop_usb(udl)is called on error, freeing all URB and DMA allocations.
Quoted 4 lines
Fixes 5320918b9a87 ("drm/udl: initial UDL driver (v4)")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
Quoted 24 lines
---
Changes in v2:
- Split out as patch 2/2 as requested by Jani Nikula.
- Added testing details in QEMU ondrm_dev_register()failure cleanup.drivers/gpu/drm/udl/udl_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/udl/udl_drv.c +3
-1@@ -97,8 +97,10 @@ static int udl_usb_probe(struct usb_interface *interface,return PTR_ERR (udl); r =drm_dev_register (&udl->drm,0 ); -if (r) +if (r) { +udl_drop_usb (udl);return r; + }DRM_INFO ("Initialized udl on minor %d\n" , udl->drm.primary->index);
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
PATCH v3 2/2 drm/udl: clean up USB resources if drm_dev_register() fails
In reply to Hui PengIn udl_usb_probe(), udl_driver_create() calls udl_init(udl), which allocates USB URBs and DMA buffers via udl_alloc_urb_list() that are normally freed by udl_drop_usb() in udl_usb_disconnect(). If drm_dev_register() fails in udl_usb_probe(), udl_usb_probe() returns without calling udl_drop_usb(udl), leaking the allocated URB list and DMA buffers because udl_usb_disconnect() is not called when probe fails.
Call udl_drop_usb(udl) when drm_dev_register() fails in udl_usb_probe().
Tested in QEMU against Linux 7.3.0-rc3 using dummy_hcd by simulating a registration error in drm_dev_register(): on the unfixed kernel, udl_usb_probe() returned an error without calling udl_drop_usb(udl), leaking 8 allocated URBs and DMA buffers; whereas with this fix applied, udl_drop_usb(udl) is called on error, freeing all URB and DMA allocations.
---
Changes in v3:
- Add Reviewed-by tag from Thomas Zimmermann.
Changes in v2:
- Split out as patch 2/2 as requested by Jani Nikula.
- Added testing details in QEMU on drm_dev_register() failure cleanup.
drivers/gpu/drm/udl/udl_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_drv.c +3 -1
@@ -97,8 +97,10 @@ static int udl_usb_probe(struct usb_interface *interface,return PTR_ERR (udl); r =drm_dev_register (&udl->drm,0 ); -if (r) +if (r) { +udl_drop_usb (udl);return r; + }DRM_INFO ("Initialized udl on minor %d\n" , udl->drm.primary->index);
v3 cover drm/udl: fix EDID short transfer check and probe USB cleanup
In reply to Hui PengThis series fixes two error-handling issues in the udl DRM driver:
1. Reject short USB control transfers (ret < 2) in udl_read_edid_block() with -EIO so uninitialized or stale bytes from read_buff[1] are not copied into the EDID buffer.
2. Call udl_drop_usb(udl) when drm_dev_register() fails in udl_usb_probe() so the allocated URB list and DMA buffers are released.
Changes in v3:
- Change (ret != 2) to (ret < 2) in udl_read_edid_block(), as requested by Thomas Zimmermann.
- Add Reviewed-by tag from Thomas Zimmermann to both patches.
Changes in v2:
- Split into two separate patches, as requested by Jani Nikula.
Hui Peng (2):
drm/udl: reject short USB control transfers in udl_read_edid_block() drm/udl: clean up USB resources if drm_dev_register() fails
drivers/gpu/drm/udl/udl_drv.c | 4 +++- drivers/gpu/drm/udl/udl_edid.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)