Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1022110imm; Wed, 22 Aug 2018 17:30:07 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwCKYoI1uTleBZ+0OYLdYjnGPtYJfyZ3gfTZA5CcmDAsfvbYVARpjjhg0fSXPV3RJlGgc1Y X-Received: by 2002:a17:902:15c5:: with SMTP id a5-v6mr55877450plh.137.1534984206939; Wed, 22 Aug 2018 17:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534984206; cv=none; d=google.com; s=arc-20160816; b=l2PuXKiVRqIZKPbN0Epl18ei4BOKefowV+gedxyo4cmY6LSOEAFMQv50XC90LsGDrV GcJfR2gaKgaaTfnviY8AnfSIbucjQGc+AG3X4HCCRL5Zo5Y93vrtETRyl1Cd/UCYuu2h kRpigX2ovjopXZgXqTktmMgrjKCyePKxBv72Ad1mdHCQvCTmO74oTvDK39DIVETjb41B tOCv82+Il/B98RL3mP0oeKW9EfUX8i/IpWPTj/gCEy2MGd/oJAr5gX+/stGWrZCkyY8k 2zZm5I8Ju/kDz1Vq2suGQjn60AHOPBeUmLt9yE14rpaVnHiYOfmpTiYk4FOeyez+a5pr igGg== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=6L+ncNStlKcOxmgbMiAHgbGIXqLn7eK23P7cqWQBDR4=; b=TiK2ty25O9u0MvrRUorw4EiSl54BFXdb3XehZ69obm4sfsv7h5pM1VHFcyUr921Slu leIBt0aksH0LXYPXKpc+JQEtF0rD811yr88WVHLA/BuiOyS8anp7bkwwQbTXYYxAhvKC gtLQS/V18Vugiar9gOF5+ZTf+OkAlQxf6LssFonWQBi22Vp8DH/82+WcUgdZJTYwhPYE VSki+vnWNSufITG9IIIDblbIHmMhOlzGAixXLffsVv0+82fMri/+7ezHr6lIIxe8eD84 gXSmCXCDnM8kybEVGhGHvHUeY+ochWyYWmCtaCzJoIsZwEsnRDS+EBYg2U3LiH+SItkf lZgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=yqbUxqIj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si2788588pgf.415.2018.08.22.17.29.51; Wed, 22 Aug 2018 17:30:06 -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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=yqbUxqIj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727624AbeHWDzr (ORCPT + 99 others); Wed, 22 Aug 2018 23:55:47 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45129 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727322AbeHWDzr (ORCPT ); Wed, 22 Aug 2018 23:55:47 -0400 Received: by mail-wr1-f68.google.com with SMTP id 20-v6so3028739wrb.12 for ; Wed, 22 Aug 2018 17:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=6L+ncNStlKcOxmgbMiAHgbGIXqLn7eK23P7cqWQBDR4=; b=yqbUxqIjVAnQ2ymuUlJuQh+ZEcLRNaBisFQfQ2hlOkStQCHwuAosMGTqcoQMI2d1CO OrqD9ZqOcWOn1/f9A9F6iCyx8tlcN4KiPuk54lP8f10rs+rvkeEwWk2NE1uUQIBbj0CF 1k6+66LkGHEBO2SWDaLeg+iH+6hj3wdvYBHpp/kswDWBA1A9GYnewKnWl/1PNKmeJaGs q6hjSXo/GuDiMbPivoq7urk4/7wFqP74w1P10HYQyxlrEWxsU6nMEGAqxGyDqhd41g5I ZGYzqaSaEhrOb23e1Q//xk9TqwJuNJHVPgob33+kuUd8bJf4YUL6ROqnau0OjTD0lfTP Gkdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=6L+ncNStlKcOxmgbMiAHgbGIXqLn7eK23P7cqWQBDR4=; b=RdHaYzmEugt4ZAADpiRs1goEG6qgmoKYYB+mJXNqlc9DpFUE7I2NQPT+I4NKWQuNC2 dzHTyFTuZn7sdfHXmF7wDE9/WIjJ7iTM5EwaFF/D4fO00MHmbcaKM0WZbYtnzM28/G/Q zBlX0AcazZniCWexE/xhrxAHYp+ko8wgbyQTOjrCa14nfDxXDO1XEMDN5smTz72QBmVv eF+9zm3u7b0Jse9khRQMvMbtK/q7GX6WAWc4VIFuwTqKaO3F2wIJuIoLXdHInQfPLVI9 0ubrYlRpQqQG+qpTHqPNb3IwmTjAeuL0SEHGtWuNiSSRK0kxVfadkjK2Qt72F+3yb5ZF UtTg== X-Gm-Message-State: AOUpUlFl3rqvy8k+v3goPbyEsa4CUvWnAydk1tJ0PXdSzaOvGfCsO3ap nkY6lrDOdwqdtD1aDRfqDz3yc/ilwVOljUOw+H3sAw== X-Received: by 2002:adf:c554:: with SMTP id s20-v6mr35686781wrf.46.1534984124465; Wed, 22 Aug 2018 17:28:44 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:548:0:0:0:0:0 with HTTP; Wed, 22 Aug 2018 17:28:24 -0700 (PDT) In-Reply-To: References: <20180807012257.20157-1-jannh@google.com> From: Andy Lutomirski Date: Wed, 22 Aug 2018 17:28:24 -0700 Message-ID: Subject: Re: [RFC PATCH 1/2] x86: WARN() when uaccess helpers fault on kernel addresses To: Jann Horn 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 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. > 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.