Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp630114ybe; Wed, 4 Sep 2019 05:30:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvr9HalBGTF8rtzOQp1AFkJtmo8gA/2US4461H6wg5NxmrRKI2HVe48j63vsAe9GegMGs5 X-Received: by 2002:a17:902:7c14:: with SMTP id x20mr25880966pll.289.1567600224571; Wed, 04 Sep 2019 05:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567600224; cv=none; d=google.com; s=arc-20160816; b=odCR6HKr+9tbIyFFEP+XllagHac485vB31ziBA3Por4KZt/Rcm1ROJqDJZTcXEZfqX sZPf2KBEb+4uLYpdXlwbsQbT18pF/1RSJqYYogZrsjyJjDPdIHrxEenf/qyGHczrvkHg YEsAUYC14zIzMFaQnOyadjHOnJkUzmroi60SlV18xKif5PTikG8rcqMHAnQzjSXHj+HN VTro6ml0AqBwd9qUzaaK1soWtQFFbmWCB6AUdKegK6Nhu5SFZDq6RYEsfb6c6ohzVJIm wpZnSGfgu5pNukZ6rMHlPS7xHFLuCYQ5C66Z1NFlsoaOcGallEFWtST6ouCvymrfUnAP 1TWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=SOrUTSskENnaqQD5ONa3uevn/3DxFryW2NW/AbaS7sQ=; b=LsKxBYfg2f8ExyoW8Hhbs6XrgaaY5u1N4AjZbAYF6avQAB/z9itzdGEqGjtBt0km6v nV+nAEXWx862mX8IDiI6+nOrBB0dPvIequBJ64FgjOqatyjoXys52LPsDLtEJGCZkMhu mjwKc0JJ+GHIX7UHw30rMws6v69qVDRD+z7dWTj3TikiDnjwcFwiiEeSzsRORBQ7PMhG gkVCeYPkvRgB0GvOMHSY9xKluWn/0xkU3vQ6h7zitMKsmXjfxIxcAD4wezSbKJ3WUzR6 GnV5xmYsP8FKyNM4fPBWUehbvreKwQ3ELO8OB2EDKxWW/x+TUQhbDKn4GJYBGldfg/rx FEbA== 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 s12si17680753plp.290.2019.09.04.05.30.08; Wed, 04 Sep 2019 05:30:24 -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 S1729881AbfIDM3N (ORCPT + 99 others); Wed, 4 Sep 2019 08:29:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:52452 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726495AbfIDM3N (ORCPT ); Wed, 4 Sep 2019 08:29:13 -0400 Received: from oasis.local.home (bl11-233-114.dsl.telepac.pt [85.244.233.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9269222DBF; Wed, 4 Sep 2019 12:29:10 +0000 (UTC) Date: Wed, 4 Sep 2019 08:29:03 -0400 From: Steven Rostedt To: Masami Hiramatsu Cc: Ingo Molnar , "Naveen N . Rao" , Anil S Keshavamurthy , "David S . Miller" , linux-kernel@vger.kernel.org Subject: Re: [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address Message-ID: <20190904082903.0ae0656a@oasis.local.home> In-Reply-To: <156750890133.19112.3393666300746167111.stgit@devnote2> References: <156750890133.19112.3393666300746167111.stgit@devnote2> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 3 Sep 2019 20:08:21 +0900 Masami Hiramatsu wrote: > Since BUG() and WARN() may use a trap (e.g. UD2 on x86) to > get the address where the BUG() has occurred, kprobes can not > do single-step out-of-line that instruction. So prohibit > probing on such address. > > Without this fix, if someone put a kprobe on WARN(), the > kernel will crash with invalid opcode error instead of > outputing warning message, because kernel can not find > correct bug address. > > Signed-off-by: Masami Hiramatsu Acked-by: Steven Rostedt (VMware) -- Steve > --- > Changes in v2: > - Add find_bug() stub function for !CONFIG_GENERIC_BUG > - Cast the p->addr to unsigned long. > --- > include/linux/bug.h | 5 +++++ > kernel/kprobes.c | 3 ++- > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/include/linux/bug.h b/include/linux/bug.h > index fe5916550da8..f639bd0122f3 100644 > --- a/include/linux/bug.h > +++ b/include/linux/bug.h > @@ -47,6 +47,11 @@ void generic_bug_clear_once(void); > > #else /* !CONFIG_GENERIC_BUG */ > > +static inline void *find_bug(unsigned long bugaddr) > +{ > + return NULL; > +} > + > static inline enum bug_trap_type report_bug(unsigned long bug_addr, > struct pt_regs *regs) > { > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 452151e79535..5bdf47190f09 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1514,7 +1514,8 @@ static int check_kprobe_address_safe(struct kprobe *p, > /* Ensure it is not in reserved area nor out of text */ > if (!kernel_text_address((unsigned long) p->addr) || > within_kprobe_blacklist((unsigned long) p->addr) || > - jump_label_text_reserved(p->addr, p->addr)) { > + jump_label_text_reserved(p->addr, p->addr) || > + find_bug((unsigned long) p->addr)) { > ret = -EINVAL; > goto out; > }