From patchwork Mon Jul 7 15:43:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Martin X-Patchwork-Id: 33168 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DEF59235AB for ; Mon, 7 Jul 2014 15:45:00 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf27281978iec.0 for ; Mon, 07 Jul 2014 08:45:00 -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:in-reply-to :references: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=vKIZv7pM7pnN3/Fb3bVuxtKqDenmBGGQYG4Dt9Vtz2M=; b=eLImO5PIEIZYSl5icKR3qIoLjdf13D1btsaNWGy8ckDP7zAC59sadpeD1nu3/lSKUC L2Rm3CUSi5lST3aw+YB+hpk+v5sfgONwdzk9uRCkA2wwUZClWxOE5RPeS3WVHg0vY3FI o9yUUvKyys8ti0xa3FoTgeofYPOgjOKASgctWHgHmKJHI2wEVVJ2LvL4qKC44vb7+4Mp fk3+2aNmpABSJduA0hWuAifhNFuM655EYY12ZKUM8WxATziQcb99naH23tBxp0nvaaVn TX5tTthLr2ENFqlP4zZJ8ise0Je/iEYHkAdzv5/Rvn8/ZGdz+gwtRKOU/UeYaPmONxHH aAlA== X-Gm-Message-State: ALoCoQkliiOlAtLU/SvcErS2MOXDyIOHOT9lwijjMvN27+p1APC71d4zoLhcCmIJW7ZviVTk/+W/ X-Received: by 10.50.73.197 with SMTP id n5mr7074918igv.1.1404747900455; Mon, 07 Jul 2014 08:45:00 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.228 with SMTP id s91ls1848538qga.58.gmail; Mon, 07 Jul 2014 08:45:00 -0700 (PDT) X-Received: by 10.53.7.204 with SMTP id de12mr11215153vdd.41.1404747900348; Mon, 07 Jul 2014 08:45:00 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id uk3si18936660vec.102.2014.07.07.08.45.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jul 2014 08:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jz11so4281019veb.31 for ; Mon, 07 Jul 2014 08:45:00 -0700 (PDT) X-Received: by 10.220.166.9 with SMTP id k9mr28301094vcy.20.1404747900261; Mon, 07 Jul 2014 08:45:00 -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 tc5csp679232vcb; Mon, 7 Jul 2014 08:44:59 -0700 (PDT) X-Received: by 10.42.22.193 with SMTP id p1mr34254841icb.43.1404747899195; Mon, 07 Jul 2014 08:44:59 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id m12si61650748icb.53.2014.07.07.08.44.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Jul 2014 08:44:59 -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-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1X4B63-0004ke-64; Mon, 07 Jul 2014 15:44:51 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1X4B60-0004kS-Gv; Mon, 07 Jul 2014 15:44:48 +0000 Received-SPF: pass (sog-mx-2.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-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1X4B5z-00011l-8B; Mon, 07 Jul 2014 15:44:48 +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 s67Fi7s0012523; Mon, 7 Jul 2014 16:44:34 +0100 From: Olivier Martin To: michael.d.kinney@intel.com, edk2-buildtools-devel@lists.sourceforge.net Date: Mon, 7 Jul 2014 16:43:52 +0100 Message-Id: <1404747833-653-3-git-send-email-olivier.martin@arm.com> X-Mailer: git-send-email 1.8.5 In-Reply-To: <1404747833-653-1-git-send-email-olivier.martin@arm.com> References: <1404747833-653-1-git-send-email-olivier.martin@arm.com> 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: 1X4B5z-00011l-8B Cc: andrew.fish@apple.com, edk2-devel@lists.sourceforge.net Subject: [edk2] [PATCH 2/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.128.172 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 and XCode for now. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Andrew Fish Signed-off-by: Olivier Martin + 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..4e2285d --- /dev/null +++ b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf @@ -0,0 +1,41 @@ +## @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 = BaseStackCheckLib + + +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + BaseStackCheckGcc.c | GCC + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask +