Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1590929ybt; Thu, 18 Jun 2020 12:17:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZCol2jyInO/y27042LvOziwQS64mbbNiuMc5evuKmIXkRKxuWjnik5+MC0WkcLNu/0taE X-Received: by 2002:a17:906:560b:: with SMTP id f11mr188532ejq.11.1592507872029; Thu, 18 Jun 2020 12:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592507872; cv=none; d=google.com; s=arc-20160816; b=qi0jexAXYILzMVG2M9FNaRasG+Ee4DFnallxxGWNMoOalVITduVRYMJWPrcPHUVlbd HTYGDsHwJmyX5yULUqn2EkBoeWLoGcpql5bsQHqqpNI46p/h447BexKm64Sm5QLiAyMe D1vy8C6sI8/Fwg/h00mcYjVRMmuCFN3F6nMAzBetywnOzVmDlAdkbu4jBdxLU9rU7HtU q/A/Bsp0SjzxIiBR4jRYnLJmiT4/W6T+qR3X14U6wOsGAb3czp2WF/MZDJAd7I9MLNBc hT47MG9ZjsskKSaw06ujL9nEtGxWJlSer3qXi/JuddksQ/QxLTtqM0sCBNhhYHWXW81y qbdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HqWhugkNcuHTkcVoxACwIvltwDirOkNSFlB5IbsYt2c=; b=H4T791h7vdJdeFbWVmTgOwx49XfVi97aHfaKXvoNIDMH1Cx2SCsKV1fX+PiRya0LuU XCQwTx+SxNSU7GcsbC0p/SE4Vm+2LPKstvG0RfWQx4HuXQmP612S6u3soTrRHbtu1pz3 Ugyv5oiwlma4YJGHmRDv9Cufs0VQSwpH/7T3nOHVrlH6G+lBSc4mOqC/V5gOF8r3mMxD QUjw2jsLMYqSgIhGgteWp+EJitZ6XRWbjd7MNH3Hbzk65rPY1zvtZY2ddhWZO39+XIXp AjeehY7wJx+Z/cCI4+wXAxUAxYFMu+bKSdsq9uMUMX14koPMWyD9G8ETg5ixC6AGqRZx uFcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=lkl3brpl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y19si2431932edm.387.2020.06.18.12.17.29; Thu, 18 Jun 2020 12:17:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=lkl3brpl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728157AbgFRTCW (ORCPT + 99 others); Thu, 18 Jun 2020 15:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbgFRTCV (ORCPT ); Thu, 18 Jun 2020 15:02:21 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 531F2C06174E for ; Thu, 18 Jun 2020 12:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=HqWhugkNcuHTkcVoxACwIvltwDirOkNSFlB5IbsYt2c=; b=lkl3brply6htcKMLsnHAmGjKo5 Y43LdJ1K7R4ymOm0L56Mda4Gn8SYEdraTHRwdo3v2N2sEY4leUDGkbs+Pw6o2w+TKA/vfmeM4JQ8D hIuCkuAYbrUV6UUi9I2d1DtE1mXOWRLfR1fPsQEbsdhPcIm3fOejnDsQ7SrN69vabdAiwsnSNlhkg AOeomP04WOCIfB0Os04tkz563nKL3V8d1uyDfc16cf844gOyQPEbBIWwAad7vp9GDSe6Qlx1ypkYN pIGCCC7jg4iE5wLp63xmuy8hX7caqT+Q3tjDdTS50woHrBAdAc57jEq9VU86NOq5jEm42+zF7y0zW yiVUL8lw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlznd-000331-IQ; Thu, 18 Jun 2020 19:02:09 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8EF90301A32; Thu, 18 Jun 2020 21:02:07 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6F66C21288468; Thu, 18 Jun 2020 21:02:07 +0200 (CEST) Date: Thu, 18 Jun 2020 21:02:07 +0200 From: Peter Zijlstra To: Andy Lutomirski Cc: Josh Poimboeuf , LKML , X86 ML , Dmitry Vyukov , Marco Elver , Andrey Konovalov , Mark Rutland , Matthew Helsley , Steven Rostedt , jthierry@redhat.com, Miroslav Benes Subject: Re: [PATCH 1/7] x86/entry: Fix #UD vs WARN more Message-ID: <20200618190207.GO576905@hirez.programming.kicks-ass.net> References: <20200618144801.642309720@infradead.org> <70455B9B-0952-4E03-B2CE-EEAE1E110C5B@amacapital.net> <20200618155017.GK576905@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 18, 2020 at 11:36:53AM -0700, Andy Lutomirski wrote: > I wasn't imagining going far down the rabbit hole at all -- I think > that, at most, we should cover the path for when the fault wasn't a > BUG/WARN in the first place. I admit that, for #UD in particular, > this isn't a big deal, but if it were a different vector, this could > matter. Right, so there's 3 cases for ud2: - WARN; ud2, bug_entry, recovers - BUG; ud2, bug_entry, dies - UBSAN; ud2, !bug_entry, dies Nothing else should be generating ud2 instructions, any other #UD goes into handle_invalid_op() -> do_error_trap() -> ... -> die(). [ while there, we should probably restructure do_trap() to have cond_local_irq_enable() _after_ do_trap_no_signal(). ] We could probably change is_valid_bugaddr() to not use probe_kernel_address(), because if it couldn't read the instruction, we'd not be getting #UD in the first place. If we've gotten rid of probe_kernel_address() we can noinstr/inline that and then we can only call into report_bug() IFF ud2. Does that make things 'better' ? This can only go realy bad if there's a 1 byte instruction that triggers #UD, but I think that was ruled out. --- diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index c26751e303f1..275a621f1aff 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -91,10 +91,7 @@ int is_valid_bugaddr(unsigned long addr) if (addr < TASK_SIZE_MAX) return 0; - if (probe_kernel_address((unsigned short *)addr, ud)) - return 0; - - return ud == INSN_UD0 || ud == INSN_UD2; + return *(unsigned short *)addr == INSN_UD2; } static nokprobe_inline int @@ -220,15 +217,17 @@ static noinstr bool handle_bug(struct pt_regs *regs) { bool handled = false; - /* - * All lies, just get the WARN/BUG out. - */ - instrumentation_begin(); - if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) { - regs->ip += LEN_UD2; - handled = true; + if (is_valid_bugaddr(regs->ip)) { + /* + * All lies, just get the WARN/BUG out. + */ + instrumentation_begin(); + if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) { + regs->ip += LEN_UD2; + handled = true; + } + instrumentation_end(); } - instrumentation_end(); return handled; }