From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Howard McLauchlan <hmclauchlan@fb.com>,
Josef Bacik <jbacik@fb.com>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Miklos Szeredi <mszeredi@redhat.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Song Liu <songliubraving@fb.com>,
"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 4.16 52/52] tracing: Fix bad use of igrab in trace_uprobe.c
Date: Tue, 8 May 2018 10:10:50 +0200 [thread overview]
Message-ID: <20180508073935.457157327@linuxfoundation.org> (raw)
In-Reply-To: <20180508073928.058320984@linuxfoundation.org>
4.16-stable review patch. If anyone has any objections, please let me know.
------------------
From: Song Liu <songliubraving@fb.com>
commit 0c92c7a3c5d416f47b32c5f20a611dfeca5d5f2e 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 two instances in trace_uprobe.c. struct path is added to
struct trace_uprobe to keep the inode and containing mount point
referenced.
Link: http://lkml.kernel.org/r/20180423172135.4050588-1-songliubraving@fb.com
Fixes: f3f096cfedf8 ("tracing: Provide trace events interface for uprobes")
Fixes: 33ea4b24277b ("perf/core: Implement the 'perf_uprobe' PMU")
Cc: stable@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Howard McLauchlan <hmclauchlan@fb.com>
Cc: Josef Bacik <jbacik@fb.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: Miklos Szeredi <mszeredi@redhat.com>
Reported-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/trace/trace_uprobe.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
--- 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;
@@ -287,7 +288,7 @@ static void free_trace_uprobe(struct tra
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);
@@ -361,7 +362,6 @@ end:
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;
@@ -369,7 +369,6 @@ static int create_trace_uprobe(int argc,
bool is_delete, is_return;
int i, ret;
- inode = NULL;
ret = 0;
is_delete = false;
is_return = false;
@@ -435,21 +434,16 @@ static int create_trace_uprobe(int argc,
}
/* 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_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;
}
@@ -488,7 +482,7 @@ static int create_trace_uprobe(int argc,
goto fail_address_parse;
}
tu->offset = offset;
- tu->inode = inode;
+ tu->path = path;
tu->filename = kstrdup(filename, GFP_KERNEL);
if (!tu->filename) {
@@ -556,7 +550,7 @@ error:
return ret;
fail_address_parse:
- iput(inode);
+ path_put(&path);
pr_info("Failed to parse address or file.\n");
@@ -935,6 +929,7 @@ probe_event_enable(struct trace_uprobe *
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;
@@ -980,6 +975,7 @@ probe_event_disable(struct trace_uprobe
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();
next prev parent reply other threads:[~2018-05-08 8:14 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-08 8:09 [PATCH 4.16 00/52] 4.16.8-stable review Greg Kroah-Hartman
2018-05-08 8:09 ` [PATCH 4.16 01/52] ACPI / button: make module loadable when booted in non-ACPI mode Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 02/52] arm64: Add work around for Arm Cortex-A55 Erratum 1024718 Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 03/52] ALSA: hda - Fix incorrect usage of IS_REACHABLE() Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 04/52] ALSA: pcm: Check PCM state at xfern compat ioctl Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 05/52] ALSA: seq: Fix races at MIDI encoding in snd_virmidi_output_trigger() Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 06/52] ALSA: dice: fix kernel NULL pointer dereference due to invalid calculation for array index Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 07/52] ALSA: aloop: Mark paused device as inactive Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 08/52] ALSA: aloop: Add missing cable lock to ctl API callbacks Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 09/52] errseq: Always report a writeback error once Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 10/52] tracepoint: Do not warn on ENOMEM Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 11/52] scsi: target: Fix fortify_panic kernel exception Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 12/52] Input: leds - fix out of bound access Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 13/52] Input: atmel_mxt_ts - add touchpad button mapping for Samsung Chromebook Pro Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 15/52] rtlwifi: cleanup 8723be ant_sel definition Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 16/52] xfs: prevent creating negative-sized file via INSERT_RANGE Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 17/52] tools: power/acpi, revert to LD = gcc Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 18/52] RDMA/cxgb4: release hw resources on device removal Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 19/52] RDMA/ucma: Allow resolving address w/o specifying source address Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 20/52] RDMA/mlx5: Fix multiple NULL-ptr deref errors in rereg_mr flow Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 21/52] RDMA/mlx4: Add missed RSS hash inner header flag Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 22/52] RDMA/mlx5: Protect from shift operand overflow Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 24/52] IB/mlx5: Use unlimited rate when static rate is not supported Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 25/52] infiniband: mlx5: fix build errors when INFINIBAND_USER_ACCESS=m Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 26/52] IB/hfi1: Fix handling of FECN marked multicast packet Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 27/52] IB/hfi1: Fix loss of BECN with AHG Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 28/52] IB/hfi1: Fix NULL pointer dereference when invalid num_vls is used Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 29/52] iw_cxgb4: Atomically flush per QP HW CQEs Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 30/52] btrfs: Take trans lock before access running trans in check_delayed_ref Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 31/52] drm/vc4: Make sure vc4_bo_{inc,dec}_usecnt() calls are balanced Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 32/52] drm/vmwgfx: Fix a buffer object leak Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 33/52] drm/bridge: vga-dac: Fix edid memory leak Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 34/52] test_firmware: fix setting old custom fw path back on exit, second try Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 35/52] xhci: Fix use-after-free in xhci_free_virt_device Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 36/52] USB: serial: visor: handle potential invalid device configuration Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 37/52] usb: dwc3: gadget: Fix list_del corruption in dwc3_ep_dequeue Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 38/52] USB: Accept bulk endpoints with 1024-byte maxpacket Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 39/52] USB: serial: option: reimplement interface masking Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 41/52] usb: musb: host: fix potential NULL pointer dereference Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 42/52] usb: musb: trace: fix NULL pointer dereference in musb_g_tx() Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 44/52] platform/x86: Kconfig: Fix dell-laptop dependency chain Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 46/52] x86/tsc: Always unregister clocksource_tsc_early Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 47/52] x86/tsc: Fix mark_tsc_unstable() Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 48/52] irqchip/qcom: Fix check for spurious interrupts Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 49/52] clocksource: Allow clocksource_mark_unstable() on unregistered clocksources Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 50/52] clocksource: Initialize cs->wd_list Greg Kroah-Hartman
2018-05-08 8:10 ` [PATCH 4.16 51/52] clocksource: Consistent de-rate when marking unstable Greg Kroah-Hartman
2018-05-08 8:10 ` Greg Kroah-Hartman [this message]
2018-05-08 16:22 ` [PATCH 4.16 00/52] 4.16.8-stable review Guenter Roeck
2018-05-08 17:52 ` Greg Kroah-Hartman
2018-05-08 17:56 ` Naresh Kamboju
2018-05-08 18:48 ` Greg Kroah-Hartman
2018-05-08 23:53 ` Shuah Khan
2018-05-09 7:32 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180508073935.457157327@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=hmclauchlan@fb.com \
--cc=jbacik@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mingo@redhat.com \
--cc=mszeredi@redhat.com \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=srikar@linux.vnet.ibm.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).