Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13928229pxu; Mon, 4 Jan 2021 08:11:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJykP+OOryEI0l5yTUMzjROJ0cnJUXJ1jredXJyJ06oBW/Eb/6w8fX/zbWu3qJBqynn62qTH X-Received: by 2002:a17:906:8693:: with SMTP id g19mr70425875ejx.111.1609776682312; Mon, 04 Jan 2021 08:11:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609776682; cv=none; d=google.com; s=arc-20160816; b=fdp0VePGanm4s0QY8u681N85hveQtWG4BtWlNPLjEj8/1ev6iwLVvstI0q7dGVzbKY pk/IHsF1XbpIq88U/kbBwKrljI+Rz0Bw41TwDOAm0Dlk3O4fV/qF6aNzik9XX3XxSL4E lUzavBX5Qjvy1mltQ3C6EIQ8mMCXJJH5byuz3Su1zzzzjAsVG7xtwjU4jNPzg9eatXQi WeWeBVM/lLxBTSE4+iy2qyvvHjkC+VjDgYgdYodHYllCmL3n0OQ48NKgcim32/AwYZc5 Njyh3aarlWsHJzyj5ni1L6DhxSDv/HuU+gjqCyyc63mv4xnqw+IZ6F0k+lXD/priaAls VguQ== 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=2S7Zkk6pDasgH2RXJHSOD1nWP1PCnWjgZJhT+gq++34=; b=mO6QjrlELsJXr5hhYaYZe7qIW4t7MUgOxfEsLhVhexPu9MC0q3H83cT+jEzdTldKnh IIaaYhiia76zopcXmB6gr7lO6ieV2qN9+F1AnL2GV3ME7FvMC3eyWkZO606TmafkwAJ1 1qQF0ehjtWRpujQmJqwKBQQprkp10C0yB/bIgyHQ902K90fclV+h5TKUK8ZKPJgd7N0r 6tWg6HFuSroQeF+EqiIzcSWKkMZvFgUobmM/qnzuryhRevVVqJXYayykVO2VH7N1wSvi uGUG53cVpyLj9sRUJtT9WFqa8dcuj5p4xsIEZ3jqpVQL7teZRAtgWN9shVnuZ2ykwy+A ogOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GvzuBDua; 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 de28si31853728edb.166.2021.01.04.08.10.58; Mon, 04 Jan 2021 08:11:22 -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=GvzuBDua; 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 S1729590AbhADQId (ORCPT + 99 others); Mon, 4 Jan 2021 11:08:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:38956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728639AbhADQBn (ORCPT ); Mon, 4 Jan 2021 11:01:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F4EA22512; Mon, 4 Jan 2021 16:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609776062; bh=hvrdvZ+ahAgbzq7pkKX+K/nK2pZ+Q7JAD23qSduyhOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GvzuBDuaHCOuQew97Vaef35UWEmyRJiQyL749kMBNvRuoR1R74CmvWRa93V7GS5oK B+Ujv+2caRJ9JFbXbOdCeXse1rau67xZ6nNSANJp3eKvlqjDPYq+HOOeBIh0Dr58b1 BBzMwnnCV4SVUySTSD0ZoCMuAvUF8ihxuj4ueudU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 5.4 22/47] of: fix linker-section match-table corruption Date: Mon, 4 Jan 2021 16:57:21 +0100 Message-Id: <20210104155706.814288920@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155705.740576914@linuxfoundation.org> References: <20210104155705.740576914@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 @@ -1282,6 +1282,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