Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp344395pxu; Thu, 7 Jan 2021 06:34:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD9w0uPdezvCppyxzDwoDld7wrDzzNUevS9Vabivaw/39BXZDEBFiNX8nsK9jMPzS9R+ss X-Received: by 2002:a17:906:82ce:: with SMTP id a14mr6561635ejy.421.1610030079560; Thu, 07 Jan 2021 06:34:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030079; cv=none; d=google.com; s=arc-20160816; b=ERwU1VE7Vrx86DyVBcC2KhtaAcviOGGH1aNS/p1jLbNE5l/TAXPutQZ5PLnC4pHm+n MmzrDEov269DzFHXZ72WM4oSTboXLKf5zVNnPPDxozbytY/ZRZWp7SjPMq/czWuE48K6 6k8FwMeIfEhq9yn2fEIgP9aIaVmug5pVsA62C7wht6behXE5Tmi3U5dQmyERcj7/3Fgc 9DS43HCmL5PYwQ/QFje6qs8yYsgGIL8tX+7fukHfFhGpXUojtEp5PXw3TFwcVU76y5Zp IcVXcyuOOQ8H4MOfIqrbLNCFEaDWJZU4qpCZ/e2H6+/55yX1mqhovDuRccIUHnzFIWC3 FkGQ== 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=iF+h63bx7Xq/YgYAs6KC25UPAqR3XWkPhQe64A0i8qQ=; b=aOjpZpuxzLrKIPSMtSUlTL8ANxD6w+HiZQNw7m2Kdbumo9zQAT/UFdw6Ga3x+1M4kV zOF9aFskZ0KMT8ZBSonXAFhSbvIjXAiP6fe1ByM/cMlIfXqo4flfBfsssFh86TVzrd6g SXXdfXdnCCmBB/vMNUEqv3sXZfN8hiRnJZCk+7msVA8WYWVGovRFNd+Nd7WlpdYzn9pD 5WyLUWu2EBpA8I4rgOSIsz2plpIpdLXrmagjezcI3GeElzbRzb334X73+V4O9LKcUyJ7 uslJ/N/DhIeqae5pEm3CICzCMdeK4QuqUamtAWgV1inkiSagDirDMNSsEL7gg/rEPOui kVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ql6k27dY; 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=pass (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 dp1si2227764ejc.21.2021.01.07.06.34.15; Thu, 07 Jan 2021 06:34:39 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=ql6k27dY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728837AbhAGObh (ORCPT + 99 others); Thu, 7 Jan 2021 09:31:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:45564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728808AbhAGObg (ORCPT ); Thu, 7 Jan 2021 09:31:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 84F9222EBF; Thu, 7 Jan 2021 14:30:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029843; bh=O52wO4kYeR2Q1muqTJRUz7LFtHpYXmI9ZhYDa5thG3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ql6k27dYZSEeA7xfCyOuyq3y+ArKUpE0xfsfJUne3tXjz5ofy7U6NjvvorYUkHxBO NjznXxtokrNo3jXyYshcb4IFc9e1K9bJnftQPR7Q3ODtz2eTY4eTen1Xhs5kkrRj6P 5KHDFtYqxkrAkkbiMpJBGiUMC/wxVjW1Q5SiKL2c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 4.14 14/29] of: fix linker-section match-table corruption Date: Thu, 7 Jan 2021 15:31:29 +0100 Message-Id: <20210107143054.955934823@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210107143052.973437064@linuxfoundation.org> References: <20210107143052.973437064@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: Johan Hovold commit 5812b32e01c6d86ba7a84110702b46d8a8531fe9 upstream. Specify type alignment when declaring linker-section match-table entries to prevent gcc from increasing alignment and corrupting the various tables with padding (e.g. timers, irqchips, clocks, reserved memory). This is specifically needed on x86 where gcc (typically) aligns larger objects like struct of_device_id with static extent on 32-byte boundaries which at best prevents matching on anything but the first entry. Specifying alignment when declaring variables suppresses this optimisation. Here's a 64-bit example where all entries are corrupt as 16 bytes of padding has been inserted before the first entry: ffffffff8266b4b0 D __clk_of_table ffffffff8266b4c0 d __of_table_fixed_factor_clk ffffffff8266b5a0 d __of_table_fixed_clk ffffffff8266b680 d __clk_of_table_sentinel And here's a 32-bit example where the 8-byte-aligned table happens to be placed on a 32-byte boundary so that all but the first entry are corrupt due to the 28 bytes of padding inserted between entries: 812b3ec0 D __irqchip_of_table 812b3ec0 d __of_table_irqchip1 812b3fa0 d __of_table_irqchip2 812b4080 d __of_table_irqchip3 812b4160 d irqchip_of_match_end Verified on x86 using gcc-9.3 and gcc-4.9 (which uses 64-byte alignment), and on arm using gcc-7.2. Note that there are no in-tree users of these tables on x86 currently (even if they are included in the image). Fixes: 54196ccbe0ba ("of: consolidate linker section OF match table declarations") Fixes: f6e916b82022 ("irqchip: add basic infrastructure") Cc: stable # 3.9 Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20201123102319.8090-2-johan@kernel.org [ johan: adjust context to 5.4 ] Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- include/linux/of.h | 1 + 1 file changed, 1 insertion(+) --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1163,6 +1163,7 @@ static inline int of_get_available_child #define _OF_DECLARE(table, name, compat, fn, fn_type) \ static const struct of_device_id __of_table_##name \ __used __section(__##table##_of_table) \ + __aligned(__alignof__(struct of_device_id)) \ = { .compatible = compat, \ .data = (fn == (fn_type)NULL) ? fn : fn } #else