Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3881491pxb; Tue, 17 Nov 2020 06:07:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYt1UxmgT17ieJlNj2hLAld0CYZYnMbqvHB0gcIRNhMsjeBGs5VrHGLPnpQZ3w04asTBGy X-Received: by 2002:a05:6402:150b:: with SMTP id f11mr1378080edw.332.1605622035274; Tue, 17 Nov 2020 06:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622035; cv=none; d=google.com; s=arc-20160816; b=bDmrUpAymOlh77NCHNUIoHWDr2plRXwVTmHy5uukeIcrdl8zXkhQs/9kgofejAkDsY sZQWIPvv8g1nBd8jdUfEKJPFuQ/5x58oTXXujAWtnVkYOiOkpegZsff98itb8DFHyjHo wTtRbw4gyiK05yGMBW+NcO+ms93Es6msflfyGnJEIsvUp/App4EvPkQOAz6EH0ONUqM1 4kGHBNrJLt2F8+oRKozPacEsuWR0Zbs8J5As5R4YQhl6uzxnJ21SZf5/Hum9ALiFK8W4 VVpAixYLaGh3qiDt79zKiqJ6rH1CSZQLN22NY11c7abSNXAaKVV+FzT0lAhxZgLNWdSy 0SGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hkSkanu4MBCRjyXq7z5lxT+MUnP7NxVMNDhhC2u/Alk=; b=QFfqmVcV3blO3qJS3D0ZeXsOOKc4yWZUbJptv2luFsdwABvBdfpreHBqXsaPFKsoq7 Le5YTJbXY9r8thE9TAnrdwJfMB+T6AlBXvluQPrnVk++8Q5xI4hSiDXroXZanZ+t5i/K 5XUwyzdjff9hJmrNJ8FDcqgp1OeETI7tYtaYw8BRn4wWruG7ezCxJ7VsWQESKprecJlX ZL0gvLGu3/rQ7gRtO7ufVNdETgRzXRFNkapBkR8Jlp1iYc1rZDK5Om1vwYr2IblrDVxr 602svLMM0xOeBRL0z1QGeMD+okYAycHgiYPX3xtULaZiZCb73lCGObBetPdq+PRqXOSS 0b6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b4ZDYAYg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k5si595445eji.617.2020.11.17.06.06.50; Tue, 17 Nov 2020 06:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b4ZDYAYg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731397AbgKQODg (ORCPT + 99 others); Tue, 17 Nov 2020 09:03:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:41728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729738AbgKQNLu (ORCPT ); Tue, 17 Nov 2020 08:11:50 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 48791221EB; Tue, 17 Nov 2020 13:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618709; bh=BUclUuYgn4Y08iF/T/yjq2TNqKKw938+bWEZ7Ug7e0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4ZDYAYgu/hXaaLkqViOB/6FTOkGP4l6p9VxHRbz80dgCiS7LWWfD36palFCcbSAm 7qNi5hzZcGozyLl5kW6+NbAUtbf8ULQPkCe3VG5aUoAoQP3LdmC7hnaDowNou9vGf3 WZuRwXVH8wC+EAMHX6CSL5qwGPsrCnLFGI19na0w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miklos Szeredi , Song Liu , "Peter Zijlstra (Intel)" , kernel-team@fb.com, Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , Ingo Molnar , Sudip Mukherjee Subject: [PATCH 4.9 59/78] perf/core: Fix bad use of igrab() Date: Tue, 17 Nov 2020 14:05:25 +0100 Message-Id: <20201117122111.996481401@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122109.116890262@linuxfoundation.org> References: <20201117122109.116890262@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Song Liu commit 9511bce9fe8e5e6c0f923c09243a713eba560141 upstream 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 [sudip: Backported to 4.9: use file_inode()] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -1117,7 +1117,7 @@ static int pt_event_addr_filters_validat if (!filter->range || !filter->size) return -EOPNOTSUPP; - if (!filter->inode) { + if (!filter->path.dentry) { if (!valid_kernel_ip(filter->offset)) return -EINVAL; @@ -1144,7 +1144,7 @@ static void pt_event_addr_filters_sync(s 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 */ --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -475,7 +475,7 @@ struct pmu { */ struct perf_addr_filter { struct list_head entry; - struct inode *inode; + struct path path; unsigned long offset; unsigned long size; unsigned int range : 1, --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6271,7 +6271,7 @@ static void perf_event_addr_filters_exec 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++; } @@ -6814,7 +6814,7 @@ static bool perf_addr_filter_match(struc struct file *file, unsigned long offset, unsigned long size) { - if (filter->inode != file->f_inode) + if (d_inode(filter->path.dentry) != file_inode(file)) return false; if (filter->offset > offset + size) @@ -8028,8 +8028,7 @@ static void free_filters_list(struct lis 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); } @@ -8123,7 +8122,7 @@ static void perf_event_addr_filters_appl * 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); @@ -8196,7 +8195,6 @@ perf_event_parse_addr_filter(struct perf { 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; @@ -8287,19 +8285,18 @@ perf_event_parse_addr_filter(struct perf goto fail; /* 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; }