Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4161898imm; Mon, 6 Aug 2018 18:32:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcHEBpqu7UMpl2+ZoJ9GbIFRraF8y5lYGdeJy1VjkMETc3721qDZWQCqd02FfCb8MLzTZU5 X-Received: by 2002:a63:7f16:: with SMTP id a22-v6mr16482113pgd.255.1533605531259; Mon, 06 Aug 2018 18:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533605531; cv=none; d=google.com; s=arc-20160816; b=bJ9NhXQZRUsWrOvozDX2Iu0CeiWYstYBgttrvUwftz3RaRkDyMS4duDOMf1MP2kpVA qiT7WBGljwoOZG3nIiOwM2ihs/PoeIRFtTL+BgUC/WaWvxa5TNRCFztORlixpVltHJ3S c8HKD+clt6/gAG5dhCTKxFoGdrW+Uk3X8ValzmvU6KJrv47EiTMQQATEwYOFw36ZG9JK KaS8Wv1Nc8g0zGFQIG7iOxyVr/RFeSJZ1NLdificcB+UH9cqSk1S7oe2X/B9VsIAASA9 13spBqtxtDXX55O6yHnxJdGcIwnRdSPY4YIRHIPbq5l1JPH67eolWZ/ng2JXkcUjJu+D toyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature :arc-authentication-results; bh=EeM9pl7nl45D9C+13M38eu9VuNZcRlR9egYZrxuwyYM=; b=hV70RlgU2MOAjMBZZD3G6zoD58SKfTb484w322Ei8Zn9g5/5wuxAtyYuLZAxc33X2c FGVA8Ww7kfF3G4V+Eg23cTvgBXC5t96aIb3T02Cp3u28x8kIK6m7SwPC52vZn5ErtVhU A9xAynR2Q+kRc0IHQERciLt8RY1WxU6Uq3tp1UjF90d/a9xx4MyHg7+BG0gD/10gXJHH uyUBxVj4VdhgKNhuQIiHi+eviB5KQFLZw1P1vH1eLyLNt6Ajec6iUjpBTqoefZHdN2T1 PwFHIrZxxN1ejBORCYkX2ikvbpiGbZRoqgjOTAmxzPxcPVIOQs+GEsrdKCvO+d1EOm8P EISA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=u7Y24NcD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8-v6si10943407pll.493.2018.08.06.18.31.56; Mon, 06 Aug 2018 18:32:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=u7Y24NcD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387660AbeHGDfE (ORCPT + 99 others); Mon, 6 Aug 2018 23:35:04 -0400 Received: from mail-ua0-f201.google.com ([209.85.217.201]:48034 "EHLO mail-ua0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731331AbeHGDfD (ORCPT ); Mon, 6 Aug 2018 23:35:03 -0400 Received: by mail-ua0-f201.google.com with SMTP id g19-v6so10262333uan.14 for ; Mon, 06 Aug 2018 18:23:15 -0700 (PDT) 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=EeM9pl7nl45D9C+13M38eu9VuNZcRlR9egYZrxuwyYM=; b=u7Y24NcD9NIt0JcxdraGBb4gYa4PIrSBLk5f/pcgg3hc8WdbhAr3zZtAsT6cYl6HXM Q0xtRU+800C2V88IYcQral504EqTMW/jZ6NoY5tnt6uj8MQgiJdOAB3vk4JGsiJV9KRj HJDH1Y7gIbQg/CvEUogC9F2zn5zDm2OMjm5JvAw4mJtTBvgfPy5Dvp5wlfXys1NtH+7w GJjX+MHaa+nclBKhSD0sZZ457WXR7JTDbkwB3XaudINjXLrvrv9j7JobPOLAcalYPpOW eNiaLBQQH1dfBsvl9YZq9MuJiKDxWCGP8AOBxziWnsLhvm6+3zkCOzcxp79TPmB74FC1 +ODQ== 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=EeM9pl7nl45D9C+13M38eu9VuNZcRlR9egYZrxuwyYM=; b=F9miO9g5TB57CSFfjLjxSc7ihpTMxDCFNFcKOVjqNjVCV4UeDj63QLPJxJsBAO1gz6 80qYYy4V1qjV2Cf2wROrcvbtUUoQuF+tgWBDBEgCQ1+iSFcVB60L+eG7xyDPlRgaCxrF KX8FOCG/5uBf6dRBEyxzCz5qsHxbCnvLuM8MYQi0JXDPKm0tEHbGG7iLBo/C4lfq9QYn xJQbyRt1rcRjhhnQCWlPOoZWFPUTPOM+PZvImxffgQ5CfF4r09CcTzcWFDtzRhj8+aCO np/a1UsZwRDzJ/rWxznrRZtIQLhA6b8PRW6QnQckeouNWRc8SNfyb+PUCzmGP8tgSV1s DDOg== X-Gm-Message-State: AOUpUlEh/knKKN6Rcm2l9Lq+h6ZjC9pNDu0dM9eKQBSD0tOU3odyDqdD 7suw95S4B7pilLYMubPCa5Z7GrBgZQ== X-Received: by 2002:a1f:a347:: with SMTP id m68-v6mr11036590vke.43.1533604994654; Mon, 06 Aug 2018 18:23:14 -0700 (PDT) Date: Tue, 7 Aug 2018 03:22:57 +0200 In-Reply-To: <20180807012257.20157-1-jannh@google.com> Message-Id: <20180807012257.20157-2-jannh@google.com> Mime-Version: 1.0 References: <20180807012257.20157-1-jannh@google.com> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog Subject: [RFC PATCH 2/2] lkdtm: test copy_to_user() on bad kernel pointer under KERNEL_DS From: Jann Horn To: Kees Cook , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, kernel-hardening@lists.openwall.com, jannh@google.com Cc: linux-kernel@vger.kernel.org, Andy Lutomirski , dvyukov@google.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Test whether the kernel WARN()s when, under KERNEL_DS, a bad kernel pointer is used as "userspace" pointer. Test with "DIRECT" mode. Signed-off-by: Jann Horn --- 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. */ -- 2.18.0.597.ga71716f1ad-goog