From patchwork Thu Dec 15 12:38:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 33640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp329852wrn; Thu, 15 Dec 2022 04:47:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7oyCGv4w67t4B0boL7WxVQ784o/km3pnwY92/M1dqayB1IeleUj0hyJvIDw05sqyNgVJf5 X-Received: by 2002:a17:906:2289:b0:7c1:639:6b46 with SMTP id p9-20020a170906228900b007c106396b46mr22160285eja.9.1671108461642; Thu, 15 Dec 2022 04:47:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671108461; cv=none; d=google.com; s=arc-20160816; b=v2O8TjM7zQlhyMcB+dz/KZvgzF5MwadSbV6gpwEuKW9YftgslmHQIopgDnpFD+v0l7 HG/n598LxOw80Zj2OGYzNpXt9wrvXNVN9JK/FF8+XVS3za9gtXHWd62uvdnjPkcAFgbf 9FQe8djW7UVYHBibYp97fuOe7RjBZytPL2YvVn9Kg8RjK9BN8NzvagkapKkKbf7XS0QO ueI34ZYl8djKLRqy/ntnsAlttu0lQwKhIO2770AMvSyv9rFga04QYJjJgPKpJTsyyvYf sz0uhCzJqYpZ+Q3H6o6gUFDIi+9x4PgN476y2cd4++zeUGap8sMymq2+EHtZNl3VmAXE au7Q== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn33-20020a1709070d2100b007c0b61436efsi15475288ejc.1008.2022.12.15.04.47.17; Thu, 15 Dec 2022 04:47:41 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752284226728305252?= X-GMAIL-MSGID: =?utf-8?q?1752284226728305252?= 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;