From patchwork Mon Aug 27 18:56:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 10577583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDF2C174A for ; Mon, 27 Aug 2018 20:34:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C887929F75 for ; Mon, 27 Aug 2018 20:34:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBF432A04C; Mon, 27 Aug 2018 20:34:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id D1ECB29F75 for ; Mon, 27 Aug 2018 20:34:56 +0000 (UTC) Received: (qmail 20403 invoked by uid 550); 27 Aug 2018 20:34:54 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 26061 invoked from network); 27 Aug 2018 18:58:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=CrPdBBcwk99epHml2S6cYfO/WlQ+fyiLt/9ijCXrSp8=; b=GHJyePU/W1cgX7K2kXjdOhpfYW0kXt0IJEE3ZIzKjlx9TKdTonrWPqQa6wWXNYngRu OL7yTaMGxh9Rfe7RaBMnaWaWVz+nny17tAZzSvSza55SElPCcfSHaebSpOAigGU1R8MU 1UpdJsp4VRacTgFNGyqmZL7VmyQ3C53eYFHyPuD8pktVOw+uQLI5OBzxFlMjiBynpOEu QNG8Ewr0bF5sHY5MfXDPskvd6pBXu+uP45K5mlWilQCMu3V+GY/vm6ZS83BIeGYAW6XG tj3scn3OpQbT8M+L27H/r9LiA8jwknDZEHFpWShd9WBdVSiPu7+N+dETyn9mZOav9aD5 PGMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=CrPdBBcwk99epHml2S6cYfO/WlQ+fyiLt/9ijCXrSp8=; b=pn5eF1EoPjAJVnqfgWIZQ42ef7idX0JCxqlriImKz8UkTWzgLMVpqUN17fMVCC8UT/ uon9PGmc30sFsAqRgYVeanqZLnlbaeAPyEdf3lsDk0S2avexM2vKp4XuPDKBeIJ9WrOF cvAhdLwszBfcWb1rQmiU7z3FA78bvdY51I3NkbK/VQu5bbn1PGany/uWmqN2P1vpHU31 MrAvFNG9oWSQvlP608Yvjqv25akE1v0Q2Qxopx7/33/+4SoVri/9sOFxRJhsXZxzPKP/ SvW72ySY+Su5adz2RwXqc537ZlCGFQFRV2i+L6DUlciqgq+I0KuwlBoy3CK0td89YjNV e83w== X-Gm-Message-State: APzg51Dj/H9j8lcrqo4F/EgDi4JMsyg5O0LwRhkY1BpQORNuFhZzeVh0 NKux8LgfgRWSm3nbTAdKbKNKjlyfag== X-Google-Smtp-Source: ANB0VdZffx48GvmurdIBDcdVHjoRie0ANsXOY3r4p+c5X7C02zbGBbhD/QMB/ZzLfqPcB8MDPotDhhiwvA== X-Received: by 2002:a9f:3812:: with SMTP id p18-v6mr7493785uad.103.1535396270277; Mon, 27 Aug 2018 11:57:50 -0700 (PDT) Date: Mon, 27 Aug 2018 20:56:24 +0200 Message-Id: <20180827185631.163506-1-jannh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH v2 0/7] x86: BUG() on #GP / kernel #PF in uaccess From: Jann Horn To: Kees Cook , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Andy Lutomirski , kernel-hardening@lists.openwall.com, Tony Luck , Borislav Petkov , jannh@google.com Cc: linux-kernel@vger.kernel.org, dvyukov@google.com, linux-edac@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is the second version of "[RFC PATCH 1/2] x86: WARN() when uaccess helpers fault on kernel addresses". See patch 6/7 ("x86: BUG() when uaccess helpers fault on kernel addresses") for a description of the motivation for this series. Patches 1 and 2 are cleanups that I did while working on this series, but the series doesn't depend on them. (I first thought these cleanups were necessary for the rest of the series, then noticed that they actually aren't, but decided to keep them since cleanups are good anyway.) Patches 3, 4 and 5 are prep work; 4 and 5 are loosely based on code from the v1 patch. They've changed quite a bit though. Patch 6 is the main semantic change. Patch 7 is a small testcase for verifying that patch 6 works. Jann Horn (7): x86: refactor kprobes_fault() like kprobe_exceptions_notify() x86: inline kprobe_exceptions_notify() into do_general_protection() x86: stop calling fixup_exception() from kprobe_fault_handler() x86: introduce _ASM_EXTABLE_UA for uaccess fixups x86: plumb error code and fault address through to fault handlers x86: BUG() when uaccess helpers fault on kernel addresses lkdtm: test copy_to_user() on bad kernel pointer under KERNEL_DS arch/x86/include/asm/asm.h | 10 ++- arch/x86/include/asm/extable.h | 3 +- arch/x86/include/asm/fpu/internal.h | 2 +- arch/x86/include/asm/futex.h | 6 +- arch/x86/include/asm/ptrace.h | 2 + arch/x86/include/asm/uaccess.h | 22 ++--- arch/x86/kernel/cpu/mcheck/mce.c | 2 +- arch/x86/kernel/kprobes/core.c | 38 +-------- arch/x86/kernel/traps.c | 16 +++- arch/x86/lib/checksum_32.S | 4 +- arch/x86/lib/copy_user_64.S | 90 ++++++++++---------- arch/x86/lib/csum-copy_64.S | 8 +- arch/x86/lib/getuser.S | 12 +-- arch/x86/lib/putuser.S | 10 +-- arch/x86/lib/usercopy_32.c | 126 ++++++++++++++-------------- arch/x86/lib/usercopy_64.c | 4 +- arch/x86/mm/extable.c | 104 +++++++++++++++++++---- arch/x86/mm/fault.c | 21 ++--- drivers/misc/lkdtm/core.c | 1 + drivers/misc/lkdtm/lkdtm.h | 1 + drivers/misc/lkdtm/usercopy.c | 13 +++ include/linux/sched.h | 6 ++ mm/maccess.c | 6 ++ 23 files changed, 297 insertions(+), 210 deletions(-)