From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D734C43613 for ; Mon, 24 Jun 2019 10:07:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8D64208E3 for ; Mon, 24 Jun 2019 10:07:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370876; bh=Cv7B6S4b4ErBNH00xyoVxNtkOjnOPMKuWbetOglwOgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DNLUsoBcOCV66xlSm07m8X6A2Z2Q7hDUlJXjEiUBBroVpi8yJvboAxG+QfgAP15aI /9qmH7IEVR/KYJy/YyktP+VcaQdkkqM+cIadQAcArNH0tovB4CjcRq8v6O8zRNBern A7X8Xl/piXPz7wjlImJ0tSgajuMJTCRVSEHmbY9M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730377AbfFXKHy (ORCPT ); Mon, 24 Jun 2019 06:07:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:40726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730372AbfFXKHy (ORCPT ); Mon, 24 Jun 2019 06:07:54 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C0F9F205C9; Mon, 24 Jun 2019 10:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370873; bh=Cv7B6S4b4ErBNH00xyoVxNtkOjnOPMKuWbetOglwOgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b3zX8TcT3U12bhEfkAjBShbzj4uDOeLCe0uTEMxrhPsOJ9gfDsWd/ajsrG7yuRTv/ P2JVXDLj0fi/9dqJjJ3lCQ04cg4pauBqcZK9mSps7OysP2fgWqCeAgCRku8RS4XQc3 z07Kl6BxuNfelZodfb4THFyYqcKhKiX4YYSHNRGk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Sasha Levin Subject: [PATCH 5.1 031/121] lkdtm/usercopy: Moves the KERNEL_DS test to non-canonical Date: Mon, 24 Jun 2019 17:56:03 +0800 Message-Id: <20190624092322.416427054@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 2bf8496f6e9b7e9a557f65eb95eab16fea7958c7 ] The prior implementation of the KERNEL_DS fault checking would work on any unmapped kernel address, but this was narrowed to the non-canonical range instead. This adjusts the LKDTM test to match. Fixes: 00c42373d397 ("x86-64: add warning for non-canonical user access address dereferences") Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- drivers/misc/lkdtm/usercopy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/misc/lkdtm/usercopy.c b/drivers/misc/lkdtm/usercopy.c index d5a0e7f1813b..e172719dd86d 100644 --- a/drivers/misc/lkdtm/usercopy.c +++ b/drivers/misc/lkdtm/usercopy.c @@ -324,14 +324,16 @@ free_user: void lkdtm_USERCOPY_KERNEL_DS(void) { - char __user *user_ptr = (char __user *)ERR_PTR(-EINVAL); + char __user *user_ptr = + (char __user *)(0xFUL << (sizeof(unsigned long) * 8 - 4)); mm_segment_t old_fs = get_fs(); char buf[10] = {0}; - pr_info("attempting copy_to_user on unmapped kernel address\n"); + pr_info("attempting copy_to_user() to noncanonical address: %px\n", + user_ptr); set_fs(KERNEL_DS); - if (copy_to_user(user_ptr, buf, sizeof(buf))) - pr_info("copy_to_user un unmapped kernel address failed\n"); + if (copy_to_user(user_ptr, buf, sizeof(buf)) == 0) + pr_err("copy_to_user() to noncanonical address succeeded!?\n"); set_fs(old_fs); } -- 2.20.1