TencentOS-kernel/drivers/usb
Quentin Perret a4698ba8f2 ehci-hcd: Move include to keep CRC stable
commit 29231826f3bd65500118c473fccf31c0cf14dbc0 upstream.

The CRC calculation done by genksyms is triggered when the parser hits
EXPORT_SYMBOL*() macros. At this point, genksyms recursively expands the
types of the function parameters, and uses that as the input for the CRC
calculation. In the case of forward-declared structs, the type expands
to 'UNKNOWN'. Following this, it appears that the result of the
expansion of each type is cached somewhere, and seems to be re-used
when/if the same type is seen again for another exported symbol in the
same C file.

Unfortunately, this can cause CRC 'stability' issues when a struct
definition becomes visible in the middle of a C file. For example, let's
assume code with the following pattern:

    struct foo;

    int bar(struct foo *arg)
    {
	/* Do work ... */
    }
    EXPORT_SYMBOL_GPL(bar);

    /* This contains struct foo's definition */
    #include "foo.h"

    int baz(struct foo *arg)
    {
	/* Do more work ... */
    }
    EXPORT_SYMBOL_GPL(baz);

Here, baz's CRC will be computed using the expansion of struct foo that
was cached after bar's CRC calculation ('UNKOWN' here). But if
EXPORT_SYMBOL_GPL(bar) is removed from the file (because of e.g. symbol
trimming using CONFIG_TRIM_UNUSED_KSYMS), struct foo will be expanded
late, during baz's CRC calculation, which now has visibility over the
full struct definition, hence resulting in a different CRC for baz.

The proper fix for this certainly is in genksyms, but that will take me
some time to get right. In the meantime, we have seen one occurrence of
this in the ehci-hcd code which hits this problem because of the way it
includes C files halfway through the code together with an unlucky mix
of symbol trimming.

In order to workaround this, move the include done in ehci-hub.c early
in ehci-hcd.c, hence making sure the struct definitions are visible to
the entire file. This improves CRC stability of the ehci-hcd exports
even when symbol trimming is enabled.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20200916171825.3228122-1-qperret@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-16 16:36:22 +08:00
..
atm Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
c67x00 USB: c67x00: fix use after free in c67x00_giveback_urb 2021-03-16 16:32:07 +08:00
cdns3 usb: cdns3: gadget: always zeroed TRB buffer when enable endpoint 2021-03-16 16:34:55 +08:00
chipidea usb: chipidea: core: add wakeup support for extcon 2021-03-16 16:32:08 +08:00
class usblp: fix race between disconnect() and read() 2021-03-16 16:36:20 +08:00
common Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
core USB: quirks: Add USB_QUIRK_IGNORE_REMOTE_WAKEUP quirk for BYD zhaoxin notebook 2021-03-16 16:36:19 +08:00
dwc2 usb: dwc2: Fix error path in gadget registration 2021-03-16 16:33:38 +08:00
dwc3 usb: dwc3: gadget: Handle ZLP for sg requests 2021-03-16 16:35:18 +08:00
early USB: early: Handle AMD's spec-compliant identifiers, too 2021-03-16 16:26:55 +08:00
gadget USB: gadget: u_f: Unbreak offset calculation in VLAs 2021-03-16 16:35:17 +08:00
host ehci-hcd: Move include to keep CRC stable 2021-03-16 16:36:22 +08:00
image Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
isp1760 Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
misc USB: yurex: Fix bad gfp argument 2021-03-16 16:35:16 +08:00
mon Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
mtu3 usb: mtu3: clear dual mode of u3port when disable device 2021-03-16 16:33:22 +08:00
musb usb: musb: Fix runtime PM imbalance on error 2021-03-16 16:28:52 +08:00
phy usb: phy: twl6030-usb: Fix a resource leak in an error handling path in 'twl6030_usb_probe()' 2021-03-16 16:28:29 +08:00
renesas_usbhs usb: renesas_usbhs: getting residue from callback_result 2021-03-16 16:31:01 +08:00
roles Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
serial USB: serial: option: add support for SIM7070/SIM7080/SIM7090 modules 2021-03-16 16:36:09 +08:00
storage USB: UAS: fix disconnect by unplugging a hub 2021-03-16 16:36:19 +08:00
typec usb: typec: ucsi: Prevent mode overrun 2021-03-16 16:36:20 +08:00
usbip Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
Kconfig Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
Makefile Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
usb-skeleton.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00