Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3287555pxk; Mon, 21 Sep 2020 09:45:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYbneIpdIRoQiYVDcZ04CPc0zoGP34MuHd3W+ZWCUB0PppgrStlBzo6nhsDZl6Sa8SYk7O X-Received: by 2002:a17:906:2458:: with SMTP id a24mr303545ejb.353.1600706709123; Mon, 21 Sep 2020 09:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706709; cv=none; d=google.com; s=arc-20160816; b=CXN5YqWLsQBQZywHnwAQLibO+uG1xzd8eIjWjLjA9NR90OtHeTlbaApmi3x8x1atok dBeBZNZV2hRu+qqeNH7odnuSeub/+jvAAeuCUuXMMxrVXPd0aBd9qPYYrHeL63Fd2vOj fD/8K4w7HgbqGJJmzWbe9P4nt6UhFqiH2a2ZD8eu7HSMDu7drYxws60gbMHy+2AnLkza QrB8EC7DX9gTbjUXKcuFbKH+GitSf8rK1ZQVA+A+6nGRRL3M7hNgZZgki1BW+nXwc6MR yDuxahCEEs3OVX0AxNwjzWZ/JWlbe4MurzfBvEf+ty9LKMNMYFZBTypoCetcJcXumtZT AXPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kvx5WbfByrYmR1LONB/T97AhmMPMLcp0ugvXGnEO8sY=; b=oNpYpby1P6QKPEwELKoJkkGt8XPBHHhsXU4qRrj11vlM41zOiHzMk0+ygPFZN8z7c2 QDSvAmJUF9KCSN6RM82IlcejFchRJjLlZyc/RNpbPYbFDn0r1/PqibvpuxBWwHJXImL0 436rqRRuEIt/fQQmHbFe+0utTOpAmczbRmJRvrODw1vGLOmdMnXwXW8Jlr0sdyJAf0/Q xShZbAld+CjKHhHYsddklTzVevZa8pLDkC7+7iBIuFrMJYNFjwVgZ6D0J6sZOliGjjRR n8t2QHddjkyNMXarU/2NthjXmgkBH6LCP7KZgLt/xVB/RsneUN8Gp3qXsbrtgvMXpfAH OqTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZKkNn7q4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si8413109ejr.489.2020.09.21.09.44.45; Mon, 21 Sep 2020 09:45:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZKkNn7q4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729400AbgIUQlB (ORCPT + 99 others); Mon, 21 Sep 2020 12:41:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:43602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729316AbgIUQkj (ORCPT ); Mon, 21 Sep 2020 12:40:39 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E04642076B; Mon, 21 Sep 2020 16:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706438; bh=t5qeN+stjGPNG6sn8aIddhIRBpgtz8iDOmvyk88XO1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZKkNn7q4fRcC2U66MNrZQdnzOfGy/82FwVTGqRmZNKur9/HW8e1vTKNiiojsJEDaM x5gf4e2R95VdtBjFoVe4U6vC8bwgpArGChtSu0V+0TAnjdAneh3nfx/dB+8j6aPVnj kInPlQegGALa123p8LmVv12egsgOh4hxIWE9VdpQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Quentin Perret Subject: [PATCH 4.14 92/94] ehci-hcd: Move include to keep CRC stable Date: Mon, 21 Sep 2020 18:28:19 +0200 Message-Id: <20200921162039.783431002@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Perret 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 Cc: stable Signed-off-by: Quentin Perret Link: https://lore.kernel.org/r/20200916171825.3228122-1-qperret@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-hcd.c | 1 + drivers/usb/host/ehci-hub.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -27,7 +27,6 @@ */ /*-------------------------------------------------------------------------*/ -#include #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)