Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp956048rwb; Thu, 15 Dec 2022 04:51:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Ri0K40iP5OA4FG8+cj4XBLr1F0AJUv1hx5cegWMgC7jJ3uhoNjnzg9usP1rAjkU16thKG X-Received: by 2002:a17:906:c018:b0:78d:f454:ba19 with SMTP id e24-20020a170906c01800b0078df454ba19mr25460881ejz.24.1671108683586; Thu, 15 Dec 2022 04:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671108683; cv=none; d=google.com; s=arc-20160816; b=RVIeRe04XKRleYOzjYjzWI9bC8x3/znEOMxn89js2vabwGFeLwRRTPc1fQRQeQbDnI DXm0dDIq3Ga/0uDd9V1gz2cJH81/XP7+M14x543uIAhtbRvgesbIVmyxdELkCPe0OsMg Wk9j2nJuWDmIVXVwhlIelv47Fcv57ISZqT91ah6XYpBG0tG9U7bNkGfTILxgfNN8zn74 llaYXC3xGrJx5wAmYBmQKEdHRobQMSHYWxpdNZNO6jlGGVV5rJT5Ptgn/DyLO9xExoQS PlhbnSBy6bW3uUBUpW+5mRnMIFz1CxkVUPZfPMxs+Xr8azs6QNFF5U2W1JpDzZ/BxCwX 1nWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=jwVZfRAAiFqcCVLSCdZEn7wStGxjBCy240Fe15tVLDM=; b=eVHO6K4EEdFTwDFVT8rBMdBbkuqqfV2Con/Bla2FkbwOnJ0NgxK4c69jvMfwV+fPXy Ak8QUal8gTecuI3V40EPyEY+L6SCki882hxHvCFBsHLSBeWVvfSYnPS4NJtNZ0UPii5q 5UengJsuCrV0kSVLsGbFNb61LSnyG+rIpbTc0yhxlH7M21FtQp4mC6mxVfWajfpliAWZ e+SpT0eOjqBjXPNIf+ftjZqxWArSnWhfFSuuJIdyuG2Jy872KpnmQiPFR39z9yuiCGZX emPbCWQQR9crgDA0Y2pgWVEph8Y5Cv2a32iVmz5RawlAgr8S2EnyLhNnjFePZAAnxEoR +pSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=AhwQace4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a05640240d200b00461c314f79fsi17636051edb.284.2022.12.15.04.51.06; Thu, 15 Dec 2022 04:51:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=AhwQace4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbiLOMne (ORCPT + 68 others); Thu, 15 Dec 2022 07:43:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiLOMnC (ORCPT ); Thu, 15 Dec 2022 07:43:02 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A36A6273; Thu, 15 Dec 2022 04:42:30 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 41F2340737B0; Thu, 15 Dec 2022 12:42:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 41F2340737B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671108147; bh=jwVZfRAAiFqcCVLSCdZEn7wStGxjBCy240Fe15tVLDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AhwQace4BSscXLSgOx45uS18mgI/sJ/7ATrZ1HBbOWSm47BpNor8Dgw4rpM6rLl/O h3XVVePg7nHJgcvqEbo1++n0PQto1GFsR0RcbgU8EcubXWeZ1NGxJjDhTrgiaE9Vho KjEzhGPGYIS5CwvD+Sshg2tO4IvfgIIbv1Ka7gn8= From: Evgeniy Baskov To: Ard Biesheuvel Cc: Peter Jones , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , "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: [PATCH v4 26/26] efi/x86: don't set unsupported memory attributes Date: Thu, 15 Dec 2022 15:38:17 +0300 Message-Id: X-Mailer: git-send-email 2.37.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Jones On platforms where the firmware uses DXE, but which do not implement the EFI Memory Attribute Protocol, we implement W^X support using DXE's set_memory_attributes() call. This call will fail without making any changes if an attribute is set that isn't supported on the platform. This patch changes efi_adjust_memory_range_protection() to avoid trying to set any attribute bits that aren't set in the memory region's capability flags. Signed-off-by: Peter Jones --- drivers/firmware/efi/libstub/mem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c index 50a0b649b75a..b86ea2920d5e 100644 --- a/drivers/firmware/efi/libstub/mem.c +++ b/drivers/firmware/efi/libstub/mem.c @@ -195,6 +195,7 @@ static efi_status_t adjust_mem_attrib_dxe(efi_physical_addr_t rounded_start, desc.attributes &= ~(EFI_MEMORY_RO | EFI_MEMORY_XP); desc.attributes |= attributes; + desc.attributes &= desc.capabilities; unprotect_start = max(rounded_start, desc.base_address); unprotect_size = min(rounded_end, next) - unprotect_start; -- 2.37.4