From patchwork Mon Aug 27 18:56:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 10577585 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 5587C5A4 for ; Mon, 27 Aug 2018 20:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4922A29F75 for ; Mon, 27 Aug 2018 20:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BC112A04C; Mon, 27 Aug 2018 20:35:09 +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 625D929F75 for ; Mon, 27 Aug 2018 20:35:08 +0000 (UTC) Received: (qmail 22146 invoked by uid 550); 27 Aug 2018 20:35:06 -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 26108 invoked from network); 27 Aug 2018 18:58:05 -0000 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=KBDYTwl+4YqOfnO5Qfg86x4cKuvMKrAYQHW8MjM7Sds=; b=o9crLYXA1KBVkHprU7iR4oojNCYfx0uxHyHSLNCkuQrKYrCnSBnaqMMyFELgVXd1NZ DAXXMej5rPOgAvVYzUelSVx7IIGxcrD9FAWTz9rULDc3e9Ac+TfzU2AcJ/5GGyVGnVKJ hS11XZbVar/Zr3KgB/yy7tXA93X55V8ZjgGKtfh+sn9FrvgVjJgFkPHLLa8nZQet3U9V n2de6p9ZUNe5uC2cMTEdz8g7WDzmcSLRfNTcOLaNa+u1aHrzpekIM0kxppOOijTsP5eS kPWizBb7tbRMa064qCQl6hhgL9mjFA94KU5fMeCVpvrZx4rUNkNhFKmvuh0GVRswxZ75 XuuA== 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=KBDYTwl+4YqOfnO5Qfg86x4cKuvMKrAYQHW8MjM7Sds=; b=jU7l8NZxZXp+WKY/yO2/xVMKC/pacyRDyL853XYtrMyVfj0LPt+mkOMgnSpKFgebgi hEdMPo85xvGkrW3HS6xikHtZ4n3CXPsthcsVuyV6D6d9lChFKJLeFrRiCy2YIlfVvVt/ JhNZxpM2Wj6uI4YAfxZQWgntBIhwEB5tRtIMvhmBeWQRNT60KJQpcEdsvEmTyc+Dgxbe jZHorgtIdZ3r11SETNfjKyWaxOIBMW6PYqc/Y1Mjo+OYDaeIqUxel/rdpqoLrL/IBQA+ qPlbVKt9036mp8MdvTPHau0KyRnDl0EKiuTVChhwisNNzhyh9T3nTmEjvLgPwU1dP/35 fRUg== X-Gm-Message-State: APzg51CJW5tgCkVbnu1zW2ujWS+kx5tLC5amPbQGctkF+SA/fyppNYV+ 6WOJ110WSjZzqdWq/HT6W8+yC2KrrQ== X-Google-Smtp-Source: ANB0VdYevvTK8UaxtYEQwxoCuHfWK0zoq9LG6T+yi/CM+Cq4Si26e92JZ4jvKH6PfCJcXKmEluyhASxfKQ== X-Received: by 2002:a81:a1c3:: with SMTP id y186-v6mr4485ywg.206.1535396273261; Mon, 27 Aug 2018 11:57:53 -0700 (PDT) Date: Mon, 27 Aug 2018 20:56:25 +0200 In-Reply-To: <20180827185631.163506-1-jannh@google.com> Message-Id: <20180827185631.163506-2-jannh@google.com> Mime-Version: 1.0 References: <20180827185631.163506-1-jannh@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH v2 1/7] x86: refactor kprobes_fault() like kprobe_exceptions_notify() 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 an extension of commit b506a9d08bae ("x86: code clarification patch to Kprobes arch code"). As that commit explains, even though kprobe_running() can't be called with preemption enabled, you don't have to disable preemption - if preemption is on, you can't be in a kprobe. Also, use X86_TRAP_PF instead of 14. Signed-off-by: Jann Horn --- arch/x86/mm/fault.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index b9123c497e0a..2254a30533b9 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -44,17 +44,14 @@ kmmio_fault(struct pt_regs *regs, unsigned long addr) static nokprobe_inline int kprobes_fault(struct pt_regs *regs) { - int ret = 0; - - /* kprobe_running() needs smp_processor_id() */ - if (kprobes_built_in() && !user_mode(regs)) { - preempt_disable(); - if (kprobe_running() && kprobe_fault_handler(regs, 14)) - ret = 1; - preempt_enable(); - } - - return ret; + /* + * To be potentially processing a kprobe fault and to be allowed to call + * kprobe_running(), we have to be non-preemptible. + */ + if (kprobes_built_in() && !user_mode(regs) && !preemptible() && + kprobe_running() && kprobe_fault_handler(regs, X86_TRAP_PF)) + return 1; + return 0; } /*