From patchwork Mon Aug 4 15:45:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Martin X-Patchwork-Id: 34879 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1471B21F5F for ; Mon, 4 Aug 2014 15:45:47 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id et14sf51519501pad.10 for ; Mon, 04 Aug 2014 08:45:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=bPQQKlGSRtte4pT9PcdS8X4Em4MmWy49W2kG5D7rlUY=; b=mtueuzp+I5W823YQYnIauXjpnyO62kbSFbjzBC3jmCt8a0XvBRJYhJHlZEVSla3YS+ u6tByxD1FrKp0dDJPubMCmHmddvwP0dpmeihhGYm62w26YeicknaPRG+6ifWU9NIu070 GMwDs2duS0j7wrL/exnbawCIlfUFyKkwqExRndZIHsa7PQkCmZ24y6/DT3rEnaX2Rll0 w9yEMVl72MNous+jqWscPcWBrkZm9Jy+AOs4YG3N45bMinUCq2O6DVHkQsemZof+QGPZ CxnFhLqXveg82Nhr5UmUfet1P/E/vvmuUcG/UTEDwnKZKZWS7qZC5wG9L2nyGlKJk0Uh djiw== X-Gm-Message-State: ALoCoQnUyO/ei9pyRTmkafVZC2CfQ8to82Lm/ohTovUGrAan1GIT4kH843KeLSVnzv8RMOuO8AVx X-Received: by 10.66.246.229 with SMTP id xz5mr9092110pac.34.1407167146392; Mon, 04 Aug 2014 08:45:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.20.132 with SMTP id 4ls2158199qgj.12.gmail; Mon, 04 Aug 2014 08:45:46 -0700 (PDT) X-Received: by 10.221.25.210 with SMTP id rj18mr24384118vcb.5.1407167146275; Mon, 04 Aug 2014 08:45:46 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id br4si12222708vcb.106.2014.08.04.08.45.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 08:45:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so11240637vcb.26 for ; Mon, 04 Aug 2014 08:45:43 -0700 (PDT) X-Received: by 10.220.97.5 with SMTP id j5mr24611657vcn.16.1407167142842; Mon, 04 Aug 2014 08:45:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp314508vcb; Mon, 4 Aug 2014 08:45:42 -0700 (PDT) X-Received: by 10.50.33.16 with SMTP id n16mr37794470igi.15.1407167141965; Mon, 04 Aug 2014 08:45:41 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id xp18si41188518icb.64.2014.08.04.08.45.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 04 Aug 2014 08:45:41 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XEKS7-00076U-08; Mon, 04 Aug 2014 15:45:35 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XEKS5-00076L-BS for edk2-devel@lists.sourceforge.net; Mon, 04 Aug 2014 15:45:33 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of arm.com designates 217.140.96.21 as permitted sender) client-ip=217.140.96.21; envelope-from=olivier.martin@arm.com; helo=cam-smtp0.cambridge.arm.com; Received: from fw-tnat.cambridge.arm.com ([217.140.96.21] helo=cam-smtp0.cambridge.arm.com) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1XEKRz-0000Y9-Tv for edk2-devel@lists.sourceforge.net; Mon, 04 Aug 2014 15:45:33 +0000 Received: from e102605-lin.cambridge.arm.com (e102605-lin.cambridge.arm.com [10.1.193.159]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s74FjDcX028066; Mon, 4 Aug 2014 16:45:13 +0100 From: Olivier Martin To: michael.d.kinney@intel.com Date: Mon, 4 Aug 2014 16:45:09 +0100 Message-Id: <1407167111-21429-1-git-send-email-olivier.martin@arm.com> X-Mailer: git-send-email 1.8.5 X-Spam-Score: -2.2 (--) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1XEKRz-0000Y9-Tv Cc: edk2-devel@lists.sourceforge.net Subject: [edk2] [PATCH v2 1/3] MdePkg: Introduced BaseStackCheckLib X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: olivier.martin@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This library only support GCC, RVCT and XCode for now. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Andrew Fish Signed-off-by: Olivier Martin --- .../Library/BaseStackCheckLib/BaseStackCheckGcc.c | 62 ++++++++++++++++++++++ .../BaseStackCheckLib/BaseStackCheckLib.inf | 42 +++++++++++++++ MdePkg/MdePkg.dsc | 5 +- 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c create mode 100644 MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf diff --git a/MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c new file mode 100644 index 0000000..130f96e --- /dev/null +++ b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c @@ -0,0 +1,62 @@ +/** @file + Base Stack Check library for GCC/clang. + + Use -fstack-protector-all compiler flag to make the compiler insert the + __stack_chk_guard "canary" value into the stack and check the value prior + to exiting the function. If the "canary" is overwritten __stack_chk_fail() + is called. This is GCC specific code. + + Copyright (c) 2012, Apple Inc. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include + +VOID +__stack_chk_fail ( + VOID + ); + + +/// "canary" value that is inserted by the compiler into the stack frame. +VOID *__stack_chk_guard = (VOID*)0x0AFF; + +// If ASLR was enabled we could use +//void (*__stack_chk_guard)(void) = __stack_chk_fail; + +/** + Error path for compiler generated stack "canary" value check code. If the + stack canary has been overwritten this function gets called on exit of the + function. +**/ +VOID +__stack_chk_fail ( + VOID + ) +{ + UINT8 DebugPropertyMask; + + DEBUG ((DEBUG_ERROR, "STACK FAULT: Buffer Overflow in function %a.\n", __builtin_return_address(0))); + + // + // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if + // BaseDebugLibNull is in use. + // + DebugPropertyMask = PcdGet8 (PcdDebugPropertyMask); + if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) { + CpuBreakpoint (); + } else if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) { + CpuDeadLoop (); + } +} + diff --git a/MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf new file mode 100644 index 0000000..4c17306 --- /dev/null +++ b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf @@ -0,0 +1,42 @@ +## @file +# Stack Check Library +# +# Copyright (c) 2014, ARM Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php. +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseStackCheckLib + FILE_GUID = 5f6579f7-b648-4fdb-9f19-4c17e27e8eff + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL + + +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + BaseStackCheckGcc.c | GCC + BaseStackCheckGcc.c | RVCT + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask + diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 0924835..7b12873 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -165,6 +165,9 @@ MdePkg/Library/DxeRuntimeExtendedSalLib/DxeRuntimeExtendedSalLib.inf MdePkg/Library/DxeSalLibEsal/DxeSalLibEsal.inf MdePkg/Library/DxeTimerLibEsal/DxeTimerLibEsal.inf - + [Components.EBC] MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf + +[Components.ARM, Components.AARCH64] + MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf