Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6611459rdb; Tue, 2 Jan 2024 07:29:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5+Na9AlcWT7DgcVh88xbbzQbOtzDugqbvhdbquuf9gfTLEpOOHeposzXbdR2jAFxsQPKF X-Received: by 2002:a17:90a:4b88:b0:28b:db20:3803 with SMTP id i8-20020a17090a4b8800b0028bdb203803mr9114354pjh.46.1704209397031; Tue, 02 Jan 2024 07:29:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704209397; cv=none; d=google.com; s=arc-20160816; b=WhtdnYSb8bd9aSm6avNpLthtOeOvSDYblLDonc43nb4P9n17jVhafTQVUQG3UqetUh wDUGHtRv1lWLgT3Jm73kHj1xBkP7kmoo1TRqyU/D8CWCJXV6Oll4kL1sX7c3oU0J8LQy Yr/yfLr9nTn9asfbf6k3GSF9//9KS9zaCOp4lwZma74nHfIv3MQHhKnnecXCrxVMwfsm LH+iD+HM1WJYHD4t4wxjpRN/VDv1qmNrBXFIercml+EH9g8HXjzSf8MrK5UUVVmFGmo3 wBrrrvIu5Ghr3C9c8hFBvQNT1nnp0kijOEnOmPSRIS7WC0Dui1AYYHVPu3ftQkBRuyxb d1Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=KLJ9Y5HApfFQWyxEM58HvTonMn7RopRqpHF4Hvloayg=; fh=2PXnc4NVAehgI0+2oKXDLX2sMz1iwDJvcYRuO/Ahn0k=; b=CsBpLCp4b2YBUnPcv29Z07mZKysAvsPLjsunMpKnc+YVMGYFgyNSMD8u9jVXWWuqpb AoV/FA0iHgVBfqtl/LF5cSFflXxDcla89WQBbHDYC9yYhubsOsD7BWxLhulgOy/VsER5 MGyU0vTNbcO2tNfe7R9Mh3uTxOXXKNr+r/uDN9FmHoeV1fCYp7G36wc2g1XTMHWwr5oJ rWjzeCRqU1g+2S7jBfBRnQgm1DnbUuhb4i5XqY74REz8NEezb9prA8uBpiYcXbXoRmY9 A01v0VHCiAfkuSEHXgNZ6RFdsFPCcrK+Bj2+orwFG4wPd7PWHWqKwGFBAUogpr0q4v6N Wl6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lGCJ7kdd; spf=pass (google.com: domain of linux-kernel+bounces-14559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id pg4-20020a17090b1e0400b0028672033a5csi20220652pjb.124.2024.01.02.07.29.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 07:29:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lGCJ7kdd; spf=pass (google.com: domain of linux-kernel+bounces-14559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9065CB22146 for ; Tue, 2 Jan 2024 15:29:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1537014A9C; Tue, 2 Jan 2024 15:29:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lGCJ7kdd" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45A8E1428F; Tue, 2 Jan 2024 15:29:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEC1BC433C8; Tue, 2 Jan 2024 15:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704209367; bh=d+GvaZhekVGQ9lMSiy4Nb4qHQGNOIjyRoiXkoMRn9yI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lGCJ7kddtHhcx8SjMavy1CSlW4RvUgR5Ap5KRjY/3PrAQ07ZQeaObkWbyw/PIbu3Z 86TH9bs/Vv43igh0SM2B0C8ApvsIMj/C7b5/IVBu4l0oAAB2g1osNbj3OeMx/ttu4z vvnKpUDYB5i9jsKiPkIPZiBKs/E+7YYBC6heHmbY18zQqVex6Hmf0Kl9+7PK8QiT6f eRrXEkV8AyWglf7vdOCK9xeV8dQncGcBoVs5g9/mO5RLGOv8rFPkutsLQ+pQMzNCRr bl8++chHRO+TP4Rupo5jS0wTOCWrRa+2KPuCr9FlZZh2ydANnZbItI8o5sdt3UtfBQ +tV6+06Ma097Q== Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2ccb923c4d2so67810491fa.1; Tue, 02 Jan 2024 07:29:27 -0800 (PST) X-Gm-Message-State: AOJu0Yzbnwo15zMMvb8YN9RZ6QQkbEGtEW1YnZUJCpvt19N9paA9UYe6 IPNYmZLhr2FnDK4ps311vOSVbh2Nwz4uPKNZIrc= X-Received: by 2002:a05:6512:b23:b0:50e:8ccc:6dec with SMTP id w35-20020a0565120b2300b0050e8ccc6decmr2574561lfu.126.1704209366003; Tue, 02 Jan 2024 07:29:26 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231226140250.224516-1-ytcoode@gmail.com> In-Reply-To: <20231226140250.224516-1-ytcoode@gmail.com> From: Ard Biesheuvel Date: Tue, 2 Jan 2024 16:29:14 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/efistub: fix the missing KASLR_FLAG bit in boot_params->hdr.loadflags To: Yuntao Wang Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Borislav Petkov (AMD)" , "Kirill A. Shutemov" , Tom Lendacky , Ingo Molnar , Dionna Glaze , Nikolay Borisov Content-Type: text/plain; charset="UTF-8" On Tue, 26 Dec 2023 at 15:03, Yuntao Wang wrote: > > When KASLR is enabled, the KASLR_FLAG bit in boot_params->hdr.loadflags > should be set to 1 to propagate KASLR status from compressed kernel to > kernel, just as the choose_random_location() function does. > > Currently, when kernel is booted via efi stub, the KASLR_FLAG bit in > boot_params->hdr.loadflags is not set, even though it should be. This > causes some functions, such as kernel_randomize_memory(), not to execute > as expected. Fix it. > > Signed-off-by: Yuntao Wang > --- > drivers/firmware/efi/libstub/x86-stub.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c > index da9b7b8d0716..b0c68593ad40 100644 > --- a/drivers/firmware/efi/libstub/x86-stub.c > +++ b/drivers/firmware/efi/libstub/x86-stub.c > @@ -787,7 +787,10 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) > efi_debug("AMI firmware v2.0 or older detected - disabling physical KASLR\n"); > seed[0] = 0; > } > - } > + > + boot_params_ptr->hdr.loadflags |= KASLR_FLAG; > + } else > + boot_params_ptr->hdr.loadflags &= ~KASLR_FLAG; > Thanks for the fix. I'll queue this up right away, but I am going to drop the 'else' part, given that the KASLR flag is never set by the EFI stub so clearing it should never be needed. > status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr, > seed[0], EFI_LOADER_CODE, > -- > 2.43.0 >