Received: by 10.192.165.148 with SMTP id m20csp3676221imm; Mon, 23 Apr 2018 10:23:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx498DsVgMZMQ5ALsL1ag7nvrpvW1b71Q9yh5qT3/LM8F5Njh9Vdn1S23KcZLy6dfKL2ilJyb X-Received: by 10.98.76.202 with SMTP id e71mr15543824pfj.171.1524504198878; Mon, 23 Apr 2018 10:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524504198; cv=none; d=google.com; s=arc-20160816; b=MR9AGZsiqR6m0yaQ56a0qQzVVXQ3+vyMj1dZCcsCaF9Jwnub2U5451ZNDxK+3JwKv2 0yytyu5UdzrKMG1rpp1yBLKZl92GJl3eI6DQPEpv0NW/qHqTOkr9TBKLqeb8pGrz16PI m4Y61NVlbHsrkl/Vz7UozxkhpulzH2/G1c4idqapxTCA7nmQdc/p6i+PKn6AFp6ByjMx c4R6xE2ly+lnSIEDAzTMeNYguHP36s8o/zPtfHFuYyHvMQCzjq1Dkfaz+tk2trePirGP XmaAwr6QDPcWpuYnsrt+qhHQNHRAI8l/MXM91ni/KuYbMf+Gn6L7s6ZFuA5/W4TJR8Bo F6Jg== 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=7dPKtPjwdKtT37ymG0S7wTFgSaKka6wuD5QhWYbSuJA=; b=1AEepu0TISBRssOppTEIBeiyI25odZIAP3IZCrCDq0+Q0FOYK0l0O4nFkvN1HC1ayY Q1dASW3gLiqrUgZy2FXiLnEofFHnMETktsDW+Yuich0HXMtR79ljkyin6FsiqfjQfm7v a7wPkC4hBDMG3Lglue3tmON+LF894myjKiSHOUko9y21C2gMIgaQ8Xc3j++L5EeDHy7o aRI9BrCIY+OowlWQDr1T7Lg6E1hzJcR0v6AVr3sKRKzCpRzEFys+ZmyuspAJNlHyE55Y VaisQVKpt7cjgkah6sOTjHdbnqRNljvGW5gePOqoB5IQQ9Mv8YdYZeP3+9zcYZOyxJPd EsgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=GgU8fDzK; 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 o18si11768033pfa.346.2018.04.23.10.23.04; Mon, 23 Apr 2018 10:23:18 -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=GgU8fDzK; 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 S1755752AbeDWRVm (ORCPT + 99 others); Mon, 23 Apr 2018 13:21:42 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:41174 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755460AbeDWRVl (ORCPT ); Mon, 23 Apr 2018 13:21:41 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w3NHCc8F027440 for ; Mon, 23 Apr 2018 10:21:41 -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=7dPKtPjwdKtT37ymG0S7wTFgSaKka6wuD5QhWYbSuJA=; b=GgU8fDzKuDTwI4WXoyiAwWc483bcF4ZaCSzdICAMUlXlWF9sCJ7GeubO4et5SFcuRD7M Kk/RIoW1+zaLS2GaqQjnPRttWiJFFJejQLFQ64xaUMpsesVydQpB7cMebQaNZpgp/vLR r76CNl8KSdfHK4PAHfeNVdFO97kqxuM8jKo= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2hhh9rggum-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 23 Apr 2018 10:21:41 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB10.TheFacebook.com (192.168.16.20) with Microsoft SMTP Server id 14.3.361.1; Mon, 23 Apr 2018 10:21:39 -0700 Received: by devbig102.frc2.facebook.com (Postfix, from userid 4523) id C475D42821F9; Mon, 23 Apr 2018 10:21:38 -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 , Miklos Szeredi Smtp-Origin-Cluster: frc2c02 Subject: [PATCH v5 1/2] tracing: fix bad use of igrab in trace_uprobe.c Date: Mon, 23 Apr 2018 10:21:34 -0700 Message-ID: <20180423172135.4050588-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-23_06:,, 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. struct path is added to struct trace_uprobe to keep the inode and containing mount point referenced. 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 Cc: Miklos Szeredi Reported-by: Miklos Szeredi Signed-off-by: Song Liu --- kernel/trace/trace_uprobe.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 34fd0e0..ac89287 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -55,6 +55,7 @@ struct trace_uprobe { struct list_head list; struct trace_uprobe_filter filter; struct uprobe_consumer consumer; + struct path path; struct inode *inode; char *filename; unsigned long offset; @@ -289,7 +290,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 +364,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 +371,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,21 +436,16 @@ 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); + return ret; - if (!inode || !S_ISREG(inode->i_mode)) { + if (!d_is_reg(path.dentry)) { ret = -EINVAL; goto fail_address_parse; } @@ -490,7 +484,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 +552,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,6 +916,7 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file, goto err_flags; tu->consumer.filter = filter; + tu->inode = d_real_inode(tu->path.dentry); ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); if (ret) goto err_buffer; @@ -967,6 +962,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); + tu->inode = NULL; tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE; uprobe_buffer_disable(); @@ -1337,7 +1333,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,11 +1340,8 @@ 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); + if (!d_is_reg(path.dentry)) { + path_put(&path); return ERR_PTR(-EINVAL); } @@ -1364,11 +1356,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); -- 2.9.5