usb: ch9: Replace bmSublinkSpeedAttr 1-element array with flexible array
PATCH 1/1 usb: ch9: Replace bmSublinkSpeedAttr 1-element array with flexible array
Since commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"), UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking bmSublinkSpeedAttr will trigger a warning, so make it a proper flexible array. Add a union to keep the struct size identical for userspace in case anything was depending on the old size.
False positive warning was:
UBSAN: array-index-out-of-bounds in drivers/usb/host/xhci-hub.c:231:31 index 1 is out of range for type '__le32 [1]'
for this line of code:
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);
--- include/uapi/linux/usb/ch9.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
include/uapi/linux/usb/ch9.h +5 -1
@@ -981,7 +981,11 @@ struct usb_ssp_cap_descriptor {#define USB_SSP_MIN_RX_LANE_COUNT (0xf << 8)#define USB_SSP_MIN_TX_LANE_COUNT (0xf << 12)__le16 wReserved; -__le32 bmSublinkSpeedAttr[1 ];/* list of sublink speed attrib entries */ +union { +__le32 legacy_padding; +/* list of sublink speed attrib entries */ + __DECLARE_FLEX_ARRAY(__le32, bmSublinkSpeedAttr); + };#define USB_SSP_SUBLINK_SPEED_SSID (0xf)/* sublink speed ID */ #define USB_SSP_SUBLINK_SPEED_LSE (0x3 << 4)/* Lanespeed exponent */ #define USB_SSP_SUBLINK_SPEED_LSE_BPS 0
Signature · 1 line
2.34.1
Greg Kroah-Hartman
maintainerQuoted 14 lines · Kees Cook
Since commit
df8fc4e934c1("kbuild: Enable -fstrict-flex-arrays=3"),UBSAN_BOUNDSno longer pretends 1-element arrays are unbounded. Walking bmSublinkSpeedAttr will trigger a warning, so make it a proper flexible array. Add a union to keep the struct size identical for userspace in case anything was depending on the old size.False positive warning was:
UBSAN: array-index-out-of-bounds in drivers/usb/host/xhci-hub.c:231:31 index 1 is out of range for type '__le32 [1]'for this line of code:
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);
Quoted 8 lines
Reported-by Borislav Petkov <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>--- include/uapi/linux/usb/ch9.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Thanks for the quick response, I'll queue it up after 6.5-rc1 is out.
Boris, can you test if this fixes the issue you see or not?
greg k-h
Quoted 12 lines · Kees Cook
Since commit
df8fc4e934c1("kbuild: Enable -fstrict-flex-arrays=3"),UBSAN_BOUNDSno longer pretends 1-element arrays are unbounded. Walking bmSublinkSpeedAttr will trigger a warning, so make it a proper flexible array. Add a union to keep the struct size identical for userspace in case anything was depending on the old size.False positive warning was:
UBSAN: array-index-out-of-bounds in drivers/usb/host/xhci-hub.c:231:31 index 1 is out of range for type '__le32 [1]'for this line of code:
Quoted 7 lines
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);Reported-by Borislav Petkov <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks!
--
Gustavo
Quoted 21 lines
--- include/uapi/linux/usb/ch9.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)include/uapi/linux/usb/ch9.h +5
-1@@ -981,7 +981,11 @@ struct usb_ssp_cap_descriptor {#define USB_SSP_MIN_RX_LANE_COUNT (0xf << 8)#define USB_SSP_MIN_TX_LANE_COUNT (0xf << 12)__le16 wReserved; -__le32 bmSublinkSpeedAttr[1 ];/* list of sublink speed attrib entries */ +union { +__le32 legacy_padding; +/* list of sublink speed attrib entries */ + __DECLARE_FLEX_ARRAY(__le32, bmSublinkSpeedAttr); + };#define USB_SSP_SUBLINK_SPEED_SSID (0xf)/* sublink speed ID */ #define USB_SSP_SUBLINK_SPEED_LSE (0x3 << 4)/* Lanespeed exponent */ #define USB_SSP_SUBLINK_SPEED_LSE_BPS 0
Borislav Petkov
Tested-byQuoted 1 line · Greg Kroah-Hartman
Boris, can you test if this fixes the issue you see or not?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 24 lines · Greg Kroah-Hartman
Quoted 14 lines · Kees Cook
Since commit
df8fc4e934c1("kbuild: Enable -fstrict-flex-arrays=3"),UBSAN_BOUNDSno longer pretends 1-element arrays are unbounded. Walking bmSublinkSpeedAttr will trigger a warning, so make it a proper flexible array. Add a union to keep the struct size identical for userspace in case anything was depending on the old size.False positive warning was:
UBSAN: array-index-out-of-bounds in drivers/usb/host/xhci-hub.c:231:31 index 1 is out of range for type '__le32 [1]'for this line of code:
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);Quoted 8 lines
Reported-by Borislav Petkov <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>--- include/uapi/linux/usb/ch9.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 1 line
Thanks for the quick response, I'll queue it up after 6.5-rc1 is out.
I'm going to send this before -rc1, since we've had another report[1] that was fixed by this. Given the verification there and Boris's testing, I think this is good to land. I'll toss it in -next now and send it to Linus on Friday after making sure there are no more surprises.
-Kees
[1] https://lore.kernel.org/lkml/[email protected]/
Signature · 1 line
Kees Cook
Quoted 27 lines · Kees Cook
Quoted 24 lines · Greg Kroah-Hartman
Quoted 14 lines · Kees Cook
Since commit
df8fc4e934c1("kbuild: Enable -fstrict-flex-arrays=3"),UBSAN_BOUNDSno longer pretends 1-element arrays are unbounded. Walking bmSublinkSpeedAttr will trigger a warning, so make it a proper flexible array. Add a union to keep the struct size identical for userspace in case anything was depending on the old size.False positive warning was:
UBSAN: array-index-out-of-bounds in drivers/usb/host/xhci-hub.c:231:31 index 1 is out of range for type '__le32 [1]'for this line of code:
ssp_cap->bmSublinkSpeedAttr[offset++] = cpu_to_le32(attr);Quoted 8 lines
Reported-by Borislav Petkov <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>--- include/uapi/linux/usb/ch9.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)Quoted 1 line
Thanks for the quick response, I'll queue it up after 6.5-rc1 is out.
Quoted 8 lines
I'm going to send this before -rc1, since we've had another report[1] that was fixed by this. Given the verification there and Boris's testing, I think this is good to land. I'll toss it in -next now and send it to Linus on Friday after making sure there are no more surprises.
-Kees
No problem: