Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3278846imm; Fri, 25 May 2018 02:59:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrtFT8lqFGLlDxR7VXjKqNEctPaA+LhdHi7XnhohAF9zODKQXn8EEtfj601c/IyTGl8n1rR X-Received: by 2002:a63:951c:: with SMTP id p28-v6mr1454492pgd.318.1527242358577; Fri, 25 May 2018 02:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527242358; cv=none; d=google.com; s=arc-20160816; b=P4BJMuIHdtm5AiYG6nYj9VitnqIt2GP/KojpHGBAmhKRUaCr4BLpUVSYlXzDf5mopS l77m3omPgFrLc3+zGsPC6dZz3VvgXSj3D7dbYovMDbbbslo+YEyWBPts/v3q8A9NhSYb 77PskBTrWI8dNyDlFbDv6aMKG22VchTzQVTbe0UWc43e+o6I34u7DtF1X3nVTINoDOfC dmVjy3d+RtIT50cVFRn1yNqwGya92YaAHV76gfL7clN4qneb5+GMR4bMekrWlM5Xzoec exl2Biyo8ocYYDZQECv1uMH3Fp5XR4LDVB8+08o7Dqz5isMc+0R5zvUxV6F7WpOedC7c SxdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=ONJ/p2gYf0Y8rX5BQgZzQVNkn1PvzSF3VPb9y5IdLlY=; b=HCXynNEpQHLZaKjzAGcQTba+1rnaIfmXIXS4AW34wmGoG9LAdw39XRdAzhv74zfjXA lsCnA9RPed0tlNWL8WTAS1C7MATAVAdh0m25o/rdbTV/rq/JKr9BEMq316VbZGlhl9qc RpVTp1QUw7FAWPqLi9a0VqI+Sz+CUlFZ4YWFFjdx7PV14jvBEE1JRtp6Ki+MdoqeXykB l3T44igH+wXavAQ5EWrlEndrai8K8d2gyQ6jG2FWfGhM0wWqS4GYJUj21CIqoPYHTRph pGLK2+Nn/WkV6eK/VWk//vL4W/3dtVGVGPKdMK7PVYu4lbuWN4+eMJeQqawojTE3omK+ w/mg== 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 j28-v6si23567401pfe.337.2018.05.25.02.59.04; Fri, 25 May 2018 02:59: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; 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 S966099AbeEYJ5J (ORCPT + 99 others); Fri, 25 May 2018 05:57:09 -0400 Received: from terminus.zytor.com ([198.137.202.136]:40141 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965826AbeEYJt7 (ORCPT ); Fri, 25 May 2018 05:49:59 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w4P9nZ7a992245 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 25 May 2018 02:49:35 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w4P9nYKN992241; Fri, 25 May 2018 02:49:34 -0700 Date: Fri, 25 May 2018 02:49:34 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Song Liu Message-ID: Cc: jolsa@redhat.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com, alexander.shishkin@linux.intel.com, miklos@szeredi.hu, eranian@google.com, peterz@infradead.org, vincent.weaver@maine.edu, mingo@kernel.org, kernel-team@fb.com, acme@redhat.com, songliubraving@fb.com, torvalds@linux-foundation.org Reply-To: acme@redhat.com, torvalds@linux-foundation.org, songliubraving@fb.com, mingo@kernel.org, vincent.weaver@maine.edu, kernel-team@fb.com, eranian@google.com, peterz@infradead.org, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, hpa@zytor.com, tglx@linutronix.de, jolsa@redhat.com, miklos@szeredi.hu In-Reply-To: <20180418062907.3210386-2-songliubraving@fb.com> References: <20180418062907.3210386-2-songliubraving@fb.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf/core: Fix bad use of igrab() Git-Commit-ID: 9511bce9fe8e5e6c0f923c09243a713eba560141 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=0.2 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9511bce9fe8e5e6c0f923c09243a713eba560141 Gitweb: https://git.kernel.org/tip/9511bce9fe8e5e6c0f923c09243a713eba560141 Author: Song Liu AuthorDate: Tue, 17 Apr 2018 23:29:07 -0700 Committer: Ingo Molnar CommitDate: Fri, 25 May 2018 08:11:10 +0200 perf/core: Fix bad use of igrab() 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 the issue in kernel/event/core.c. Reviewed-and-tested-by: Alexander Shishkin Reported-by: Miklos Szeredi Signed-off-by: Song Liu Signed-off-by: Peter Zijlstra (Intel) Cc: Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Fixes: 375637bc5249 ("perf/core: Introduce address range filtering") Link: http://lkml.kernel.org/r/20180418062907.3210386-2-songliubraving@fb.com Signed-off-by: Ingo Molnar --- arch/x86/events/intel/pt.c | 4 ++-- include/linux/perf_event.h | 2 +- kernel/events/core.c | 21 +++++++++------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 3b993942a0e4..8d016ce5b80d 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -1194,7 +1194,7 @@ static int pt_event_addr_filters_validate(struct list_head *filters) filter->action == PERF_ADDR_FILTER_ACTION_START) return -EOPNOTSUPP; - if (!filter->inode) { + if (!filter->path.dentry) { if (!valid_kernel_ip(filter->offset)) return -EINVAL; @@ -1221,7 +1221,7 @@ static void pt_event_addr_filters_sync(struct perf_event *event) return; list_for_each_entry(filter, &head->list, entry) { - if (filter->inode && !offs[range]) { + if (filter->path.dentry && !offs[range]) { msr_a = msr_b = 0; } else { /* apply the offset */ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index def866f7269b..bea0b0cd4bf7 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -467,7 +467,7 @@ enum perf_addr_filter_action_t { */ struct perf_addr_filter { struct list_head entry; - struct inode *inode; + struct path path; unsigned long offset; unsigned long size; enum perf_addr_filter_action_t action; diff --git a/kernel/events/core.c b/kernel/events/core.c index ce6aa5ff3c96..24dea13a27ed 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6668,7 +6668,7 @@ static void perf_event_addr_filters_exec(struct perf_event *event, void *data) raw_spin_lock_irqsave(&ifh->lock, flags); list_for_each_entry(filter, &ifh->list, entry) { - if (filter->inode) { + if (filter->path.dentry) { event->addr_filters_offs[count] = 0; restart++; } @@ -7333,7 +7333,7 @@ static bool perf_addr_filter_match(struct perf_addr_filter *filter, struct file *file, unsigned long offset, unsigned long size) { - if (filter->inode != file_inode(file)) + if (d_inode(filter->path.dentry) != file_inode(file)) return false; if (filter->offset > offset + size) @@ -8686,8 +8686,7 @@ static void free_filters_list(struct list_head *filters) struct perf_addr_filter *filter, *iter; list_for_each_entry_safe(filter, iter, filters, entry) { - if (filter->inode) - iput(filter->inode); + path_put(&filter->path); list_del(&filter->entry); kfree(filter); } @@ -8784,7 +8783,7 @@ static void perf_event_addr_filters_apply(struct perf_event *event) * Adjust base offset if the filter is associated to a binary * that needs to be mapped: */ - if (filter->inode) + if (filter->path.dentry) event->addr_filters_offs[count] = perf_addr_filter_apply(filter, mm); @@ -8858,7 +8857,6 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr, { struct perf_addr_filter *filter = NULL; char *start, *orig, *filename = NULL; - struct path path; substring_t args[MAX_OPT_ARGS]; int state = IF_STATE_ACTION, token; unsigned int kernel = 0; @@ -8971,19 +8969,18 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr, goto fail_free_name; /* look up the path and grab its inode */ - ret = kern_path(filename, LOOKUP_FOLLOW, &path); + ret = kern_path(filename, LOOKUP_FOLLOW, + &filter->path); if (ret) goto fail_free_name; - filter->inode = igrab(d_inode(path.dentry)); - path_put(&path); kfree(filename); filename = NULL; ret = -EINVAL; - if (!filter->inode || - !S_ISREG(filter->inode->i_mode)) - /* free_filters_list() will iput() */ + if (!filter->path.dentry || + !S_ISREG(d_inode(filter->path.dentry) + ->i_mode)) goto fail; event->addr_filters.nr_file_filters++;