Received: by 10.192.165.156 with SMTP id m28csp888834imm; Tue, 17 Apr 2018 23:30:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+63qXBv8tIwMNZvXRldakfrtf9C/I1uPWrEoftteuypxSzAN+ZxFl22HXJAoiuxtEc85Eu X-Received: by 2002:a17:902:a70c:: with SMTP id w12-v6mr897281plq.74.1524033053218; Tue, 17 Apr 2018 23:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524033053; cv=none; d=google.com; s=arc-20160816; b=wA4K8ojHEcQAVR901RRXQeAMmH3v8lTuu8ks7A9cf7BRENDQEObtTI9aKFPnmjHdmO D9I/WuD5pm935nBCcrTMWES9+m9KW36+l0F2uIC48WhvgdG36ZDIIDgCUFGA9Q3MlD0G 7XiBEvslxuaG8OQh18Mwitl4+GgpQgnhr+JeJBXjdYdIAIUro+2HFQarp2RnN3nf6BUr 1IVq0zLFkK4/IKz7XjP/6ijDKkL/b+gDK/jMvEvV4kvSPbMiGNm0W2c8n0LL8UjYMnW2 bsiyFNP5CGXlG/5ho8c/NLq25XdmnF1WWjH9pvMJyL0hob6ThIdGhO6vDd7sU+XLuj7u DRRA== 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:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature:arc-authentication-results; bh=WUZ7vc6doPXr8iueI37F3nX68oq3C1K5DTDYZqNBu7s=; b=iIge63LwFtfN+BSpIMDIY9oyts2yTDhYI5Uy8I7oXHvLw1h4GFjATQLTu6wjWFTPAC MYb0OzgcaAi96WOH+SQZQFlhTQk7eNYHm6ZELDvb3CNIPGsXUxs7cP95xSeaRlLXbjzO T5AC7TvhianfXQ2I4pc5bKU6niIt0/orFZN/nFomnqHf0NgHIfxLAn3Cwk4hgRrlxo1b mPI6/dQEugDz7WYy3v/3izy72FqkTWtUohGsSQShSC643xo7dVafffBktW1DeK0C5BH3 XE+CIh1BxohhO8cLok5s9cvxzQsyd7ybe/SI3MPuqPGVQYmBp3o51WhwUI00KDSQEoyo dXlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=iixTX5a8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si537000pgs.193.2018.04.17.23.30.37; Tue, 17 Apr 2018 23:30:53 -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; dkim=pass header.i=@fb.com header.s=facebook header.b=iixTX5a8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145AbeDRG33 (ORCPT + 99 others); Wed, 18 Apr 2018 02:29:29 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:40016 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751305AbeDRG32 (ORCPT ); Wed, 18 Apr 2018 02:29:28 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3I6SL1e006201 for ; Tue, 17 Apr 2018 23:29:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=WUZ7vc6doPXr8iueI37F3nX68oq3C1K5DTDYZqNBu7s=; b=iixTX5a8hD3pWB3HswXgbMpuL2CwI6c+3LvDcDF0Byltvsk7xucPoj6YDgIqdYG1mqS+ EBm1gu9u7F3uJmaDg7MsFBthpTKxweBfKC/RWEWeOReT3pb1+9csdyEz+H60JTubGSKD NCtS3dPbbRBJuhJAAWGO/EAVjdu9obCdTJc= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2hdxp0r6r5-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 17 Apr 2018 23:29:28 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB04.TheFacebook.com (192.168.16.14) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 17 Apr 2018 23:29:27 -0700 Received: by devbig102.frc2.facebook.com (Postfix, from userid 4523) id D2DB84282898; Tue, 17 Apr 2018 23:29:26 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig102.frc2.facebook.com To: CC: , Song Liu , Steven Rostedt , Ingo Molnar , Howard McLauchlan , Josef Bacik , Srikar Dronamraju Smtp-Origin-Cluster: frc2c02 Subject: [PATCH 1/2] tracing: fix bad use of igrab in trace_uprobe.c Date: Tue, 17 Apr 2018 23:29:06 -0700 Message-ID: <20180418062907.3210386-1-songliubraving@fb.com> X-Mailer: git-send-email 2.9.5 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-18_02:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 0d450b4..80dfcdf 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; @@ -448,14 +446,6 @@ static int create_trace_uprobe(int argc, char **argv) if (ret) goto fail_address_parse; - inode = igrab(d_inode(path.dentry)); - path_put(&path); - - if (!inode || !S_ISREG(inode->i_mode)) { - ret = -EINVAL; - goto fail_address_parse; - } - ret = kstrtoul(arg, 0, &offset); if (ret) goto fail_address_parse; @@ -490,7 +480,8 @@ static int create_trace_uprobe(int argc, char **argv) goto fail_address_parse; } tu->offset = offset; - tu->inode = inode; + tu->path.mnt = path.mnt; + tu->path.dentry = path.dentry; tu->filename = kstrdup(filename, GFP_KERNEL); if (!tu->filename) { @@ -558,7 +549,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"); @@ -937,7 +928,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; @@ -981,7 +973,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(); @@ -1056,7 +1048,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; } @@ -1088,7 +1081,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); } @@ -1352,7 +1346,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; @@ -1360,14 +1353,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 @@ -1383,7 +1368,8 @@ create_local_trace_uprobe(char *name, unsigned long offs, bool is_return) } tu->offset = offs; - tu->inode = inode; + tu->path.mnt = path.mnt; + tu->path.dentry = path.dentry; tu->filename = kstrdup(name, GFP_KERNEL); init_trace_event_call(tu, &tu->tp.call); -- 2.9.5