From patchwork Wed Jan 25 13:46:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kpark3469@gmail.com X-Patchwork-Id: 9537071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2FA45601D3 for ; Wed, 25 Jan 2017 13:46:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2127D28285 for ; Wed, 25 Jan 2017 13:46:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 134302824F; Wed, 25 Jan 2017 13:46:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 01D392824F for ; Wed, 25 Jan 2017 13:46:48 +0000 (UTC) Received: (qmail 24394 invoked by uid 550); 25 Jan 2017 13:46:46 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 24376 invoked from network); 25 Jan 2017 13:46:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=GaalNX+ERcwWVWjt3gHYV02yhT6wL/I+jYWl9uDGJd8=; b=lNgjKNHnY3QeqVv4TdUnPrVxDiujvZQtjtE3XKK6PpTZhBephPD5YF8zKSr3IT6ddq 979QdiBhM285vd0VK7apvdMVDVuDxc6IRN96QhgxY6vGz+6Hv5uc3n6uxbhI3mRjB8Wd nr82PXGGfQxuuWHnWkYy5/Yo7T7a/qdExAi+UU6mT3XE9k6850y2BlZmg09jH352a5kz bFGgag68AEwSl/stSJbhAcQynb8gMXN+JltANj1MurhhYsHFOdFjjvCLcziG5qXec4lg ltCtg39JbEoj+VOGijVH95cT8GHKoDGpz82YQYJdBIe1r7mQYsVl7bxzfbmGuFJ8GbK2 ta0Q== 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; bh=GaalNX+ERcwWVWjt3gHYV02yhT6wL/I+jYWl9uDGJd8=; b=JbIiqTLxFQKJbUSCz/tc+hG3wE6Q5IaLGVJV46fz3UNQNRmOD29gY5JB7y4lV1DvVb RlsX6lvkhWltjFmCMDufYQknNI2uWAd9VUZLu1WMgwA74nlmPatDutMEGCZuJ76hGZi/ EOX3Zbh5bKu7ca2lMrIuArxDqdYUg0vTfQ6uiPIL1vm/4KiRu8elod+c7ThbT6R6ELFl iVLk4V/JS3mT2uqcjTcIAzAYWQO3laTMzHGvaOdkHw2v16FikcD7CgfDM9vGgm+NyBcw zaR6MBWifjTXeJzmabMABrO9S74MdFdnBBFiZSxdYzxLk5iTBlHgaOFSQwymPJ+cA2dz RyWQ== X-Gm-Message-State: AIkVDXIapDdHHPy2PZgIxzRJDw+RspygTElkKIm3m+bMUhQIS7J5gu2U8fZlExxFkYPAwA== X-Received: by 10.223.162.211 with SMTP id t19mr33298947wra.57.1485351994836; Wed, 25 Jan 2017 05:46:34 -0800 (PST) From: kpark3469@gmail.com To: kernel-hardening@lists.openwall.com Cc: catalin.marinas@arm.com, keescook@chromium.org, will.deacon@arm.com, mark.rutland@arm.com, james.morse@arm.com, panand@redhat.com, keun-o.park@darkmatter.ae Date: Wed, 25 Jan 2017 17:46:23 +0400 Message-Id: <1485351983-13873-1-git-send-email-kpark3469@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [PATCH] arm64: usercopy: Implement stack frame object validation X-Virus-Scanned: ClamAV using ClamSMTP From: Sahara This implements arch_within_stack_frames() for arm64 that should validate if a given object is contained by a kernel stack frame. Signed-off-by: Sahara --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/thread_info.h | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1117421..8bf70b4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -97,6 +97,7 @@ config ARM64 select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES select HAVE_KRETPROBES if HAVE_KPROBES + select HAVE_ARCH_WITHIN_STACK_FRAMES select IOMMU_DMA if IOMMU_SUPPORT select IRQ_DOMAIN select IRQ_FORCED_THREADING diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 46c3b93..f610c44 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -68,7 +68,62 @@ struct thread_info { #define thread_saved_fp(tsk) \ ((unsigned long)(tsk->thread.cpu_context.fp)) +/* + * Walks up the stack frames to make sure that the specified object is + * entirely contained by a single stack frame. + * + * Returns: + * 1 if within a frame + * -1 if placed across a frame boundary (or outside stack) + * 0 unable to determine (no frame pointers, etc) + */ +static inline int arch_within_stack_frames(const void * const stack, + const void * const stackend, + const void *obj, unsigned long len) +{ +#if defined(CONFIG_FRAME_POINTER) + const void *oldframe; + const void *callee_fp = NULL; + const void *caller_fp = NULL; + + oldframe = __builtin_frame_address(1); + if (oldframe) { + callee_fp = __builtin_frame_address(2); + if (callee_fp) + caller_fp = __builtin_frame_address(3); + } + /* + * low ----------------------------------------------> high + * [callee_fp][lr][args][local vars][caller_fp'][lr'] + * ^----------------^ + * allow copies only within here + */ + while (stack <= callee_fp && callee_fp < stackend) { + /* + * If obj + len extends past the caller frame, this + * check won't pass and the next frame will be 0, + * causing us to bail out and correctly report + * the copy as invalid. + */ + if (!caller_fp) { + if (obj + len <= stackend) + return (obj >= callee_fp + 2 * sizeof(void *)) ? + 1 : -1; + else + return -1; + } + if (obj + len <= caller_fp) + return (obj >= callee_fp + 2 * sizeof(void *)) ? 1 : -1; + callee_fp = caller_fp; + caller_fp = *(const void * const *)caller_fp; + } + return -1; +#else + return 0; #endif +} + +#endif /* !__ASSEMBLY__ */ /* * thread information flags: