Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp133136imm; Tue, 7 Aug 2018 15:29:25 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxf6Q9Sp+QRlms3ByCHVM7PS+VF8dVYB+Y/eCxPRQ8+9l70E+cqpytVirPg9TX+PsaHr19P X-Received: by 2002:a62:4ece:: with SMTP id c197-v6mr243867pfb.240.1533680965807; Tue, 07 Aug 2018 15:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533680965; cv=none; d=google.com; s=arc-20160816; b=g1af0rxIWn4KzaEXueHsixv2E56l8QedWvpHe+Eta2J2EerBTAnyDZX25EboT472jY j3kzxm3bwDVm/FH16XT24QQ1++Oj8rtQ5kdq1xGYrxKNoK74V2LjbGaZ8xREi5Gl9hIF gGFtbxJJE2BuORl4zzk4KLPcDS5CZYAtVxJENCCjv/r+T+DCyKpQsYIKprmy2MmubKpc y1XLusYdM0sG3ldXJ+1LLn3uowb+jHz78NYnscCfoqMUCrvyF2QNk/aSTY7bjh0Ffoa0 DDL7eYfaQPmmcdZ/dO6mdNC2vbH2cw8zBmAVUKLNiMDfoIZWIo49zPhPU7PwjxT6zHqL Lujw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=3AYaBXyIGCsJXUfcXqERbFYbtttGmx+ac68jEKqIERQ=; b=xmV1+kSqSs7TaluxX/TtfXLVsPb2hifoQfnh9cLBnL7bO8Cm+5QcICK1wK8Fr1laL7 5v3EK9CXxhn09WYJQ7cL0cAwE+Mk6xDntEN3vLElZ1F/OjstlRGAa9hGyoUbRc3MtxM5 XPgfbynzCONjqjTzvpmBYKqKJ1bUclMnLEZcCc61ZrcA9tfwWVaH+i5JTSm7InK2pgS2 jTzVSoKUvRWMGohiz9ByUQcQI3ln5mz/+cQbXRTaXhigDWg9yhZzC+Yx2dIZ+A0pAWee p23QnwWpstV96aVXbdD98MrUyGsNTnvMbWCbfqQn7T20suiW1aBH0/Z4p+qBP9awCZ18 5+DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=QAQ+GwHo; 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 c5-v6si1908113pll.275.2018.08.07.15.29.10; Tue, 07 Aug 2018 15:29:25 -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=QAQ+GwHo; 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 S1726890AbeHHAox (ORCPT + 99 others); Tue, 7 Aug 2018 20:44:53 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37120 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbeHHAox (ORCPT ); Tue, 7 Aug 2018 20:44:53 -0400 Received: by mail-pg1-f195.google.com with SMTP id n7-v6so107293pgq.4 for ; Tue, 07 Aug 2018 15:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=3AYaBXyIGCsJXUfcXqERbFYbtttGmx+ac68jEKqIERQ=; b=QAQ+GwHoDm8hXE3s+gMvyk9i1itjTF5IN5XgmImHtvmjF/dm1G63Y6PDZON5MrPdRA tgP27FKVD4ktbwAXNxKaQ4MuEK7X+dKBgBafMKB9/A59vlkRC/9cNnIywqpgH+ggfe6i Jc7nC/CfgdytN9bArueYGhnyHXU/tcY4Le/HAAsMtJKEIVChw7RHJS2/pye8L4q33Cen OQaHzZWCKPFW0Y9zgwDhOhbMG/QKd22erMYLK+qqv0ca5/mxXJsH4tcOcnwsiKCDJ7Rz 437juLNP/Er4QdiXA59iiDL6yEFC/dokhg+XAVYxtc8UQiLVEZMt3+c6OMudfjaZp3GK KtAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=3AYaBXyIGCsJXUfcXqERbFYbtttGmx+ac68jEKqIERQ=; b=fZn+b+zThjQS9axhCDntfRKIQbo6P3ZfzmauoPghdqC7Gra5rAU5TPVbTw4NvCmd2q AR8WPhQrSm0RARfevDiznNhezCRNgIbFnnVj4YwXvitNJMNnrU7lZwz3t06x4C8XTJiS E9WIUJmSbLXpXuo919DNt1Vxn/InoHAs6ndbBG3Wx1Sdi1EAPu1L8zeiYcL5DYXP8JYJ QJZbvWmPPxC9CtBsW5VXaf2GR6xNppLdvK/ZtnecNfSVaWEbdvndehL/VT5NSuTwnQ2s Ai7RvNnRVSL0i9K3KS//NsskWXSVtbuAmNMiYFH5rDK2Ssi3PjaH+0599VpJXL6orFro y4MA== X-Gm-Message-State: AOUpUlFctp5xjj9OhORcH+mfr7iGH9HvcH5vZy8YelB0xwJBg/Gltl8N tJyXck/6pQ0Ra+pZWF6x621whO8CGvQ= X-Received: by 2002:a62:b0c:: with SMTP id t12-v6mr259907pfi.36.1533680900448; Tue, 07 Aug 2018 15:28:20 -0700 (PDT) Received: from ?IPv6:2600:1010:b016:7102:f59d:5c2c:ab3c:d9ca? ([2600:1010:b016:7102:f59d:5c2c:ab3c:d9ca]) by smtp.gmail.com with ESMTPSA id 1-v6sm6655301pfk.134.2018.08.07.15.28.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Aug 2018 15:28:19 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [RFC PATCH 1/2] x86: WARN() when uaccess helpers fault on kernel addresses From: Andy Lutomirski X-Mailer: iPhone Mail (15G77) In-Reply-To: Date: Tue, 7 Aug 2018 15:28:17 -0700 Cc: Kees Cook , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , the arch/x86 maintainers , Kernel Hardening , kernel list , Andy Lutomirski , Dmitry Vyukov Content-Transfer-Encoding: quoted-printable Message-Id: <126BF909-1BB3-45EF-944E-C0AAD239F752@amacapital.net> References: <20180807012257.20157-1-jannh@google.com> To: Jann Horn Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Aug 7, 2018, at 2:17 PM, Jann Horn wrote: >=20 > On Tue, Aug 7, 2018 at 4:55 AM Andy Lutomirski wrote= : >>> On Aug 6, 2018, at 6:22 PM, Jann Horn wrote: >>>=20 >>> There have been multiple kernel vulnerabilities that permitted userspace= to >>> pass completely unchecked pointers through to userspace accessors: >>>=20 >>> - the waitid() bug - commit 96ca579a1ecc ("waitid(): Add missing >>> access_ok() checks") >>> - the sg/bsg read/write APIs >>> - the infiniband read/write APIs >>>=20 >>> These don't happen all that often, but when they do happen, it is hard t= o >>> test for them properly; and it is probably also hard to discover them wi= th >>> 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 leas= t >>> WARN(). >>>=20 >>> 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. >>=20 >> I like this a lot, and, in fact, I once wrote a patch to do something sim= ilar. It was before the fancy extable code, though, so it was a mess. Here a= re some thoughts: >>=20 >> - It should be three patches. One patch to add the _UA annotations, one t= o improve the info passes to the handlers, and one to change behavior. >>=20 >> - You should pass the vector, the error code, and the address to the hand= ler. >>=20 >> - The uaccess handler should IMO WARN if the vector is anything other tha= n #PF (which mainly means warning if it=E2=80=99s #GP). I think it should pr= _emerg() and return false if the vector is #PF and the address is too high. >=20 > What about #MC? do_machine_check() sometimes invokes fixup handlers. > It looks like fixup_exception() is basically reached for anything that > can't be restarted (either MCG_STATUS_RIPV isn't set or the worst > severity is MCE_AR_SEVERITY), but doesn't reach MCE_PANIC_SEVERITY? In > particular for "Action required: data load in error recoverable area > of kernel", if I'm reading the code correctly. It seems like the code > is intentionally preventing memory errors during user access from > being treated as kernel memory errors? So perhaps #MC in user access > should not WARN()? Agreed.=20 >=20 >> - Arguably most non-uaccess fixups should at least warn for anything othe= r than #GP and #UD.