From patchwork Sun Feb 5 12:14:08 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: 9556059 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 EE483602B1 for ; Sun, 5 Feb 2017 12:14:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD6EC269E2 for ; Sun, 5 Feb 2017 12:14:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEA2A27F85; Sun, 5 Feb 2017 12:14:41 +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 7AE4A269E2 for ; Sun, 5 Feb 2017 12:14:39 +0000 (UTC) Received: (qmail 30025 invoked by uid 550); 5 Feb 2017 12:14:37 -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 30004 invoked from network); 5 Feb 2017 12:14:37 -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=aGYDqTvCUvTDl9yJMowOIlbnH31q16o43UbDotwLRTY=; b=VTmwlV2t32Hky1qmpSExBqyWe3bCSsWyo0vIbHTv6re0mlBAgfHlI9y2EApQJ5gcl4 RDixO4+yuC4fSbdcYslEAMIR9/gGoqsEYC4RjF0u1SpOJPn7vUuIdl1qVNsp1UiQruXM Sqc2VJ2ToQqZMfZ3KUtakEApoSu2R3DexuneJGND1DqJCzHA/gyZMrIaWif3DKf6zU5Z e3aWU+jPJbk/xtF1kfALNBQXZkdxQA7yPdMZDIEOu5fVcnI+BwmYU6CNO6h/5TKl52Wh xWxZR/sdBF9R469RBJCTA1/xY8+AOa2zlYf/lqCQ7+a4D739vLf9FrymlOeYC9psnVX8 iwCQ== 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=aGYDqTvCUvTDl9yJMowOIlbnH31q16o43UbDotwLRTY=; b=GavX5ViZ41MxYffPOBgBvDvKuetqlSC137NdaCMSlRSDZqcnyjCtLkfQLS+ePW2RPa 2N5DiSLTfuB0f6Q6pvOF2yLeII8/6kZ5rAWKdllNXpOvpq14fXaMQrQ6uc9Y+Uvvn8GC cHvDadJrRPkPavJTtgEgrPZQPTA0bW/K5kDvUsiqBporTaVQjSk+4IHZt24o1KnblWqk 0wEN+/jcPYnxAqVnYePIJvaGkW7y9LSGn69263qIp+K5qk2t6MQKFTUqGDiMZpEqtsJ2 5qaCZou15fz2EDCwgqGv9WoWjXdxwN/mGSNLKv3h2epiW6QDJsgEl6yO8YBiuuN/I+zM VX/g== X-Gm-Message-State: AIkVDXLnGxBQcmf6RoLxUI0X9pwpzR4L7zgGABTQyWpOJ/hXPtCiHPmN8F5kPlP6oQvkDw== X-Received: by 10.25.234.216 with SMTP id y85mr1784881lfi.35.1486296865596; Sun, 05 Feb 2017 04:14:25 -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: Sun, 5 Feb 2017 16:14:08 +0400 Message-Id: <1486296850-16045-1-git-send-email-kpark3469@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [PATCH v3 1/3] usercopy: create enum stack_type 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 Suggested-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 ad6f5eb0..7af4b8b 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 5837387..a38b3be 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 3c8da0a..3531ae7 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).