Received: by 10.192.165.156 with SMTP id m28csp1512893imm; Wed, 18 Apr 2018 10:49:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx49JjEPPtqZ82VMo3gcu8HNg4qKLg9AfQItEpLBdbQkEM1NTJc/AWBSSzfrk6ARqX3t3MBx0 X-Received: by 10.101.99.68 with SMTP id p4mr2483652pgv.421.1524073790004; Wed, 18 Apr 2018 10:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524073789; cv=none; d=google.com; s=arc-20160816; b=FMMkyL72v2gIfPtEAKvCuoqMH+eDk/+vGFDV/6+F9yHR3esHIpF0EG0a6uirToXlF+ 8pkt6lwAyAQWersL8cgeQ9kuWhnBemKvktBVUWKa4GfS/usWLtM8i3Y0m+7GApdMyYDL 84KwrkMFRm70VTZgOsGG801Z6oJZxfK3uBIUWXI7BAnDSVqeEGpnsimTa7OpJgA0bdA8 ZlF38Fk/zKuGhol/BAeBoqv/NzZ4l6hfKI8pp9o0bk3uTrXMEEXkIHqh8jrLLYh9Jpcp sYHqu6qi6WMOoIpWkmc/+Lfrqb5o2B/wlzqgT8k5bg5ynGcyix3cZ5TJqacH1AARRFWb aXQQ== 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=CAO5+J0z4WUhhMENTjEg9D40yg/XidwQyvefSy2C9Iw=; b=ypIgIXNSFb83s6FE3HucHd7W+YAPJkIg3yZ+M/ebtZdSrSzIJ/+YgQs081pbqVn07L Xa5dfxWQhOMjVUuG8ot6Qn2NVXHY3p7zquzjBCAIL+Ced1E9zgKTCMGKQMWjLLGmC2h0 aeI2Es6tGtBWNkbi23PdIxglz3+woelNjEhgqXEMAWVRg0DlY6lT8dr7PLSCXIGkIcuY 3DOvWhsAmmNihnqRmRg8+qbWRvo1FhbWhu6Q5d2ZZBGxOxz90RbSKUCz9bnM2SAAIiyL 22v0o0LwbNyLUhvbdtbidClR96r/mus/EMTI4okkSU9lf3awrv8pE2276ApO3inzgPg5 xIzg== 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 n5si1514570pfi.360.2018.04.18.10.49.36; Wed, 18 Apr 2018 10:49:49 -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 S1752966AbeDRRsA (ORCPT + 99 others); Wed, 18 Apr 2018 13:48:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:52780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750885AbeDRRr7 (ORCPT ); Wed, 18 Apr 2018 13:47:59 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (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 F375F21727; Wed, 18 Apr 2018 17:47:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F375F21727 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=rostedt@goodmis.org Date: Wed, 18 Apr 2018 13:47:56 -0400 From: Steven Rostedt To: Song Liu Cc: , , Ingo Molnar , Howard McLauchlan , Josef Bacik , Srikar Dronamraju , Miklos Szeredi Subject: Re: [PATCH v2] tracing: fix bad use of igrab in trace_uprobe.c Message-ID: <20180418134756.482c899f@gandalf.local.home> In-Reply-To: <20180418174014.1592871-1-songliubraving@fb.com> References: <20180418174014.1592871-1-songliubraving@fb.com> X-Mailer: Claws Mail 3.16.0 (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 You forgot to add Miklos again. Miklos, have any comments on this patch? Or can you give a "Reviewed-by"? -- Steve On Wed, 18 Apr 2018 10:40:14 -0700 Song Liu wrote: > As Miklos reported and suggested: > > This pattern repeats two times in trace_uprobe.c and in > kernel/events/core.c as well: > > ret = kern_path(filename, LOOKUP_FOLLOW, &path); > if (ret) > goto fail_address_parse; > > inode = igrab(d_inode(path.dentry)); > path_put(&path); > > And it's wrong. You can only hold a reference to the inode if you > have an active ref to the superblock as well (which is normally > through path.mnt) or holding s_umount. > > This way unmounting the containing filesystem while the tracepoint is > active will give you the "VFS: Busy inodes after unmount..." message > and a crash when the inode is finally put. > > Solution: store path instead of inode. > > This patch fixes two instances in trace_uprobe.c. > > Fixes: f3f096cfedf8 ("tracing: Provide trace events interface for uprobes") > Fixes: 33ea4b24277b ("perf/core: Implement the 'perf_uprobe' PMU") > Cc: Steven Rostedt > Cc: Ingo Molnar > Cc: Howard McLauchlan > Cc: Josef Bacik > Cc: Srikar Dronamraju > Reported-by: Miklos Szeredi > Signed-off-by: Song Liu > --- > kernel/trace/trace_uprobe.c | 49 +++++++++++++++------------------------------ > 1 file changed, 16 insertions(+), 33 deletions(-) > > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c > index 34fd0e0..d9ee522c 100644 > --- a/kernel/trace/trace_uprobe.c > +++ b/kernel/trace/trace_uprobe.c > @@ -55,7 +55,7 @@ struct trace_uprobe { > struct list_head list; > struct trace_uprobe_filter filter; > struct uprobe_consumer consumer; > - struct inode *inode; > + struct path path; > char *filename; > unsigned long offset; > unsigned long nhit; > @@ -289,7 +289,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu) > for (i = 0; i < tu->tp.nr_args; i++) > traceprobe_free_probe_arg(&tu->tp.args[i]); > > - iput(tu->inode); > + path_put(&tu->path); > kfree(tu->tp.call.class->system); > kfree(tu->tp.call.name); > kfree(tu->filename); > @@ -363,7 +363,6 @@ static int register_trace_uprobe(struct trace_uprobe *tu) > static int create_trace_uprobe(int argc, char **argv) > { > struct trace_uprobe *tu; > - struct inode *inode; > char *arg, *event, *group, *filename; > char buf[MAX_EVENT_NAME_LEN]; > struct path path; > @@ -371,7 +370,6 @@ static int create_trace_uprobe(int argc, char **argv) > bool is_delete, is_return; > int i, ret; > > - inode = NULL; > ret = 0; > is_delete = false; > is_return = false; > @@ -437,24 +435,14 @@ static int create_trace_uprobe(int argc, char **argv) > } > /* Find the last occurrence, in case the path contains ':' too. */ > arg = strrchr(argv[1], ':'); > - if (!arg) { > - ret = -EINVAL; > - goto fail_address_parse; > - } > + if (!arg) > + return -EINVAL; > > *arg++ = '\0'; > filename = argv[1]; > ret = kern_path(filename, LOOKUP_FOLLOW, &path); > if (ret) > - goto fail_address_parse; > - > - inode = igrab(d_real_inode(path.dentry)); > - path_put(&path); > - > - if (!inode || !S_ISREG(inode->i_mode)) { > - ret = -EINVAL; > - goto fail_address_parse; > - } > + return ret; > > ret = kstrtoul(arg, 0, &offset); > if (ret) > @@ -490,7 +478,7 @@ static int create_trace_uprobe(int argc, char **argv) > goto fail_address_parse; > } > tu->offset = offset; > - tu->inode = inode; > + tu->path = path; > tu->filename = kstrdup(filename, GFP_KERNEL); > > if (!tu->filename) { > @@ -558,7 +546,7 @@ static int create_trace_uprobe(int argc, char **argv) > return ret; > > fail_address_parse: > - iput(inode); > + path_put(&path); > > pr_info("Failed to parse address or file.\n"); > > @@ -922,7 +910,8 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file, > goto err_flags; > > tu->consumer.filter = filter; > - ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); > + ret = uprobe_register(d_inode(tu->path.dentry), tu->offset, > + &tu->consumer); > if (ret) > goto err_buffer; > > @@ -966,7 +955,7 @@ probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file) > > WARN_ON(!uprobe_filter_is_empty(&tu->filter)); > > - uprobe_unregister(tu->inode, tu->offset, &tu->consumer); > + uprobe_unregister(d_inode(tu->path.dentry), tu->offset, &tu->consumer); > tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE; > > uprobe_buffer_disable(); > @@ -1041,7 +1030,8 @@ static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event) > write_unlock(&tu->filter.rwlock); > > if (!done) > - return uprobe_apply(tu->inode, tu->offset, &tu->consumer, false); > + return uprobe_apply(d_inode(tu->path.dentry), tu->offset, > + &tu->consumer, false); > > return 0; > } > @@ -1073,7 +1063,8 @@ static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event) > > err = 0; > if (!done) { > - err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true); > + err = uprobe_apply(d_inode(tu->path.dentry), > + tu->offset, &tu->consumer, true); > if (err) > uprobe_perf_close(tu, event); > } > @@ -1337,7 +1328,6 @@ struct trace_event_call * > create_local_trace_uprobe(char *name, unsigned long offs, bool is_return) > { > struct trace_uprobe *tu; > - struct inode *inode; > struct path path; > int ret; > > @@ -1345,14 +1335,6 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return) > if (ret) > return ERR_PTR(ret); > > - inode = igrab(d_inode(path.dentry)); > - path_put(&path); > - > - if (!inode || !S_ISREG(inode->i_mode)) { > - iput(inode); > - return ERR_PTR(-EINVAL); > - } > - > /* > * local trace_kprobes are not added to probe_list, so they are never > * searched in find_trace_kprobe(). Therefore, there is no concern of > @@ -1364,11 +1346,12 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return) > if (IS_ERR(tu)) { > pr_info("Failed to allocate trace_uprobe.(%d)\n", > (int)PTR_ERR(tu)); > + path_put(&path); > return ERR_CAST(tu); > } > > tu->offset = offs; > - tu->inode = inode; > + tu->path = path; > tu->filename = kstrdup(name, GFP_KERNEL); > init_trace_event_call(tu, &tu->tp.call); >