From patchwork Fri Sep 8 15:31:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9944519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 900B36035D for ; Fri, 8 Sep 2017 15:33:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D88D287ED for ; Fri, 8 Sep 2017 15:33:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 702A4287F1; Fri, 8 Sep 2017 15:33:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C72F287ED for ; Fri, 8 Sep 2017 15:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=EtwDqOTa8nN3Wg0TNCkn8UbdkP1GFJbOxF/2xdy9x1k=; b=Wkp s2swHpyFG5W6o9TLWSW8/BanD6NBcOxjGMZxgRSYif18KyidU8NBs3lf0MV3WbF47/UWSb04SerJy 1pKah6oV9esW8B3HABGH4t9VG2fzDgRyiTv+SJTqFTytzZEEuUUJBtzUy2RrNCA0NjC2gSqENizbK TRIBgh1ROwcPzRib3frgMItojmWzbip8JMBcWzOrAt5dRsyz2lvLiXRpCpi7sl+SyhzB0geXJZcgo OL1GxgIfWeFVoU17bzL0sjq1rtajBGxiK+RTrPVhqYf0ZuJeONKHeyWMAQJRKAYxVRS1fTOHztwvy P2rM4VpquuWgdoiQ7nbiJXvH+IkDmsw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dqLGw-0004Kg-Lf; Fri, 08 Sep 2017 15:32:46 +0000 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dqLGV-0004Iz-6m for linux-arm-kernel@lists.infradead.org; Fri, 08 Sep 2017 15:32:23 +0000 Received: by mail-wr0-x232.google.com with SMTP id a43so5358493wrc.0 for ; Fri, 08 Sep 2017 08:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=LZ5fC5jp5Onx0pNMOc19SjpXF8kV5F6T6iYhkCAY/D8=; b=P6orzCV0/Ryoz+e4T/nEVCUlkpB5LqY06Ma0SQ/c84dJz+v07i2UyHw8b8wQ2k0T22 3XluAX2+hMgYgjJphL2NBtJ5+HacWKqDb/E+vQ80L0nxOVVqwoG20Q7B/PyesJFnaQrX 7uSgCTZS5iKhGR48UGpZfxXehdE6YtRnQS+gA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LZ5fC5jp5Onx0pNMOc19SjpXF8kV5F6T6iYhkCAY/D8=; b=RYQs2oguuqL/DC2joVbPzUZz+H89a9fIcdPZnXdpsf6TD349WbxIAJXpXcn8xBmRaR 8ZrPU3FZYWh9Kmsoe4zyOW9lukCedY2rm2uxo4kelDXpW4bPr/30YIsF18B0H9oOEU2X wde3whd9dj16wyaNk85YQ59iFM7SmA4XqSu2MvODcY5H6kUnMwm5kmofSiBwPcKgWLgL biZER3tfdj6+XbNWb+Ih61N3mAPA6Jn7JYTdtOsMHyffQ2t+5Vg3cQJlh9tsmHFGYeF7 brdDmw/EWat5LNLfeLcCDqscWjciX4HOIvhnXOQmwMoPejotYqJUt87T43AHk+0Ug1t2 PWlw== X-Gm-Message-State: AHPjjUh7NFAz9avxnhNbuZxD/ttgin9SDEB6KLysU9GKEUClYzeh95JQ W4QJm5zN7B8v8Ctjvu0Keg== X-Google-Smtp-Source: ADKCNb40afrCAnJLfLJo70OwdZzGtWxhgGjfY5ZCwJzJ9Zlt7uB1ICPganWidO7xJpKqumkIRxVZdg== X-Received: by 10.223.133.244 with SMTP id 49mr2254306wru.153.1504884716875; Fri, 08 Sep 2017 08:31:56 -0700 (PDT) Received: from localhost.localdomain ([154.151.223.220]) by smtp.gmail.com with ESMTPSA id a69sm1197299wme.29.2017.09.08.08.31.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 08:31:56 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] ARM: compressed: discard ksym/kcrctab input section Date: Fri, 8 Sep 2017 16:31:43 +0100 Message-Id: <20170908153143.27279-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170908_083222_180498_4E89374C X-CRM114-Status: GOOD ( 11.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gregory.clement@free-electrons.com, Russell King , arnd@arndb.de, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP As it turns out, building the ARM kernel with EFI support pulls in a couple of sections that we don't really need in the decompressor. This is due to the fact the the UEFI stub uses sort() to sort the UEFI memory map, which is an exported symbol pulled in from lib/sort.c. Before commit e4bae4d0b5f3 ("arm/efi: Split zImage code and data into separate PE/COFF sections"), this resulted in the following layout for the decompressor ELF binary. [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 010000 009b3c 00 AX 0 0 512 [ 2] .rodata PROGBITS 00009b3c 019b3c 001684 00 A 0 0 4 [ 3] __ksymtab_strings PROGBITS 0000b1c0 01b1c0 000005 00 A 0 0 1 [ 4] .data PROGBITS 0000b1c8 01b1c8 000020 00 WA 0 0 8 [ 5] ___ksymtab+sort PROGBITS 0000b1e8 01b1e8 000008 00 WA 0 0 4 [ 6] .piggydata PROGBITS 0000b1f0 01b1f0 77ac38 00 A 0 0 1 [ 7] .got.plt PROGBITS 00785e28 795e28 00000c 04 WA 0 0 4 [ 8] .got PROGBITS 00785e34 795e34 000028 00 WA 0 0 4 [ 9] .pad PROGBITS 00785e5c 795e5c 000004 00 WA 0 0 1 [10] .bss NOBITS 00785e60 795e60 00001c 00 WA 0 0 4 [11] .stack NOBITS 00785e80 795e60 001000 00 WA 0 0 1 Commit e4bae4d0b5f3 made some changes to the linker script to allow the UEFI firmware to map the decompressor with strict R-X/RW- permissions before invoking it. Unfortunately, this turns out to break the boot on some systems, because the linker now also moves the ksymtab/kcrctab sections around, resulting in .piggydata to appear misaligned. [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 010000 00a93c 00 AX 0 0 4096 [ 2] .rodata PROGBITS 0000a93c 01a93c 001684 00 A 0 0 4 [ 3] __ksymtab_strings PROGBITS 0000bfc0 01bfc0 000005 00 A 0 0 1 [ 4] .piggydata PROGBITS 0000bfc5 01bfc5 77ac47 00 A 0 0 1 [ 5] .got.plt PROGBITS 00786c0c 796c0c 00000c 04 WA 0 0 4 [ 6] .got PROGBITS 00786c18 796c18 000028 00 WA 0 0 4 [ 7] .pad PROGBITS 00786c40 796c40 000008 00 WA 0 0 1 [ 8] .data PROGBITS 00787000 797000 000200 00 WA 0 0 4096 [ 9] ___ksymtab+sort PROGBITS 00787200 797200 000008 00 WA 0 0 4 [10] .bss NOBITS 00787208 797208 00001c 00 WA 0 0 4 [11] .stack NOBITS 00787228 797208 001000 00 WA 0 0 1 So let's align piggydata explicitly, and discard these sections from the binary. Cc: Russell King Fixes: e4bae4d0b5f3 ("arm/efi: Split zImage code and data into separate ...") Tested-by: Gregory CLEMENT Signed-off-by: Ard Biesheuvel Tested-by: Matthias Brugger --- arch/arm/boot/compressed/piggy.S | 1 + arch/arm/boot/compressed/vmlinux.lds.S | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/arm/boot/compressed/piggy.S b/arch/arm/boot/compressed/piggy.S index f72088495f43..5d52c556dd32 100644 --- a/arch/arm/boot/compressed/piggy.S +++ b/arch/arm/boot/compressed/piggy.S @@ -1,5 +1,6 @@ .section .piggydata,#alloc .globl input_data + .align 2 input_data: .incbin "arch/arm/boot/compressed/piggy_data" .globl input_data_end diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S index 7a4c59154361..5c5265be4605 100644 --- a/arch/arm/boot/compressed/vmlinux.lds.S +++ b/arch/arm/boot/compressed/vmlinux.lds.S @@ -29,6 +29,7 @@ SECTIONS * of the text/got segments. */ *(.data) + *(*ksymtab* *kcrctab*) } . = TEXT_START;