Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp176385imd; Wed, 31 Oct 2018 16:51:28 -0700 (PDT) X-Google-Smtp-Source: AJdET5eAua0WoLHGXU/Jo7bAwGwCjW+GnvBXxaN7rGJ9Ud/VfXwfodTlWCUeJ9vFMxFKhAsszGhS X-Received: by 2002:a63:1066:: with SMTP id 38-v6mr5080906pgq.254.1541029888636; Wed, 31 Oct 2018 16:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029888; cv=none; d=google.com; s=arc-20160816; b=fXYxOGQmMoHrzW74iSwQU3Urq72j/bgekvwMXhv+lCU9svT+fxX7wjXWopORvtq9Ut kZ/2caxQVgxwI77m8t6y6OOO/3Rm7ik8TiB8DNQ/kAFifKC2VmsdMr9bVcvceafW7fmu LrOisWD02Tb/sdTi4j4Rd3vGBvHQfpz7Qx2I5dL6/Zg4MzTnngDLv0qWBA1ObE1f/0WS wKl1sZGMKAB+7I0wUvrl6+1T9I/PIOjUz0uDiKZwElu4pLCV0pCRaxGzjrdo/M5ZJ225 EZkWJTwv14R6X77oUMHnKN6VZdZTwPpXuZ6lSQ+byRc0+O+PnQlNYRp28+puskzX/y+6 mChg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=7dbEFi2isFNzaEqkeLH1DWcnh7+pNmA1xtaWhW+dKv4=; b=M6zX4sTwtoPMlFn0PbX90pyCGCDybVrhT8yyVzXx03SaKLCXqyx03v+EJ8HbkqcmCQ Ir3lHNUDDH1kUDb99+tNVMYgOe+Fa/x/iv00yNolip7K9VvKVN9iKHmFxbBvId4/TmTe x8qHLLf8QPAoyHn16VzOkS7YKqBEcal8Unqrdid3jKTYVIe12HQ8poyp6qV1LCW3F0l9 W3ZSZlvfUzPTiG2qHl4yx+ueZ7QAlKDvi52oaJQPsdar79aQT0p/7FBIbN72ZoPh+SFB KrnyG4iiQwqL5hHUJluvXUws//bSFAzLvPaoKLpmURFr9yHYCSCPDkwnJrqDUWg7AoUV Iwmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pBTlPY4x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11-v6si30019642pgj.409.2018.10.31.16.51.13; Wed, 31 Oct 2018 16:51:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pBTlPY4x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728156AbeKAIGh (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:53638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728133AbeKAIGh (ORCPT ); Thu, 1 Nov 2018 04:06:37 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 33FE720848; Wed, 31 Oct 2018 23:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027186; bh=6EgiTXOrwfLghNJdk5MY3htzX8wi0Djm0JrWUTRY55g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pBTlPY4xX0IbPoW+vjwHXwOgA1mCfuN+mc2Exl2bIc6klgNGqAufz2WC9VJL0/fpD egwgN5RLbjMtFS8m3b+MOKE7ds/THMk2ss8jluVjUifPVCveZNjvVcKM2nr2IgtlLX lo0B8zzsOvvlFiQN5925h9LvXms1Es71lmPa+p00= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ben Hutchings , Ard Biesheuvel , Sasha Levin Subject: [PATCH AUTOSEL 4.19 049/146] x86: boot: Fix EFI stub alignment Date: Wed, 31 Oct 2018 19:04:04 -0400 Message-Id: <20181031230541.28822-49-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ben Hutchings [ Upstream commit 9c1442a9d039a1a3302fa93e9a11001c5f23b624 ] We currently align the end of the compressed image to a multiple of 16. However, the PE-COFF header included in the EFI stub says that the file alignment is 32 bytes, and when adding an EFI signature to the file it must first be padded to this alignment. sbsigntool commands warn about this: warning: file-aligned section .text extends beyond end of file warning: checksum areas are greater than image size. Invalid section table? Worse, pesign -at least when creating a detached signature- uses the hash of the unpadded file, resulting in an invalid signature if padding is required. Avoid both these problems by increasing alignment to 32 bytes when CONFIG_EFI_STUB is enabled. Signed-off-by: Ben Hutchings Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- arch/x86/boot/tools/build.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index d4e6cd4577e5..bf0e82400358 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -391,6 +391,13 @@ int main(int argc, char ** argv) die("Unable to mmap '%s': %m", argv[2]); /* Number of 16-byte paragraphs, including space for a 4-byte CRC */ sys_size = (sz + 15 + 4) / 16; +#ifdef CONFIG_EFI_STUB + /* + * COFF requires minimum 32-byte alignment of sections, and + * adding a signature is problematic without that alignment. + */ + sys_size = (sys_size + 1) & ~1; +#endif /* Patch the setup code with the appropriate size parameters */ buf[0x1f1] = setup_sectors-1; -- 2.17.1