Page MenuHomeFreeBSD

Fix undefined behaviour in the USB controllers
ClosedPublic

Authored by andrew on Jan 12 2022, 10:38 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 19, 11:03 PM
Unknown Object (File)
Wed, Mar 19, 6:24 AM
Unknown Object (File)
Mon, Mar 10, 11:12 AM
Unknown Object (File)
Feb 10 2025, 9:16 AM
Unknown Object (File)
Feb 10 2025, 8:47 AM
Unknown Object (File)
Feb 4 2025, 1:01 AM
Unknown Object (File)
Jan 27 2025, 4:45 PM
Unknown Object (File)
Jan 26 2025, 5:53 PM
Subscribers

Details

Summary

The USB controller drivers assume they can cast a NULL pointer to a
struct and find the address of a member. KUBSan complains about this so
replace with the __offsetof macro that uses sither a builtin function
where available, or the same method on older compilers.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/dev/usb/controller/atmegadci.c
81

I would suggest to use __containerof() here to replace everything inside these macros BUS2SC macros.

__containerof(bus, struct atmegadci_softc, sc_bus)

Also make sure that all build targets inside stand/usb are building after this change.

And update the commit message with the containerof bits.

This revision is now accepted and ready to land.Jan 12 2022, 12:28 PM

I already changed it locally, unfortunately it doesn't update the review automatically.

sys/dev/usb/controller/atmegadci.c
81

Is stand/usb used by any of the loaders? It's broken for me on arm64, e.g. bus_topo_lock is undefined in usb_controller.c

I'll have a look at stand/usb later then.

It is not used by any official loaders.

Is stand/usb used by any of the loaders? It's broken for me on arm64, e.g. bus_topo_lock is undefined in usb_controller.c

@imp : Do you mind adding two dummy functions bus_topo_lock() and bus_topo_unlock() to the kernel emulation shims in stand/usb ?

There are a few other errors I've seen when building with make -k