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)
Sun, Sep 8, 6:30 AM
Unknown Object (File)
Wed, Sep 4, 6:53 PM
Unknown Object (File)
Tue, Aug 20, 8:42 PM
Unknown Object (File)
Sun, Aug 18, 2:08 AM
Unknown Object (File)
Aug 8 2024, 10:49 AM
Unknown Object (File)
Aug 6 2024, 4:14 AM
Unknown Object (File)
Aug 5 2024, 10:28 PM
Unknown Object (File)
Aug 3 2024, 10:36 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