Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp592617ybh; Tue, 10 Mar 2020 04:45:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsX5c1troCpAXn2sop5wFQcne/XFmA7He1OkRCXWFYUCXkQ7H+edCihoYUhIDfVpcdJBjly X-Received: by 2002:a05:6830:104a:: with SMTP id b10mr16836675otp.63.1583840759026; Tue, 10 Mar 2020 04:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583840759; cv=none; d=google.com; s=arc-20160816; b=AasnTbddiZ+rv1zzN8AILpfydxoXzp/UCVfSHjZX5C7iXNv7YWMz5YMXb7dkIhX4TK X4gt2NtAgyGAIdEL7fCsVofRK1uqjKYXveQqIuh5LIV/Ctt0DqUVAR23eHP8KRJGP82E OkRuJp9h9X7Jscg907Vjp4Mg64hRAFw5kbecFN5g6XYIzMTUYu2B7w41Rzn6EFcBnK44 rGY1YnIZ/JTQ68yn0bXuciSI6pRcherCrHMeP3rmrcPISrEuOA4mS8bksYBXkGf2CRGL fFdKpbaud2dGZC1NQ8epNDU5L9f1jKJpIbj2V25bW8lm7t42kZOVVLqDivGMx1W9QXfr IamQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=91Vnow5Hgg9xXzTjYyIx2cYoXjzSbM2199h9BBfNcIw=; b=H7yBLoCf53qLhKF6UoVwK2aETlYYaUKHOISR0ry0K1Xylbq0jE9tEpK5w07ngn4016 ffakMA7nxMIRO8CEBHSS2UbKo9jxaeZfzeLPd7aUvkhXPjuvLgwdbTRRzcKdQlXoPnjt KyaBkZmhPhXspxRwYNl9MdncLRtU2i1ZIbaJyT4F5f0BBxNlWM5Ml3HEvXCNNLscHi6K KJ0AgSSpyBTOB0XlNncG5S0FLLgnqqLkKtCBxkaanu/WDvWX8KwuawO9H7C39pKlEEot PuezudQ2afThZu/P/joFZYSAZR1ZvV0tq8wSJr3p9Dik8A+HMvDKaPleiDDTIifFF2+X ZMbQ== 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 j68si7824418otj.56.2020.03.10.04.45.46; Tue, 10 Mar 2020 04:45:59 -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 S1726444AbgCJLnm (ORCPT + 99 others); Tue, 10 Mar 2020 07:43:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:33437 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbgCJLnm (ORCPT ); Tue, 10 Mar 2020 07:43:42 -0400 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jBdIF-0005q3-On; Tue, 10 Mar 2020 12:43:27 +0100 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 4AAF51040A5; Tue, 10 Mar 2020 12:43:27 +0100 (CET) From: Thomas Gleixner To: Masami Hiramatsu Cc: Steven Rostedt , LKML , Peter Zijlstra , Masami Hiramatsu , Alexei Starovoitov , Mathieu Desnoyers , "Paul E. McKenney" , Joel Fernandes , Frederic Weisbecker , Jason Wessel Subject: Re: Instrumentation and RCU In-Reply-To: <20200310170951.87c29e9c1cfbddd93ccd92b3@kernel.org> References: <87mu8p797b.fsf@nanos.tec.linutronix.de> <20200309141546.5b574908@gandalf.local.home> <87fteh73sp.fsf@nanos.tec.linutronix.de> <20200310170951.87c29e9c1cfbddd93ccd92b3@kernel.org> Date: Tue, 10 Mar 2020 12:43:27 +0100 Message-ID: <87pndk5tb4.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Masami, Masami Hiramatsu writes: > On Mon, 09 Mar 2020 19:59:18 +0100 > Thomas Gleixner wrote: > >> >> #2) Breakpoint utilization >> >> >> >> As recent findings have shown, breakpoint utilization needs to be >> >> extremly careful about not creating infinite breakpoint recursions. >> >> >> >> I think that's pretty much obvious, but falls into the overall >> >> question of how to protect callchains. >> > >> > This is rather unique, and I agree that its best to at least get to a point >> > where we limit the tracing within breakpoint code. I'm fine with making >> > rcu_nmi_exit() nokprobe too. >> >> Yes, the break point stuff is unique, but it has nicely demonstrated how >> much of the code is affected by it. > > I see. I had followed the callchain several times, and always found new function. > So I agree with the off-limit section idea. That is a kind of entry code section > but more generic one. It is natural to split such sensitive code in different > place. > > BTW, what about kdb stuffs? (+Cc Jason) That's yet another area of wreckage which nobody every looked at. >> >> #4 Protecting call chains >> >> >> >> Our current approach of annotating functions with notrace/noprobe is >> >> pretty much broken. >> >> >> >> Functions which are marked NOPROBE or notrace call out into functions >> >> which are not marked and while this might be ok, there are enough >> >> places where it is not. But we have no way to verify that. > > Agreed. That's the reason why I haven't add kprobe-fuzzer yet. > It is easy to make a fuzzer for kprobes by ftrace (note that we need > to enable CONFIG_KPROBE_EVENTS_ON_NOTRACE=y to check notrace functions), > but there is no way to kick the target code. In the result, most of the > kprobed functions are just not hit. I'm not sure such test code is > reasonable or not. Well, test code is always reasonable, but you have to be aware that code coverage is a really hard to solve problem with a code base as complex as the kernel. >> which is also in section "text" then the analysis tool will find the >> missing offlimit_safecall() - or what ever method we chose to annotate >> that stuff. Surely not an annotation on the called function itself >> because that might be safe to call in one context but not in another. > > Hmm, what the offlimit_safecall() does? and what happen if the > do_fragile_stuff_on_enter() invokes a library code? I think we also need > to tweak kbuild to duplicate some library code to the off-limit text > area. That's why we want the sections and the annotation. If something calls out of a noinstr section into a regular text section and the call is not annotated at the call site, then objtool can complain and tell you. What Peter and I came up with looks like this: noinstr foo() do_protected(); <- Safe because in the noinstr section instr_begin(); <- Marks the begin of a safe region, ignored by objtool do_stuff(); <- All good instr_end(); <- End of the safe region. objtool starts looking again do_other_stuff(); <- Unsafe because do_other_stuff() is not protected and: noinstr do_protected() bar(); <- objtool will complain here See? >> These annotations are halfways easy to monitor for abuse and they should >> be prominent enough in the code that at least for the people dealing >> with that kind of code they act as a warning flag. > > This off-limit text will be good for entries, but I think we still not > able to remove all NOKPROBE_SYMBOLS with this. > > For example __die() is marked a NOKPROBE because if we hit a recursive > int3, it calls BUG() to dump stacks etc for debug. So that function > must NOT probed. (I think we also should mark all backtrace functions > in this case, but not yet) Would we move those backtrace related > functions (including printk, and console drivers?) into the offlimit > text too? That's something we need to figure out and decide on. Some of this stuff sureley wants to be in the noinstr section. Other things might end up still being explicitely annotated, but that should be the exception not the rule. > Hmm, if there is a bust_kprobes(), that can be easy to fix this issue. That might help, but is obviously racy as hell. Thanks, tglx