Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1041376imm; Wed, 22 Aug 2018 17:58:39 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw3VExqhzbs6BVeI3WHNtJHJQvMoWXgqB4yWQ90yKYCO+Vj+VmXCUG3DmslfAnWzDzoc3h7 X-Received: by 2002:a63:c50c:: with SMTP id f12-v6mr11061898pgd.113.1534985919495; Wed, 22 Aug 2018 17:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534985919; cv=none; d=google.com; s=arc-20160816; b=XWVhzccJJbqo0RFKafTDPc6fLyHIDl8I+pjJFN5CNuKV6ZEdxqQUpAdMXKnmh5KQ26 wIWi7gOQJO9LIGTTiKaYG06BgizWyz25kVawt6wRTmtPiJ2LzVY7dnjtlfzLziIITFOD iPsXQj0+EIiRSMMNNDeNYd+PkwGV9UuLh6OrJjsJlSbD9Mevv84SP+WdWtvKt8+f0+Js mU83QYT7f1+1QiaSlQqlgzsN/08a/Mo1kryQYonRmSGZHnXhWBx2yS89N5ACDdntPs3A ocCCjUaw6899XzMXgxsoGCKYd507JEx4jKwlGrJ392KliLSU8DAB8ESlNFywGIqt676W wvHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=4Zfeh/7ZYgfMNgZA9AlNRZU03af4gwNJS9F4XB6chF8=; b=grM3h9dxwDPovz45el7ysC35gs+AH8KrIlWYiOv9VuVwJfUmtbtf/J2/dzxcjLu47U Wt5W/htQgUrVFVAw4kYR9N2vTPUC6WhQFMdAWC5vy0C1boFUImsmM2a+WjoKDn93sspd F3P1y0hLHFcPzf2DzbKTbpkvr7Of6qZJeYKTqUySOOBMR80zKn3yWqXn2dRpR+P/3Qz9 25Y7vWMd1wCV9B28ElWpYhXvM5wrejihOTuyl010B4YKIkXtijKe3S13tLFUNLwA6VMA IjSvyPwnnL+HkYw895jWuu+le83TO+hCE/pHyWTZFVT6tiLBq0DRVS7z1WCZZ38mTr9J XZrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=phau4Dik; 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 r1-v6si2876017plo.100.2018.08.22.17.58.24; Wed, 22 Aug 2018 17:58:39 -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=phau4Dik; 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 S1726509AbeHWEXM (ORCPT + 99 others); Thu, 23 Aug 2018 00:23:12 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:39395 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbeHWEXL (ORCPT ); Thu, 23 Aug 2018 00:23:11 -0400 Received: by mail-oi0-f65.google.com with SMTP id c190-v6so6424267oig.6 for ; Wed, 22 Aug 2018 17:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4Zfeh/7ZYgfMNgZA9AlNRZU03af4gwNJS9F4XB6chF8=; b=phau4Dik+U/nSHa9l4qHwvU/ZPofv0dfOs9b4aDLVaKlNArpmzB/6cMe1L3mh2bqUI G9jrC0hVvanYlnK0O1yVbui/bFXT9vafDkAYpRwoFtGwuehNeu983AYn0pBgxmWHtP1W Va/xHCMVBWxyVIuhvoUnc0uW++aziD/2eZ61le3gv6xGH8213XBjUmKVucUPMlM5u1Cw Hz2YxnbeTUz5rWOmdG4tLPPUqFnf6p7MpjEf2ppxnDVFfbE2heo7ltNNmBx3yvDnGu3k GPz+2qZiec5yNIM9plYaaCT7YEoGRSJL1vbzrBFtkST8XDTBORruRY9oP1n+N/1i4V1J hwjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4Zfeh/7ZYgfMNgZA9AlNRZU03af4gwNJS9F4XB6chF8=; b=Y9pvgHyCycYNkrqYEfrNVfVruwhoOaUGtzED7CBmw+Ql4gXJVuID+fmRdINRQX1Noq jd20/jVzE2y4e5+XgVNm4errZsEvum5wWV1DGFROI3w7FDLeTBy7Bzuq1WeFOiJokiDn +/q0bWIMLPQdM+yf+/HaXyuG9vsncmXV6BNhyqnInP1Uwmz4ZvW8sFVJ9wdqKBYwMMj6 rjVoE1aGr684Gd882GXbjz5wBbFtuYPxSuOWoFmwMJ5fpeTH7MbfC6QpG/0w45BI+6Rw wQ/krC8k+H4sMaYfG0VVppghHIfSiFedPZ5pVtf3d5IMLvumcCUH1jldt/gFayBP9Een tNfg== X-Gm-Message-State: APzg51Cy/lqVITWmxs+0cUPy6ICkEJ5W9nx/ZLXbaPaOA5fndAoIVJzz Itg+lVfdjWbzrNckJxrn2R5i+zjD9Vlgt5SR3Gya+w== X-Received: by 2002:aca:e504:: with SMTP id c4-v6mr5997610oih.246.1534985765410; Wed, 22 Aug 2018 17:56:05 -0700 (PDT) MIME-Version: 1.0 References: <20180807012257.20157-1-jannh@google.com> In-Reply-To: From: Jann Horn Date: Thu, 23 Aug 2018 02:55:39 +0200 Message-ID: Subject: Re: [RFC PATCH 1/2] x86: WARN() when uaccess helpers fault on kernel addresses To: Andy Lutomirski Cc: Kees Cook , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , "the arch/x86 maintainers" , Kernel Hardening , kernel list , Andy Lutomirski , Dmitry Vyukov 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 On Thu, Aug 23, 2018 at 2:28 AM Andy Lutomirski wrote: > > On Wed, Aug 22, 2018 at 4:53 PM, Jann Horn wrote: > > On Tue, Aug 7, 2018 at 4:55 AM Andy Lutomirski wrote: > >> > On Aug 6, 2018, at 6:22 PM, Jann Horn wrote: > >> > There have been multiple kernel vulnerabilities that permitted userspace to > >> > pass completely unchecked pointers through to userspace accessors: > >> > > >> > - the waitid() bug - commit 96ca579a1ecc ("waitid(): Add missing > >> > access_ok() checks") > >> > - the sg/bsg read/write APIs > >> > - the infiniband read/write APIs > >> > > >> > These don't happen all that often, but when they do happen, it is hard to > >> > test for them properly; and it is probably also hard to discover them with > >> > fuzzing. Even when an unmapped kernel address is supplied to such buggy > >> > code, it just returns -EFAULT instead of doing a proper BUG() or at least > >> > WARN(). > >> > > >> > This patch attempts to make such misbehaving code a bit more visible by > >> > WARN()ing in the pagefault handler code when a userspace accessor causes > >> > #PF on a kernel address and the current context isn't whitelisted. > >> > >> I like this a lot, and, in fact, I once wrote a patch to do something similar. It was before the fancy extable code, though, so it was a mess. Here are some thoughts: > >> > >> - It should be three patches. One patch to add the _UA annotations, one to improve the info passes to the handlers, and one to change behavior. > >> > >> - You should pass the vector, the error code, and the address to the handler. > > > > I'm polishing the patch a bit, and I've noticed that to plumb the > > error code and address through properly, I might need significantly > > more code churn because of kprobes - I want to make sure I'm not going > > down the completely wrong path here. > > > > I'm extending fixup_exception() to take two extra args "unsigned long > > error_code, unsigned long fault_addr". Most callers of > > fixup_exception() are fairly straightforward, but > > kprobe_fault_handler() has a dozen callchains from different exception > > handlers, and most of them are coming via notify_die(). > > KILL IT WITH FIRE!!!!!!!! > > More seriously, kill kprobe_exceptions_notify() and just fold the > contents into do_general_protection(). This notifier chain crap is > incomprehensible. I would love to see notify_die() removed entirely, > and crap like this is just more reason to want it gone. This isn't just do_general_protection() though, that's just one example. As far as I can tell, similar stuff happens everywhere where notify_die() is used - #DF, #BR, #BP, #MF and so on. > > I think there's also some inconsistency between #PF and #GP in the > > ordering of error handling: > > It's probably a bug. It's also probably irrelevant, but maybe not. Depends on what people do in their ->fault_handler hooks, I guess. Yeah, probably doesn't matter.