From patchwork Wed Feb 22 18:24:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 94361 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1041836qgi; Wed, 22 Feb 2017 10:25:16 -0800 (PST) X-Received: by 10.84.224.11 with SMTP id r11mr50211617plj.130.1487787916887; Wed, 22 Feb 2017 10:25:16 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id i135si1897591pgd.33.2017.02.22.10.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Feb 2017 10:25:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 73FD882245; Wed, 22 Feb 2017 10:25:16 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com [IPv6:2a00:1450:400c:c09::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B705582245 for ; Wed, 22 Feb 2017 10:25:14 -0800 (PST) Received: by mail-wm0-x231.google.com with SMTP id v186so148569892wmd.0 for ; Wed, 22 Feb 2017 10:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jl3Cv2W9dBV/wPbqxZBS//P62jVQme8foGbc/HQDDck=; b=dr6eG8ae5wfAP7t1XpPnzuOx1FszajxZa77P67DSqRlepZZqPyTKBaH7DoDgc8Blt2 jTmhBVLx117616HZazrc7URRY59lIBV4DiEMd3kcGurDYTjGIdHR8bygSN4/nB+3oAgu 6NPE/6i0LwrZPS1/sVlyzEArgD86n0PRE1IZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jl3Cv2W9dBV/wPbqxZBS//P62jVQme8foGbc/HQDDck=; b=aGb6sTfwPtN1A1AVMGZee/+dlzhSuGZ8ipAgPya/CCDIHLC/WvV6cOmUTAG6g8D0Ct XC3QTw+pKYMljXay1JdQ4NnkPZP3CyLj6SwKBBhpVuG0b33dPfo914dgLVm6bAVa64hU qsOrPpeaj1oeYyBMmk+Xd9dtrUfqz9ybNFz0dKV0OQq7M/g7rrnTlKfHF9ZDNkx2I4Xi H28Mp6T2A/6AJXqk6OnRux9qQMxu4NvnZ1pDR9wAflG7ouw6eRW0x15KhiCFmrsORwW3 cnoaD2H1aTttUiNSe1R39/f/MnWPwl9Vg6eWWr/AyBd7qmHv13Nu0OoYdiyJhCHmJ568 iU8Q== X-Gm-Message-State: AMke39lqWPSXzI8YWHEF2gj7O1fycpkeM1hTerENeFQFF53DM1bJGGc9ZP7jEpwNkx1UuKHp X-Received: by 10.28.226.67 with SMTP id z64mr3446117wmg.137.1487787913176; Wed, 22 Feb 2017 10:25:13 -0800 (PST) Received: from localhost.localdomain ([196.80.204.181]) by smtp.gmail.com with ESMTPSA id e73sm3504667wmi.32.2017.02.22.10.25.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Feb 2017 10:25:12 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, afish@apple.com, leif.lindholm@linaro.org, michael.d.kinney@intel.com, liming.gao@intel.com, jiewen.yao@intel.com Date: Wed, 22 Feb 2017 18:24:57 +0000 Message-Id: <1487787898-5222-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487787898-5222-1-git-send-email-ard.biesheuvel@linaro.org> References: <1487787898-5222-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [RFC PATCH 3/4] MdeModulePkg/DxeCore: lift non-exec permissions on loaded images X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: feng.tian@intel.com, lersek@redhat.com, star.zeng@intel.com, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" To ensure that loaded PE/COFF images are executable regardless of the protection policy and the section alignment, clear all permission restrictions when loading PE/COFF images. Subsequently, permissions may be restricted again if the protection policy and section alignment allow it. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Image/Image.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 652da8bf1075..cab06e821e39 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -644,6 +644,14 @@ CoreLoadPeImage ( InvalidateInstructionCacheRange ((VOID *)(UINTN)Image->ImageContext.ImageAddress, (UINTN)Image->ImageContext.ImageSize); // + // Remove any permission restrictions. + // + if (gCpu != NULL) { + gCpu->SetMemoryAttributes (gCpu, Image->ImageContext.ImageAddress, + Image->ImageContext.ImageSize, 0); + } + + // // Copy the machine type from the context to the image private data. This // is needed during image unload to know if we should call an EBC protocol // to unload the image.