Received: by 10.192.165.156 with SMTP id m28csp461186imm; Thu, 19 Apr 2018 01:59:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx49J0M00f9+YOgldYFaYdtip/koga2DZgQpN7JEWEUSHyaGSd7Nu3hPJ0OaEDJPRzZCP4kg0 X-Received: by 2002:a17:902:6689:: with SMTP id e9-v6mr5418294plk.176.1524128373975; Thu, 19 Apr 2018 01:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524128373; cv=none; d=google.com; s=arc-20160816; b=QSvKDBmnPFqzLDauvQWhH8TdZej1NeFR1dI32FQIl72+x/MlAba24XwjUW9DfYjVk+ GrbbvJxMfu+b6SR67moNnjHyx1SKKmrlsucQi0IOJ6QH7RIqoCQ63v1xhg9bV9sxwW0J TnZihRcwenb/JOWB06L6cmxo8VSenbgyMRwsNDw2s4t+yxrlOa0b3F/DBLcT7gi4UcgW DFbeuUSEnQDD3N+EUiVu0eeLUM5BMQpY9SpBZDsgEJXBG6A5rAjr0Z+mg15zz3Vqmcrn riFEi7QsYbVngkgpCFoix/JjkZ5cMwaJU8z/Ab0tQyoki+O0ZPwKGrjwrmpElVZSekmx udfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=twLAJia+Zahy2Y4e5GyK3iMrf+rZpyvXMfQ8ZKtCB1g=; b=r+jO8vOjaq8+jaZ2um8POujPa1Z+21zJFsxRt8lIC8ODCLLGRpMa9f+40xjuqXcres aI99N4Bt4FdJy/uROeDoAR6PGs/xfpv9RXW8lrDdVxMZfwmJnp3Xpo2PlF60NT0kq2EH i6iw+/XjtQ24nsgJYGiUpJyYUNlGPhfV+MdJeFoiWVM6hHrdf57jOjeBJcTCc4/v/JOE S0NFXQNdNBYVPI+L0C60A9W8+BAFwH49QsR8GWqQcvCKL+nBgd0hpPsHP4W55ZzVTqK0 YdQ/7hZuEifhfK94pu3m64r6a6va30BQIemcs127PQYJ2cli/qgXqRnFNUrd1GESOCFr 3xHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=oJgNvwIo; 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 j33-v6si3029459pld.395.2018.04.19.01.59.19; Thu, 19 Apr 2018 01:59:33 -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=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=oJgNvwIo; 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 S1751135AbeDSI6N (ORCPT + 99 others); Thu, 19 Apr 2018 04:58:13 -0400 Received: from mail-yb0-f195.google.com ([209.85.213.195]:35721 "EHLO mail-yb0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750799AbeDSI6K (ORCPT ); Thu, 19 Apr 2018 04:58:10 -0400 Received: by mail-yb0-f195.google.com with SMTP id c1-v6so1579433ybm.2 for ; Thu, 19 Apr 2018 01:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=twLAJia+Zahy2Y4e5GyK3iMrf+rZpyvXMfQ8ZKtCB1g=; b=oJgNvwIovAQcUS61qo6TrY56iY9r0WwkVp7HGptDugX4PU4HOcaB3F4O+XxkjX4CxV f19C/nv5uR/WK2os/B7hhCTdzYcklVv1CcPwhcE30Gswe6Trm/DocMG6NPZdStGr+rM+ lqFxmrA+EvhbkiIUqyR/nqxmgjPubDlHGceLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=twLAJia+Zahy2Y4e5GyK3iMrf+rZpyvXMfQ8ZKtCB1g=; b=giykgqc+e8QxvzNfxHZUZIj/ojRthOjgw0tB3dn15D/bY23PXJSLvk/LEP/iXlrypq 3t4I0y6UuRAbj42gITSWBx5wwM3zal7wn8di/VQURi5whchZHHFWvxeSU5EhQPZmoLDO uYmFRWACwqcJOJd/qC0P6j4a8IQ/BG1DQBy4yDS586o9lC/wM40dmRfoWyIqiaKTW+AL nD4JgpSp0tvWMZJaTwiI5518gTwupEu2fcy+3ZF4ZGb1QECLmwtXk1YyKfUDp1CokrBM KviDu/ggjJ/JhG0amYXZVCjZlw1PgXFmlew5XbpjIeYnmZvGZBXCitWC1D+TDoDDLdYF KLQw== X-Gm-Message-State: ALQs6tBla4L+Urkt1xe3punnQ5+SM3ftoDIY6YhWJ6lBKUyJvWM+Dsq0 gPbad11w9SVbs7NKklQLnAar4pwa X-Received: by 2002:a25:e808:: with SMTP id k8-v6mr3422411ybd.55.1524128289695; Thu, 19 Apr 2018 01:58:09 -0700 (PDT) Received: from mail-yw0-f175.google.com (mail-yw0-f175.google.com. [209.85.161.175]) by smtp.gmail.com with ESMTPSA id b66-v6sm1303004ywh.5.2018.04.19.01.58.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Apr 2018 01:58:08 -0700 (PDT) Received: by mail-yw0-f175.google.com with SMTP id i144-v6so1437059ywc.2 for ; Thu, 19 Apr 2018 01:58:08 -0700 (PDT) X-Received: by 2002:a81:6e84:: with SMTP id j126-v6mr3205218ywc.510.1524128288387; Thu, 19 Apr 2018 01:58:08 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:ca52:0:0:0:0:0 with HTTP; Thu, 19 Apr 2018 01:58:07 -0700 (PDT) In-Reply-To: <20180418174014.1592871-1-songliubraving@fb.com> References: <20180418174014.1592871-1-songliubraving@fb.com> From: Miklos Szeredi Date: Thu, 19 Apr 2018 10:58:07 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] tracing: fix bad use of igrab in trace_uprobe.c To: Song Liu Cc: LKML , kernel-team , Steven Rostedt , Ingo Molnar , Howard McLauchlan , Josef Bacik , Srikar Dronamraju Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 18, 2018 at 7:40 PM, 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)) { Where has the S_ISREG check gone? > - 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)) { And here, again. Otherwise ACK. Also please create a separate patch that removes igrab/iput calls from kernel/events/uprobes.c and adds a comment to the effect that the caller is required to keep the inode (and the containing mount) referenced. Thanks, Miklos