Page MenuHomeFreeBSD

Fix undefined behaviour in the USB controllers
ClosedPublic

Authored by andrew on Jan 12 2022, 10:38 AM.
Tags
None
Referenced Files
F102041591: D33865.id101357.diff
Wed, Nov 6, 9:19 PM
Unknown Object (File)
Tue, Nov 5, 6:04 AM
Unknown Object (File)
Mon, Nov 4, 5:09 PM
Unknown Object (File)
Fri, Nov 1, 4:54 PM
Unknown Object (File)
Sun, Oct 20, 6:49 PM
Unknown Object (File)
Fri, Oct 18, 3:16 PM
Unknown Object (File)
Fri, Oct 18, 12:48 PM
Unknown Object (File)
Thu, Oct 17, 2:50 AM
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