From patchwork Tue Aug 28 20:14:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 10579059 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 8D76B174C for ; Tue, 28 Aug 2018 20:15:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 832292A9B4 for ; Tue, 28 Aug 2018 20:15:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 772E32ACD9; Tue, 28 Aug 2018 20:15:21 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24DA82A9B4 for ; Tue, 28 Aug 2018 20:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727360AbeH2AIE (ORCPT ); Tue, 28 Aug 2018 20:08:04 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:50159 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727356AbeH2AID (ORCPT ); Tue, 28 Aug 2018 20:08:03 -0400 Received: by mail-pg1-f201.google.com with SMTP id g9-v6so1757005pgc.16 for ; Tue, 28 Aug 2018 13:14:48 -0700 (PDT) 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=03TAXzBIbK9qSPjls82pb6bVgK3cZq6BxaYmPeOzPNA=; b=k9MstZk0c2zdNTFSvMTX0jVj6F0t2QStibNqEXye6Ey7CN7GTPilMG/QNGEft9wwy7 7z3CUVCrnrHtFjQjnkrsiBgHyXu+V4ix9rOiV4ZhUDLlcDEls7cQ49zmOUuIeITJ89J+ BBYyvErOgZn9brmOZMbBKpii+A8kEqmhE6h7D25Hru6B1N7gwxHGU+60IbF6vnTz/DUF 8eJg1VRws24//e00HOVbKSAPVB5SIPxY1rTRctGFQWg7LZDxNcVr9KHesDp/YyZOqnVd S4e9L3Tt7fufL0H57G4qQL0Kd9YsY1Wb0/g0gCfLQ0RoCOiCmnpeQbkLBeXym0aCP8mS ZUew== 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=03TAXzBIbK9qSPjls82pb6bVgK3cZq6BxaYmPeOzPNA=; b=XBdrei9qH/MnIRHp8mZHeIo5fmvg1cNsFbXBv35R9E9Rh4aFdChYiTWSv/mJEBZ2n8 kyshi3rduAsRbVSDujoupbY5PvdOKh1Iu+DG61yCkqLdxe5zst075SkhcXuGnf+TydvC zM4rKdbGrBiTxmQeJDlsgqj+d5r5ZWVoZZQf206SLIkV0iODEjqkYAWkj5/md+0Bx3/e /9SxUw5YHvk13XomIgfPvBPJMhv4qr+Ou+4BJ/N9Z8Sn6JZxBCAUAAQcFT5+vrE+7PQR UA4Q7JFGSbVbUgAmuDVLOTm7Qm1w05nAaZ/NzSNGdWvafxi3LkXO1APLZ3Qb3jN4JXHG h6WA== X-Gm-Message-State: APzg51BxxMra+EboljOO0O+5jUNktOsulc2r/9YGHP4yaCL9SI2FCn/h w63U64JtOTJe1ToJmpmpQTiqeMeH0w== X-Google-Smtp-Source: ANB0VdYgWZ5VfYWaGnKLfkPsMkmQJLzGAuQC5FQ4qD+JPJXy209W/KyIRBpY8ob3Rf+BctOyZwDckr/9yw== X-Received: by 2002:a63:4406:: with SMTP id r6-v6mr853725pga.64.1535487288321; Tue, 28 Aug 2018 13:14:48 -0700 (PDT) Date: Tue, 28 Aug 2018 22:14:17 +0200 In-Reply-To: <20180828201421.157735-1-jannh@google.com> Message-Id: <20180828201421.157735-4-jannh@google.com> Mime-Version: 1.0 References: <20180828201421.157735-1-jannh@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH v3 3/7] x86: stop calling fixup_exception() from kprobe_fault_handler() From: Jann Horn To: Kees Cook , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Andy Lutomirski , kernel-hardening@lists.openwall.com, jannh@google.com Cc: linux-kernel@vger.kernel.org, dvyukov@google.com, Masami Hiramatsu , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Alexander Viro , linux-fsdevel@vger.kernel.org, Borislav Petkov Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This removes the call into exception fixup that was added in commit c28f896634f2 ("[PATCH] kprobes: fix broken fault handling for x86_64"). On X86, kprobe_fault_handler() is called from two places: do_general_protection() (for #GP) and kprobes_fault() (for #PF). In both paths, the fixup_exception() call in the kprobe fault handler is redundant. For #GP, fixup_exception() is called immediately before kprobe_fault_handler() is invoked - if someone wanted to fix up our #GP, they've already done so, no need to try again. (This assumes that the kprobe's fault handler isn't going to do something crazy like changing RIP so that it suddenly points to an instruction that does userspace access.) For #PF on a kernel address from kernel space, after the kprobe fault handler has run, we'll go into no_context(), which calls fixup_exception(). Acked-by: Masami Hiramatsu Signed-off-by: Jann Horn --- arch/x86/kernel/kprobes/core.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 467ac22691b0..7315ac202aad 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -1021,13 +1021,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr) if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr)) return 1; - /* - * In case the user-specified fault handler returned - * zero, try to fix up. - */ - if (fixup_exception(regs, trapnr)) - return 1; - /* fixup routine could not handle it. */ }