Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4DF5C64EC4 for ; Wed, 8 Mar 2023 16:15:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbjCHQP0 (ORCPT ); Wed, 8 Mar 2023 11:15:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbjCHQPX (ORCPT ); Wed, 8 Mar 2023 11:15:23 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6904A6586; Wed, 8 Mar 2023 08:15:22 -0800 (PST) Received: from mail.ispras.ru (unknown [83.149.199.84]) by mail.ispras.ru (Postfix) with ESMTPSA id 98CF740737C6; Wed, 8 Mar 2023 16:15:20 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 98CF740737C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1678292120; bh=6HCHXUJhJp0VIvr8sxomfDwRvRVkrxfUfl6ds5kRe8o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=M1NjzfVl3wVvCvZccFGigwqQSrSm4g6cN15uz2oilsnU0McX0b807Arj7OQYdC1ll Vcve7bZPLBGyRIbs+2rShB6JuuXQfJDic2vaWzZObqet5spYvzkHFuPCbgWs3ucwfr 2iHptNIBm7Xp3E8di+148eO72nNijyAEveCV8fOU= MIME-Version: 1.0 Date: Wed, 08 Mar 2023 19:15:20 +0300 From: Evgeniy Baskov To: Ard Biesheuvel Cc: Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , "Limonciello, Mario" , joeyli , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v4 06/26] x86/boot: Setup memory protection for bzImage code In-Reply-To: References: <63ea4796323a734c061ad774a68c88a47f5669a4.1671098103.git.baskov@ispras.ru> User-Agent: Roundcube Webmail/1.4.4 Message-ID: <5248590f6b1dad1732334af630035732@ispras.ru> X-Sender: baskov@ispras.ru Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-03-08 13:47, Ard Biesheuvel wrote: > On Thu, 15 Dec 2022 at 13:38, Evgeniy Baskov wrote: >> >> Use previously added code to use 4KB pages for mapping. Map compressed >> and uncompressed kernel with appropriate memory protection attributes. >> For compressed kernel set them up manually. For uncompressed kernel >> used flags specified in ELF header. >> >> Tested-by: Mario Limonciello >> Tested-by: Peter Jones >> Signed-off-by: Evgeniy Baskov >> > > This patch breaks the 'nokaslr' command line option (at least with > SeaBIOS) unless I apply the hunk below: > Oh, I didn't think of that option.. Thanks! I will also add the check to the identity mapping, so the warning won't be emitted with 'nokaslr'. > > --- a/arch/x86/boot/compressed/misc.c > +++ b/arch/x86/boot/compressed/misc.c > @@ -329,7 +329,8 @@ static size_t parse_elf(void *output, unsigned > long output_len, > > handle_relocations(output, output_len, virt_addr); > > - if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE)) > + if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE) || > + cmdline_find_option_bool("nokaslr")) > goto skip_protect; > > for (i = 0; i < ehdr.e_phnum; i++) { > @@ -481,8 +482,10 @@ asmlinkage __visible void *extract_kernel(void > *rmode, memptr heap, > * If KASLR is disabled input and output regions may overlap. > * In this case we need to map region excutable as well. > */ > - unsigned long map_flags = MAP_ALLOC | MAP_WRITE | > - (IS_ENABLED(CONFIG_RANDOMIZE_BASE) ? 0 : > MAP_EXEC); > + unsigned long map_flags = MAP_ALLOC | MAP_WRITE; > + if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE) || > + cmdline_find_option_bool("nokaslr")) > + map_flags |= MAP_EXEC; > phys_addr = kernel_add_identity_map(phys_addr, > phys_addr + needed_size, > map_flags);