Received: by 10.223.176.46 with SMTP id f43csp626729wra; Thu, 18 Jan 2018 23:07:07 -0800 (PST) X-Google-Smtp-Source: ACJfBosW4msHJBTOTj5ArvcBqvZ4uePa5obj7tfBfzM4zsqLK8XXEmDHVWtVDrOQ+/rLPMpm/gSX X-Received: by 10.101.96.44 with SMTP id p12mr11653799pgu.390.1516345627196; Thu, 18 Jan 2018 23:07:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516345627; cv=none; d=google.com; s=arc-20160816; b=dllWCOCNvVOpWU1rdNqtS3KJ8UtdXLx12sMfdDozMMHwTrgo7r2t+CBbjKn7xy1jt8 O+2BvhcI1O7A5abssCmFJGdY4T08DzB2lvr9bjxV9Y3ablM6APOTNq32zg+H4Owy3wT8 JpDi8OHMT1V566fbr1kcaC5kSGen9DiJuowY92Vo2Xnnu8wrRZ4jvO//8tuzPPrE49Z8 bQBli9RO5X7QJrW93kY1oNrX4oMAyIgSE6+NjBJahWegv/L7EeB2AyS2heoBkXISwKfQ GCAbq42mdVZ1vEiWXXhvyU3SoZFD6TWBRCp4dL/26S/Ennc/HXQphLzZFpWnRPhBwaBL Gn3w== 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 :dmarc-filter:arc-authentication-results; bh=EkCHYAFYGlv+UUgTUQ8MU5fkItE9g8cfNzJ57xmhH44=; b=Cp9sB0v3x3ROOn+/4WjdcLFtg5DMdsTZZ7ghZU73rnNHWHaMwIIBE4nzUDeR9PAj6b QkBbKddWOsQA89h1ZoH6Dgccdaxwkpdd16XuMVxsNR8udqIVk5/TY0Bgyil4yMTunpKQ 0tkMmR2XA5+Ur04Pu5BqwFXu+8gA9IXdM6PUYUyiHDoBQFZtyWQir3qzLPxZnCKJrtyi T+jlBctokTH0RCc5UwG9fhJpSLz4oHgnu+3PK7ONECu71T8Ex0G9cDc7eZtx6rleVGUp 1+Bpp/RRIjR2cs+FgcaD7ufHUIRN8R3k6I/Yv2tDLG1BTs7IZDMUttSkccDSBZ/55d/y HJCw== 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 i2si7865292pgt.354.2018.01.18.23.06.52; Thu, 18 Jan 2018 23:07:07 -0800 (PST) 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 S1753618AbeASHGS (ORCPT + 99 others); Fri, 19 Jan 2018 02:06:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:57850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750757AbeASHGM (ORCPT ); Fri, 19 Jan 2018 02:06:12 -0500 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 5234E21717; Fri, 19 Jan 2018 07:06:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5234E21717 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org Date: Fri, 19 Jan 2018 16:06:07 +0900 From: Masami Hiramatsu To: Jessica Yu , Ingo Molnar Cc: mhiramat@kernel.org, Ananth N Mavinakayanahalli , Anil S Keshavamurthy , "David S . Miller" , Ingo Molnar , Petr Mladek , Josh Poimboeuf , Joe Lawrence , Jiri Kosina , Miroslav Benes , Steven Rostedt , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 0/2] kprobes: improve error handling when arming/disarming kprobes Message-Id: <20180119160607.5ed19168be13d27cf7f94531@kernel.org> In-Reply-To: <20180109235124.30886-1-jeyu@kernel.org> References: <20180109235124.30886-1-jeyu@kernel.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-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 Hi Ingo, Could you pick this to tip tree? Thank you, On Wed, 10 Jan 2018 00:51:22 +0100 Jessica Yu wrote: > Hi, > > This patchset attempts to improve error handling when arming or disarming > ftrace-based kprobes. The current behavior is to simply WARN when ftrace > (un-)registration fails, without propagating the error code. This can lead > to confusing situations where, for example, register_kprobe()/enable_kprobe() > would return 0 indicating success even if arming via ftrace had failed. In > this scenario we'd end up with a non-functioning kprobe even though kprobe > registration (or enablement) returned success. In this patchset, we take > errors from ftrace into account and propagate the error when we cannot arm > or disarm a kprobe. > > Below is an example that illustrates the problem using livepatch and > systemtap (which uses kprobes underneath). Both livepatch and kprobes use > ftrace ops with the IPMODIFY flag set, so registration at the same > function entry is limited to only one ftrace user. > > Before > ------ > # modprobe livepatch-sample # patches cmdline_proc_show, ftrace ops has IPMODIFY set > # stap -e 'probe kernel.function("cmdline_proc_show").call { printf ("cmdline_proc_show\n"); }' > > .. (nothing prints after reading /proc/cmdline) .. > > The systemtap handler doesn't execute due to a kprobe arming failure caused > by a ftrace IPMODIFY conflict with livepatch, and there isn't an obvious > indication of error from systemtap (because register_kprobe() returned > success) unless the user inspects dmesg. > > After > ----- > # modprobe livepatch-sample > # stap -e 'probe kernel.function("cmdline_proc_show").call { printf ("cmdline_proc_show\n"); }' > WARNING: probe kernel.function("cmdline_proc_show@/home/jeyu/work/linux-next/fs/proc/cmdline.c:6").call (address 0xffffffffa82fe910) registration error (rc -16) > > Although the systemtap handler doesn't execute (as it shouldn't), the > ftrace error is propagated and now systemtap prints a visible error message > stating that (kprobe) registration had failed (because register_kprobe() > returned an error), along with the propagated error code. > > This patchset was based on Petr Mladek's original patchset (patches 2 and 3) > back in 2015, which improved kprobes error handling, found here: > > https://lkml.org/lkml/2015/2/26/452 > > However, further work on this had been paused since then and the patches > were not upstreamed. > > This patchset has been lightly sanity-tested (on linux-next) with kprobes, > kretprobes, and optimized kprobes. It passes the kprobes smoke test, but > more testing is greatly appreciated. > > Changes from v4: > - Switch from WARN() to pr_debug() in arm_kprobe_ftrace() so the stack > dumps don't pollute dmesg, as IPMODIFY conflicts can occur in normal usage > - Added Masami's ack to the first patch > > Changes from v3: > - Have (dis)arm_kprobe_ftrace() return -ENODEV instead of 0 in case of > !CONFIG_KPROBES_ON_FTRACE > - Add total count of all probes tried in (dis)arm_all_kprobes() > > Changes from v2: > - Add missing synchronize rcu in register_aggr_kprobe() > - s/kprobes/probes/ on error message in (dis)arm_all_kprobes() > > Changes from v1: > - Don't arm the kprobe before adding it to the kprobe table, otherwise > we'll temporarily see a stray breakpoint. > - Remove kprobe from the kprobe_table and call synchronize_sched() if > arming during register_kprobe() fails. > - add Masami's ack on the 2nd patch (unchanged from v1) > > --- > Jessica Yu (2): > kprobes: propagate error from arm_kprobe_ftrace() > kprobes: propagate error from disarm_kprobe_ftrace() > > kernel/kprobes.c | 178 +++++++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 128 insertions(+), 50 deletions(-) > > -- > 2.13.6 > -- Masami Hiramatsu