From patchwork Tue Apr 24 11:00:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 134061 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2080816lji; Tue, 24 Apr 2018 04:01:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+1w7KtU3neUzxgSfchOKeTg5n9rbi8efQMKIsWtoSWkPIVSuRi9kRHVxfVDJVN/W1vvTns X-Received: by 10.99.144.196 with SMTP id a187mr19778220pge.189.1524567666456; Tue, 24 Apr 2018 04:01:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524567666; cv=none; d=google.com; s=arc-20160816; b=R0/QtH8uQ37ZUPMkvy2/KKjqYPEHGYV7TbY+oqoTq1hbCotG+MuhArzeMq/Qz1T09z HRVl/6m/ewBml7AadAqHnNcLDMS4CeGWm5NY9r9x1JbXosyEfFNuwoLuSIPiGwN1PJrO 4NY4VU9/x12IidYiW1ggTD8QiRLN2HxZCoVfrfFoMXN30bfCuJrj1a58BmIkJvyABt+X b6JCjrAHGlwTtV9qEKSjSG27pwMglt5KoHYnsZ3sdV22+OTQmM8NyGK8tydzR0nCWuAa W09dTJigQziQWbfSP6zlHpmPpEVMs4poAgImcWyfkXfAcbx2D3ic4lrGJJceZEnpcqPn B90g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ztmcJvSMReO3W18ekgke1r7HFA3vZjdvjGb+3pwaziQ=; b=z7buKeIhgrs9hhrdKr9PEcPTMSOLjBa2avbHkC7Qv5Wd0JcBlbjy4mH9b1CkmO9fyg 6GDO4OLyUSB4rjjI5xDNvHIn5S+wGo9XgdV+JjsjAt7y4vdEbjw8artDII3He9U7IiXG XSookUyVPfFCFtuEBcHfsE/T/+Om+Xs5jlwri5TKk4xKrsGmqX4ment0yzmi+o07Xu90 +PLxZ0bp1WjPDrBO8yKeOi26wS1Y5h/ZordAx8ML6A8T/r14wH2B8+1VPuHVYAnl9dIg 9EEfxMR3EQlFo22J2+ANvfHfUQF90azcx/vEn52Vi0XQ8AEwCA+lt9Ld3M8Sv+WPbJIU u72g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h23-v6si13365966plr.576.2018.04.24.04.01.06; Tue, 24 Apr 2018 04:01:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756013AbeDXLBF (ORCPT + 2 others); Tue, 24 Apr 2018 07:01:05 -0400 Received: from foss.arm.com ([217.140.101.70]:51406 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755329AbeDXLBF (ORCPT ); Tue, 24 Apr 2018 07:01:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E907780D; Tue, 24 Apr 2018 04:01:04 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D8D633F25D; Tue, 24 Apr 2018 04:01:03 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: kim.phillips@arm.com, Mark Rutland , Ard Biesheuvel , linux-efi@vger.kernel.org Subject: [PATCH] efi/libstub/arm64: handle randomized TEXT_OFFSET Date: Tue, 24 Apr 2018 12:00:58 +0100 Message-Id: <20180424110058.29344-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org When CONFIG_RANDOMIZE_TEXT_OFFSET is selected, TEXT_OFFSET is an arbitrary multiple of PAGE_SIZE in the interval [0, 2MB). The EFI stub doesn't accuont for this, and only handles the case where TEXT_OFFSET is multiple of EFI_KIMG_ALIGN. This can result in the kernel being loaded to an erroneous physical alignment. This has been observed to result in spurious stack overflow reports and failure to make use of the IRQ stacks, and theoretically could result in a number of other issues. We can OR in the low bits of TEXT_OFFSET to ensure that we have the necessary offset (and hence have the necessary alignment), so let's do that. Fixes: 6f26b3671184c36d ("arm64: kaslr: increase randomization granularity") Reported-by: Kim Phillips Signed-off-by: Mark Rutland Cc: Ard Biesheuvel Cc: linux-efi@vger.kernel.org --- drivers/firmware/efi/libstub/arm64-stub.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Ard Biesheuvel Tested-by: Kim Phillips diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c index b9bd827caa22..541b82fdc8a2 100644 --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -98,6 +98,13 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg, (phys_seed >> 32) & mask : TEXT_OFFSET; /* + * With CONFIG_RANDOMIZE_TEXT_OFFSET, TEXT_OFFSET may not be a + * multiple of EFI_KIMG_ALIGN, and we must ensure that we apply + * the offset below EFI_KIMG_ALIGN. + */ + offset |= (TEXT_OFFSET % EFI_KIMG_ALIGN); + + /* * If KASLR is enabled, and we have some randomness available, * locate the kernel at a randomized offset in physical memory. */