From patchwork Thu Mar 23 20:34:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9641917 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 7E42C602D6 for ; Thu, 23 Mar 2017 20:34:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 712452840E for ; Thu, 23 Mar 2017 20:34:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6598F28474; Thu, 23 Mar 2017 20:34:38 +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_SIGNED, 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 963C12840E for ; Thu, 23 Mar 2017 20:34:37 +0000 (UTC) Received: (qmail 11614 invoked by uid 550); 23 Mar 2017 20:34:35 -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 11584 invoked from network); 23 Mar 2017 20:34:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=gEzy2u2F6PzLhRASnLDCLJg32r3/0kRaj3R1Dy3obVY=; b=DybRP5ZoJCgyI5C+4ZUpzXmYSz9RwyJjTIsL32i995Z5vVJkWtyMWZV3wXpxcp0xbG l+MiSF0FJa5VBjskBbRtXlEAHzXcQFBgGU/wYM2Lck2pt95GbhUlPcHO6qtLQ8BXgcvJ uyYKJkEziz24ju8Gtb3OxGNZzEcpql7wNxcOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=gEzy2u2F6PzLhRASnLDCLJg32r3/0kRaj3R1Dy3obVY=; b=FvPWELXIEWyXkPwDYx5rJEqBRJh9Tl0vxepxGCQtBDHdGzGoM6+5+8QPUHrdBxLluj 8DKbyFUERsxigjS4Wg1TIwvneP8Ra89PNxJziXrPv9FcGu2/S+rr855g7JKyc275Gsf8 nMOeeH6NPjbWvCiuYWgkbimLrmY2Zxd9MZVa71XJdyB3+LZ1E08nW7mzlnWDSc05UGAU YMl3o0UcKqjEvxjOvXE3tgGdOaK6AQ3bpgumAI3NVGtEYn3YTxZfJf6Gk05/J3HJ+rch 5q+yZ0YL8zNp5Navd4jhWWL4E5lBoWZHZwuw8q+BolVEYumEeliXhtaWHZWtDNDJWEFS PV/w== X-Gm-Message-State: AFeK/H0pGPAc6w8g7D3aCBK1CdPqgQRXBklRZv2f0geTyCYzZeEjdPPtwJjPoZIneQRQHFLg X-Received: by 10.84.229.73 with SMTP id d9mr6097192pln.177.1490301262344; Thu, 23 Mar 2017 13:34:22 -0700 (PDT) Date: Thu, 23 Mar 2017 13:34:19 -0700 From: Kees Cook To: Thomas Garnier Cc: Martin Schwidefsky , Heiko Carstens , David Howells , Arnd Bergmann , Dave Hansen , Al Viro , Thomas Gleixner , =?iso-8859-1?Q?Ren=E9?= Nyffenegger , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , Oleg Nesterov , Pavel Tikhomirov , Stephen Smalley , Ingo Molnar , "H . Peter Anvin" , Andy Lutomirski , Paolo Bonzini , Rik van Riel , Josh Poimboeuf , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , Christian Borntraeger , Russell King , Will Deacon , Catalin Marinas , Mark Rutland , James Morse , "linux-s390@vger.kernel.org" , LKML , Linux API , "x86@kernel.org" , "linux-arm-kernel@lists.infradead.org" , "kernel-hardening@lists.openwall.com" Message-ID: <20170323203419.GA62859@beast> MIME-Version: 1.0 Content-Disposition: inline Subject: [kernel-hardening] [PATCH] lkdtm: add bad USER_DS test X-Virus-Scanned: ClamAV using ClamSMTP This adds CORRUPT_USER_DS to check that the get_fs() test on syscall return still sees USER_DS during the new VERIFY_PRE_USERMODE_STATE checks. Signed-off-by: Kees Cook --- drivers/misc/lkdtm.h | 1 + drivers/misc/lkdtm_bugs.c | 20 ++++++++++++++++++++ drivers/misc/lkdtm_core.c | 1 + 3 files changed, 22 insertions(+) diff --git a/drivers/misc/lkdtm.h b/drivers/misc/lkdtm.h index 67d27be60405..3b4976396ec4 100644 --- a/drivers/misc/lkdtm.h +++ b/drivers/misc/lkdtm.h @@ -27,6 +27,7 @@ void lkdtm_REFCOUNT_ZERO_SUB(void); void lkdtm_REFCOUNT_ZERO_ADD(void); void lkdtm_CORRUPT_LIST_ADD(void); void lkdtm_CORRUPT_LIST_DEL(void); +void lkdtm_CORRUPT_USER_DS(void); /* lkdtm_heap.c */ void lkdtm_OVERWRITE_ALLOCATION(void); diff --git a/drivers/misc/lkdtm_bugs.c b/drivers/misc/lkdtm_bugs.c index e3f4cd8876b5..4906e53a6df3 100644 --- a/drivers/misc/lkdtm_bugs.c +++ b/drivers/misc/lkdtm_bugs.c @@ -8,6 +8,7 @@ #include #include #include +#include struct lkdtm_list { struct list_head node; @@ -279,3 +280,22 @@ void lkdtm_CORRUPT_LIST_DEL(void) else pr_err("list_del() corruption not detected!\n"); } + +void lkdtm_CORRUPT_USER_DS(void) +{ + /* + * Test that USER_DS has been set correctly on exiting a syscall. + * Since setting this higher than USER_DS (TASK_SIZE) would introduce + * an exploitable condition, we lower it instead, since that should + * not create as large a problem on an unprotected system. + */ + mm_segment_t lowfs; +#ifdef MAKE_MM_SEG + lowfs = MAKE_MM_SEG(TASK_SIZE - PAGE_SIZE); +#else + lowfs = TASK_SIZE - PAGE_SIZE; +#endif + + pr_info("setting bad task size limit\n"); + set_fs(lowfs); +} diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c index b9a4cd4a9b68..42d2b8e31e6b 100644 --- a/drivers/misc/lkdtm_core.c +++ b/drivers/misc/lkdtm_core.c @@ -199,6 +199,7 @@ struct crashtype crashtypes[] = { CRASHTYPE(OVERFLOW), CRASHTYPE(CORRUPT_LIST_ADD), CRASHTYPE(CORRUPT_LIST_DEL), + CRASHTYPE(CORRUPT_USER_DS), CRASHTYPE(CORRUPT_STACK), CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE), CRASHTYPE(OVERWRITE_ALLOCATION),