From patchwork Mon Aug 27 18:56:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 10577597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3C2B5A4 for ; Mon, 27 Aug 2018 20:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C580A2A09F for ; Mon, 27 Aug 2018 20:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B726C2A0D1; Mon, 27 Aug 2018 20:36:15 +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=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL 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 D33BC2A09F for ; Mon, 27 Aug 2018 20:36:14 +0000 (UTC) Received: (qmail 30009 invoked by uid 550); 27 Aug 2018 20:36:04 -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 Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 26360 invoked from network); 27 Aug 2018 18:58:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ycFD50Qbqy2nsG8VK8f/Mv9TVDy1OUIkLU31FaF+unc=; b=Inp3rDYfU183FlYE+NFUsy7ksvex6gl9N2We90XZsfgqClFLoFcriIVQcXEyyfEeZF WxFcaVIghxRt5djJfm3wc5G1w1KItP+zoql6wI+Rve/EEkf0bASuUvgGlPsVwrmDqa3c oNfZ4udfPhnb5FVZnP/tUIzGyQWIjre3LHDdkywsMGLYpdtmnJyqjd52VeI8L+i5ZpzW zfh8tsFrPRRCjm9a3zgXSqSVAajVT/wjOpaWjzYfa/tjiRllc4sMW3mdAI15jVQVXazM mIS8BU0Wto84H+0aZ3N1mgg/rWCQr10Xf/dvjKAwnd4oXMi/Qkd8XgmI9rI6BX6SqX+m qleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ycFD50Qbqy2nsG8VK8f/Mv9TVDy1OUIkLU31FaF+unc=; b=A7zckHb15hUTtxDPe4VdOVPQmds3GHmgr1FToW3DoPL782HI4ITT87+VZyuNbd2KTm oziKBhDYZudTbVXCrgl4uek/8shfxdZyOPMRckMBXvRUuoOe3G76A5Uq9ccA/1KbPYwp OXjRqMXM8CGOJRnfMWIzoVM7AL3aRrdtAvhya91oIff6AALehcOJI38QeDMFJ0KqjvuL 9fCYiCvYaxsDKH2LE/h3LVbS7v98rIU20faAg7b25qqi8FHqAzCu9QUfXub/y5sASaxI RMLBDbjsMJoafJDVrq3oye0xy/OghmJlW2Oa3VrFCKKToWGPXBiJSm+bAsSIrHj2vqPA NIXA== X-Gm-Message-State: APzg51BVEJd+byKtgD+exsmKODhGYj5KykHh6oKEf0Z62muMBZrD776F RRC7yCcGbHCujOuv2l6jQAWoHlgZ9g== X-Google-Smtp-Source: ANB0VdaXjqOrrHANxz1rCv+tH9fays7AA2RAsMOahiQ8j6ctktmJS29FhFIfemOGyGe8R5FsvzGjCzFPjA== X-Received: by 2002:a1f:a991:: with SMTP id s139-v6mr6956921vke.107.1535396292059; Mon, 27 Aug 2018 11:58:12 -0700 (PDT) Date: Mon, 27 Aug 2018 20:56:31 +0200 In-Reply-To: <20180827185631.163506-1-jannh@google.com> Message-Id: <20180827185631.163506-8-jannh@google.com> Mime-Version: 1.0 References: <20180827185631.163506-1-jannh@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH v2 7/7] lkdtm: test copy_to_user() on bad kernel pointer under KERNEL_DS From: Jann Horn To: Kees Cook , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Andy Lutomirski , kernel-hardening@lists.openwall.com, Tony Luck , Borislav Petkov , jannh@google.com Cc: linux-kernel@vger.kernel.org, dvyukov@google.com, linux-edac@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Test whether the kernel WARN()s when, under KERNEL_DS, a bad kernel pointer is used as "userspace" pointer. Should normally be used in "DIRECT" mode. Signed-off-by: Jann Horn Acked-by: Kees Cook --- drivers/misc/lkdtm/core.c | 1 + drivers/misc/lkdtm/lkdtm.h | 1 + drivers/misc/lkdtm/usercopy.c | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c index 2154d1bfd18b..5a755590d3dc 100644 --- a/drivers/misc/lkdtm/core.c +++ b/drivers/misc/lkdtm/core.c @@ -183,6 +183,7 @@ static const struct crashtype crashtypes[] = { CRASHTYPE(USERCOPY_STACK_FRAME_FROM), CRASHTYPE(USERCOPY_STACK_BEYOND), CRASHTYPE(USERCOPY_KERNEL), + CRASHTYPE(USERCOPY_KERNEL_DS), }; diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index 9e513dcfd809..07db641d71d0 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/lkdtm.h @@ -82,5 +82,6 @@ void lkdtm_USERCOPY_STACK_FRAME_TO(void); void lkdtm_USERCOPY_STACK_FRAME_FROM(void); void lkdtm_USERCOPY_STACK_BEYOND(void); void lkdtm_USERCOPY_KERNEL(void); +void lkdtm_USERCOPY_KERNEL_DS(void); #endif diff --git a/drivers/misc/lkdtm/usercopy.c b/drivers/misc/lkdtm/usercopy.c index 9725aed305bb..389475b25bb7 100644 --- a/drivers/misc/lkdtm/usercopy.c +++ b/drivers/misc/lkdtm/usercopy.c @@ -322,6 +322,19 @@ void lkdtm_USERCOPY_KERNEL(void) vm_munmap(user_addr, PAGE_SIZE); } +void lkdtm_USERCOPY_KERNEL_DS(void) +{ + char __user *user_ptr = (char __user *)ERR_PTR(-EINVAL); + mm_segment_t old_fs = get_fs(); + char buf[10] = {0}; + + pr_info("attempting copy_to_user on unmapped kernel address\n"); + set_fs(KERNEL_DS); + if (copy_to_user(user_ptr, buf, sizeof(buf))) + pr_info("copy_to_user un unmapped kernel address failed\n"); + set_fs(old_fs); +} + void __init lkdtm_usercopy_init(void) { /* Prepare cache that lacks SLAB_USERCOPY flag. */