From patchwork Thu Feb 16 18:29:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 9578049 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 0F50160244 for ; Thu, 16 Feb 2017 18:30:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 012BF284D1 for ; Thu, 16 Feb 2017 18:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA1322863C; Thu, 16 Feb 2017 18:30:49 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 682E4284D1 for ; Thu, 16 Feb 2017 18:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=F+22hdZVDR8yFygsjODQe7vQVpPLNcFgXJofKEYPFOo=; b=I1N892R0JF9VCQP5/yxjs4OFRx asXfcrxKox/OZf7BW85aWfTZc1/S9N3J++5matAVAgxZScrnK/oiv5pgSvhf1JGoQ/dKiKkXTH3yR xgfYXP4gbaeeG3mHWWjdicbTN4rbyM0BHe5R9w6JLbTCFhYwVV7vzDWBNrjMbHTMnbNYqQZnJySZW dKV7eXYIUrjrLerkhfa0xMtCSrvjDfCV5V/rZIOOYsbZjm7W0YqnORdyCYK+S3qYBaRiIGVsQi1tL ePl7Zk3zSvWLiSSeQTyTcfjirwUpTVnJPdY6s51Y53Oz93R1PDcABZldRmhRlJYlqlzvgm7Neby8d bFNCsG8Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceQpD-0000uL-8P; Thu, 16 Feb 2017 18:30:39 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceQoa-0007cp-MP for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2017 18:30:14 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C251E54C; Thu, 16 Feb 2017 10:29:40 -0800 (PST) Received: from melchizedek.cambridge.arm.com (melchizedek.cambridge.arm.com [10.1.207.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7A69D3F23B; Thu, 16 Feb 2017 10:29:39 -0800 (PST) From: James Morse To: kernel-hardening@lists.openwall.com Subject: [PATCH v4 1/3] usercopy: create enum stack_type Date: Thu, 16 Feb 2017 18:29:15 +0000 Message-Id: <20170216182917.19637-2-james.morse@arm.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170216182917.19637-1-james.morse@arm.com> References: <20170216182917.19637-1-james.morse@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170216_103001_013884_51948721 X-CRM114-Status: GOOD ( 11.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , panand@redhat.com, keescook@chromium.org, Catalin Marinas , Will Deacon , keun-o.park@darkmatter.ae, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sahara This patch creates enum stack_type which is only used in usercopy.c for now. This enum type can be used for x86 and other architecture's thread_info.h, which may have arch_within_stack_frames(). Signed-off-by: Sahara Signed-off-by: James Morse Reviewed-by: Kees Cook Acked-by: Kees Cook --- arch/x86/include/asm/thread_info.h | 19 ++++++++++--------- include/linux/thread_info.h | 13 ++++++++++--- mm/usercopy.c | 8 +------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index ad6f5eb07a95..7af4b8b23b8b 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -168,13 +168,13 @@ static inline unsigned long current_stack_pointer(void) * 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) + * GOOD_FRAME if within a frame + * BAD_STACK if placed across a frame boundary (or outside stack) + * NOT_STACK 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) +static inline enum stack_type 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 *frame = NULL; @@ -197,13 +197,14 @@ static inline int arch_within_stack_frames(const void * const stack, * the copy as invalid. */ if (obj + len <= frame) - return obj >= oldframe + 2 * sizeof(void *) ? 1 : -1; + return obj >= oldframe + 2 * sizeof(void *) ? + GOOD_FRAME : BAD_STACK; oldframe = frame; frame = *(const void * const *)frame; } - return -1; + return BAD_STACK; #else - return 0; + return NOT_STACK; #endif } diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 58373875e8ee..a38b3be347df 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -22,6 +22,13 @@ #endif #include + +enum stack_type { + BAD_STACK = -1, + NOT_STACK = 0, + GOOD_FRAME, + GOOD_STACK, +}; #include #ifdef __KERNEL__ @@ -77,9 +84,9 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED) #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES -static inline int arch_within_stack_frames(const void * const stack, - const void * const stackend, - const void *obj, unsigned long len) +static inline enum stack_type arch_within_stack_frames(const void * const stack, + const void * const stackend, + const void *obj, unsigned long len) { return 0; } diff --git a/mm/usercopy.c b/mm/usercopy.c index 3c8da0af9695..3531ae735d87 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -16,15 +16,9 @@ #include #include +#include #include -enum { - BAD_STACK = -1, - NOT_STACK = 0, - GOOD_FRAME, - GOOD_STACK, -}; - /* * Checks if a given pointer and length is contained by the current * stack frame (if possible).