From patchwork Thu Feb 2 12:50:22 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: 9551749 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 147F960236 for ; Thu, 2 Feb 2017 12:50:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2AB528329 for ; Thu, 2 Feb 2017 12:50:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E756928427; Thu, 2 Feb 2017 12:50:54 +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 A6F6A28329 for ; Thu, 2 Feb 2017 12:50:53 +0000 (UTC) Received: (qmail 13391 invoked by uid 550); 2 Feb 2017 12:50:51 -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 13368 invoked from network); 2 Feb 2017 12:50:51 -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=4EYdjadPv/e2hpLKMICllSZn6H84rRrrOV/Iysr1Th0=; b=GRZACpnkOo0I/4TfQgyhJWk+hmkLM3NDyGScn5YLOpIVRQ6e22Lki6ZiEjr+B5s4C5 a6OgtfktUcRjlYe8gGzzKtFLOH0IroHanVkAgKkq9kFqAThlNnIOOm13S3B5q/wTo5Pq OlnpzJU4xOuVP88tdc57SgUXJg8KM5AGnA2XR3APMG6UVeB8FyPYE7SKA3koYNdk5HTT gFCgj9u2ZkAwDtKg2I60lWDTyM8hzfhZB6Zna3TRy9k++fknD7lZbTeNYFzr/8S0CJ6O LuFiPUVZy1hQS0v2fUjZEN0QY0p4Ptlq4/9JnngHpMZKD1J7V4oNNupveoBE7P40g+SV f4yA== 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=4EYdjadPv/e2hpLKMICllSZn6H84rRrrOV/Iysr1Th0=; b=JVM+mNWJFYdQx3VYiUf+ZxeC46IRVAL8jrIP3/18u6QnBW82ibn9Sb303DnBGh7feO g74HqwGt0fsya4q+h4d2rMaCta4ScKRXo8K/WiFFbI4hINpT/Tsj8ELsTtQVJBvrI1Cr pikf6LPNlqAY1wo0RPTykLls0pDqTcJS4QLsvGcoGDcnAJ7kR4+IbuECT1xjGtOrHlTH s0XzhnAlHCyCYLS9rA5YBC6zUNnF6uctirfqi45cqgd1OrdahcsJmQmrCXZLBudD6+LA rnPQiAV0mGLsUxBxnTZ0Yo4JmZ7AxJv9j6824FFcUm313zuWXSmqKrzjQEg6HjvZFkKS wwYg== X-Gm-Message-State: AIkVDXJBC1hBBJmHgRVulEAPsTRZGP7bqb2ZX9Dny+i0Jfx3URED32RV6ODRXsdwXxvIKg== X-Received: by 10.223.134.15 with SMTP id 15mr8690451wrv.102.1486039839633; Thu, 02 Feb 2017 04:50:39 -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: Thu, 2 Feb 2017 16:50:22 +0400 Message-Id: <1486039824-8470-1-git-send-email-kpark3469@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [PATCH v2 1/3] usercopy: create usercopy.h and move enum stack_type X-Virus-Scanned: ClamAV using ClamSMTP From: Sahara This patch creates linux/usercopy.h and moves the enum which is only used in usercopy.c so as to make it usable to x86 and other architecture's thread_info.h, which may have arch_within_stack_frames(). Signed-off-by: Sahara Suggested-by: James Morse --- arch/x86/include/asm/thread_info.h | 20 +++++++++++--------- include/linux/usercopy.h | 11 +++++++++++ mm/usercopy.c | 8 +------- 3 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 include/linux/usercopy.h diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index ad6f5eb0..c991126 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -51,6 +51,7 @@ struct task_struct; #include #include +#include struct thread_info { unsigned long flags; /* low level flags */ @@ -168,13 +169,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 +198,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/usercopy.h b/include/linux/usercopy.h new file mode 100644 index 0000000..974859e --- /dev/null +++ b/include/linux/usercopy.h @@ -0,0 +1,11 @@ +#ifndef __LINUX_USERCOPY_H +#define __LINUX_USERCOPY_H + +enum stack_type { + BAD_STACK = -1, + NOT_STACK = 0, + GOOD_FRAME, + GOOD_STACK, +}; + +#endif diff --git a/mm/usercopy.c b/mm/usercopy.c index 3c8da0a..ee7bced 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).