From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f71.google.com (mail-wm0-f71.google.com [74.125.82.71]) by kanga.kvack.org (Postfix) with ESMTP id 5ADBA6B025E for ; Thu, 7 Jul 2016 13:29:41 -0400 (EDT) Received: by mail-wm0-f71.google.com with SMTP id f126so22952939wma.3 for ; Thu, 07 Jul 2016 10:29:41 -0700 (PDT) Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com. [2a00:1450:400c:c09::229]) by mx.google.com with ESMTPS id q190si4111211wmg.17.2016.07.07.10.29.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jul 2016 10:29:40 -0700 (PDT) Received: by mail-wm0-x229.google.com with SMTP id f126so219256392wma.1 for ; Thu, 07 Jul 2016 10:29:40 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <1467843928-29351-1-git-send-email-keescook@chromium.org> <1467843928-29351-2-git-send-email-keescook@chromium.org> From: Kees Cook Date: Thu, 7 Jul 2016 13:29:38 -0400 Message-ID: Subject: Re: [PATCH 1/9] mm: Hardened usercopy Content-Type: text/plain; charset=UTF-8 Sender: owner-linux-mm@kvack.org List-ID: To: Thomas Gleixner Cc: LKML , Rik van Riel , Casey Schaufler , PaX Team , Brad Spengler , Russell King , Catalin Marinas , Will Deacon , Ard Biesheuvel , Benjamin Herrenschmidt , Michael Ellerman , Tony Luck , Fenghua Yu , "David S. Miller" , "x86@kernel.org" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Andy Lutomirski , Borislav Petkov , Mathias Krause , Jan Kara , Vitaly Wool , Andrea Arcangeli , Dmitry Vyukov , Laura Abbott , "linux-arm-kernel@lists.infradead.org" , linux-ia64@vger.kernel.org, "linuxppc-dev@lists.ozlabs.org" , sparclinux , linux-arch , Linux-MM , "kernel-hardening@lists.openwall.com" On Thu, Jul 7, 2016 at 3:42 AM, Thomas Gleixner wrote: > On Wed, 6 Jul 2016, Kees Cook wrote: >> + >> +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86) >> + const void *frame = NULL; >> + const void *oldframe; >> +#endif > > That's ugly Yeah, I'd like to have this be controlled by a specific CONFIG, like I invented for the linear mapping, but I wasn't sure what was the best approach. > >> + >> + /* Object is not on the stack at all. */ >> + if (obj + len <= stack || stackend <= obj) >> + return 0; >> + >> + /* >> + * Reject: object partially overlaps the stack (passing the >> + * the check above means at least one end is within the stack, >> + * so if this check fails, the other end is outside the stack). >> + */ >> + if (obj < stack || stackend < obj + len) >> + return -1; >> + >> +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86) >> + oldframe = __builtin_frame_address(1); >> + if (oldframe) >> + frame = __builtin_frame_address(2); >> + /* >> + * low ----------------------------------------------> high >> + * [saved bp][saved ip][args][local vars][saved bp][saved ip] >> + * ^----------------^ >> + * allow copies only within here >> + */ >> + while (stack <= frame && frame < stackend) { >> + /* >> + * If obj + len extends past the last 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 (obj + len <= frame) >> + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1; >> + oldframe = frame; >> + frame = *(const void * const *)frame; >> + } >> + return -1; >> +#else >> + return 1; >> +#endif > > I'd rather make that a weak function returning 1 which can be replaced by > x86 for CONFIG_FRAME_POINTER=y. That also allows other architectures to > implement their specific frame checks. Yeah, though I prefer CONFIG-controlled stuff over weak functions, but I agree, something like arch_check_stack_frame(...) or similar. I'll build something for this on the next revision. -Kees -- Kees Cook Chrome OS & Brillo Security -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org