Received: by 10.213.65.68 with SMTP id h4csp900296imn; Tue, 27 Mar 2018 10:50:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/m2vWFcz5ksUKvtBLJR7YrSTl1OOzFAUHyoD7u/lGZhLDOMLi8BlfQq/I02cIsN6/wvsjC X-Received: by 2002:a17:902:6b85:: with SMTP id p5-v6mr308543plk.66.1522173029928; Tue, 27 Mar 2018 10:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522173029; cv=none; d=google.com; s=arc-20160816; b=lnuwN0C5fV8H2O14uNQMnKKyUcHQI3/tRrKQ5lyncPdA88xagmu63LebdBXM7jThDU i7cONTfsdfNyKUq2nkFjFVf2j5m2RjaeB/QV9nWoPTas+Ofx5ZBxI0bMuc+jGIl1GJol AENL6FizQSYlJEQUi+Y+o6eqVTWahfeDBp8L13d2JtU1ghL7+deKvaunKCJ2oeBGNQOR 3vc8jnwUC117uO6Jouy0ModIhsfmaKvivb1TPZ4OhbyRC7PZFAZ+otpRJ8bHfvyE5tMt m3fX+ioXQKRIWhTm0ZRhbvO09AjD6yApbayRxcHZdI78ORlpMR7+CGUFOzuXhb3We5xy C1VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=CvYXXS37PYL8I1FVpLSKIgElGYcM+C80aNBehCp43iM=; b=o4Zyx5p8aIyrmxIal5PZnWN2DIfH/L2yAzSzP5CdsU5TlZnWajo7/Vr8jYn961YoPh avaKmLXROfbsDELLkiNxa95RRX6nwsQ4PAKyvE+kk5U8c6KNpblSf3McA8lRgZMpDLPv nDdSmU98VrJ8yTchCIt5Xspbo6mqhyQtK1SMvlcqIlZXMT4LuAfClKLHzTTh/deuOAJi 4m+mbKoYRYHgES/MpO+E8uF9t/3E6smgI1KvWGknwj1bXznOlXeaCF5pjo+MB0IiXaSu o+8YhdMqYs8jznF68ssFWAS28CltA1KKdil7eUp39ddAHWx6stwby9mJdDWAA0aJ2EwM J+3A== ARC-Authentication-Results: i=1; mx.google.com; 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 85si1223198pfz.271.2018.03.27.10.50.15; Tue, 27 Mar 2018 10:50:29 -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; 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 S1753759AbeC0Qco (ORCPT + 99 others); Tue, 27 Mar 2018 12:32:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43504 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753695AbeC0Qcn (ORCPT ); Tue, 27 Mar 2018 12:32:43 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 95C1F10B0; Tue, 27 Mar 2018 16:32:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Linus Torvalds , Thomas Gleixner Subject: [PATCH 4.9 53/67] x86/entry/64: Dont use IST entry for #BP stack Date: Tue, 27 Mar 2018 18:27:45 +0200 Message-Id: <20180327162730.431033236@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162726.702411083@linuxfoundation.org> References: <20180327162726.702411083@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit d8ba61ba58c88d5207c1ba2f7d9a2280e7d03be9 upstream. There's nothing IST-worthy about #BP/int3. We don't allow kprobes in the small handful of places in the kernel that run at CPL0 with an invalid stack, and 32-bit kernels have used normal interrupt gates for #BP forever. Furthermore, we don't allow kprobes in places that have usergs while in kernel mode, so "paranoid" is also unnecessary. Signed-off-by: Andy Lutomirski Signed-off-by: Linus Torvalds Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_64.S | 2 +- arch/x86/kernel/traps.c | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -943,7 +943,7 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTO #endif /* CONFIG_HYPERV */ idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK -idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK +idtentry int3 do_int3 has_error_code=0 idtentry stack_segment do_stack_segment has_error_code=1 #ifdef CONFIG_XEN --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -526,7 +526,6 @@ do_general_protection(struct pt_regs *re } NOKPROBE_SYMBOL(do_general_protection); -/* May run on IST stack. */ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code) { #ifdef CONFIG_DYNAMIC_FTRACE @@ -541,7 +540,15 @@ dotraplinkage void notrace do_int3(struc if (poke_int3_handler(regs)) return; + /* + * Use ist_enter despite the fact that we don't use an IST stack. + * We can be called from a kprobe in non-CONTEXT_KERNEL kernel + * mode or even during context tracking state changes. + * + * This means that we can't schedule. That's okay. + */ ist_enter(regs); + RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP, @@ -558,17 +565,11 @@ dotraplinkage void notrace do_int3(struc SIGTRAP) == NOTIFY_STOP) goto exit; - /* - * Let others (NMI) know that the debug stack is in use - * as we may switch to the interrupt stack. - */ - debug_stack_usage_inc(); preempt_disable(); cond_local_irq_enable(regs); do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL); cond_local_irq_disable(regs); preempt_enable_no_resched(); - debug_stack_usage_dec(); exit: ist_exit(regs); } @@ -989,19 +990,16 @@ void __init trap_init(void) cpu_init(); /* - * X86_TRAP_DB and X86_TRAP_BP have been set - * in early_trap_init(). However, ITS works only after - * cpu_init() loads TSS. See comments in early_trap_init(). + * X86_TRAP_DB was installed in early_trap_init(). However, + * IST works only after cpu_init() loads TSS. See comments + * in early_trap_init(). */ set_intr_gate_ist(X86_TRAP_DB, &debug, DEBUG_STACK); - /* int3 can be called from all */ - set_system_intr_gate_ist(X86_TRAP_BP, &int3, DEBUG_STACK); x86_init.irqs.trap_init(); #ifdef CONFIG_X86_64 memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16); set_nmi_gate(X86_TRAP_DB, &debug); - set_nmi_gate(X86_TRAP_BP, &int3); #endif }