Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3294428pxk; Mon, 21 Sep 2020 09:55:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi1O3qODsybtJy9y5PdOTAXKQteKXXh29Zr263rl3QNACNQsttudt7NayK5G90kbI8hkNv X-Received: by 2002:a05:6402:644:: with SMTP id u4mr591750edx.182.1600707307509; Mon, 21 Sep 2020 09:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707307; cv=none; d=google.com; s=arc-20160816; b=gsWDWcSfIaLCl+LzH++UNnt4w0dujIExN5kW8AmN87BItZnOXVm+1e4xaDJKTlR9St btkPgCljLbcFhqlAcsmL47CWDWZomvE6IPm1soz0BtMwyiiKgJh/QtNaYgpWbI6OBY3b mVrDQd2XWvkitN5rMzPa7v6eomKaC80P8FHDxSPRCCObMC9PRgLtBzPr7kIJM+atYjXR vh9sKmJRJltNaX4jsXl0ZxebcB6vSVcsPRv/dv12yUvL0H6GwoXNJo8K7X8wrCMt8Yao 8JAQqbhGGwkntAYy4vElKV+spYVtVkGp4ebJXRvUE4ocg5FfH99acGrAr8UkXr2HPAj4 t2TA== 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=7kCGLYkmXIEJBN7cWnu/4vobo0zBoQ7f5cDFI1/SkL4=; b=c2axBfHXZtMsfBsBuFPO+unH+G//OMDYFMwN+DUvikmURYl2IStgpVq3eAbgJzX/LX GJgRjbUUH6TijuIe2TX9PR9OxN2te7nOEjMgswC78uZKbzWF1f7pkBQ/kxWOStAn2J+s fq2JCE6hhzbfxkajHgcN6C8IBCqW9Zxvas0SATGbmyuVis2I4/d3rWTwR8DL/3WnTAkD FHM8BPyCVmlXOZRFfuaH4OiQt4/9nel6311DXEyiAxCz7GIe3RMQjDjCw97QR7WqyKFx byxm1wgqJ3GB2hTaEuhf1T/etJ1hZ3jq2oAue9HGx4zJI4dRqKFpD2xc6AhIZ3/xTKN9 DpHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ilICyG/z"; 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 a21si8211122eds.368.2020.09.21.09.54.40; Mon, 21 Sep 2020 09:55:07 -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="ilICyG/z"; 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 S1727745AbgIUQxn (ORCPT + 99 others); Mon, 21 Sep 2020 12:53:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:53820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728424AbgIUQrH (ORCPT ); Mon, 21 Sep 2020 12:47:07 -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 1DB5D23888; Mon, 21 Sep 2020 16:47:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706826; bh=xZPIUDxZ6XjiG2PBxafL20G65Jt35WLLPvkj6a2Hvb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ilICyG/zYiuJCissarwIoFvfhzrQDLngTRNgSN8QBOf6HUN2Tjz4fISoTiAOqozQS cJMR1ychBgnNI39gi0yu7A9FM1ztMvKaUJnMSGEiVKSB5GX6aBLyMqK9wnvapLd765 cE+vSHE4XETsj7ZJzjxAUnYl3dTc7d6pZmwl08zU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Quentin Perret Subject: [PATCH 5.8 109/118] ehci-hcd: Move include to keep CRC stable Date: Mon, 21 Sep 2020 18:28:41 +0200 Message-Id: <20200921162041.444850361@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@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 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -14,7 +14,6 @@ */ /*-------------------------------------------------------------------------*/ -#include #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)