tracing: Fixes for v5.4-rc2
Subsystems (3)
Steven Rostedt
maintainerLinus,
A few tracing fixes:
- Removed locked down from tracefs itself and moved it to the trace directory. Having the open functions there do the lockdown checks.
- Fixed a few races with opening an instance file and the instance being deleted (Discovered during the locked down updates). Kept separate from the clean up code such that they can be backported to stable easier.
- Cleaned up and consolidated the checks done when opening a trace file, as there were multiple checks that need to be done, and it did not make sense having them done in each open instance.
- Fixed a regression in the record mcount code.
- Small hw_lat detector tracer fixes.
- A trace_pipe read fix due to not initializing trace_seq.
Please pull the latest trace-v5.4-rc2 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v5.4-rc2
Tag SHA1: c79f12f50e68ee99f36c061f128b0a1411a96f5f Head SHA1: d303de1fcf344ff7c15ed64c3f48a991c9958775
Petr Mladek (1):
tracing: Initialize iter->seq after zeroing in tracing_read_pipe()
Srivatsa S. Bhat (VMware) (2):
tracing/hwlat: Report total time spent in all NMIs during the sample tracing/hwlat: Don't ignore outer-loop duration when calculating max_latency
Steven Rostedt (VMware) (8):
tracefs: Revert ccbd54ff54e8 ("tracefs: Restrict tracefs when the kernel is locked down")
ftrace: Get a reference counter for the trace_array on filter files
tracing: Get trace_array reference for available_tracers files
tracing: Have trace events system open call tracing_open_generic_tr()
tracing: Add tracing_check_open_get_tr()
tracing: Add locked_down checks to the open calls of files created for tracefs
tracing: Do not create tracefs files if tracefs lockdown is in effect
recordmcount: Fix nop_mcount() function
----
fs/tracefs/inode.c | 46 ++---------- kernel/trace/ftrace.c | 55 ++++++++++---- kernel/trace/trace.c | 139 ++++++++++++++++++++++-------------- kernel/trace/trace.h | 2 + kernel/trace/trace_dynevent.c | 4 ++ kernel/trace/trace_events.c | 35 +++++---- kernel/trace/trace_events_hist.c | 13 +++- kernel/trace/trace_events_trigger.c | 8 ++- kernel/trace/trace_hwlat.c | 4 +- kernel/trace/trace_kprobe.c | 12 +++- kernel/trace/trace_printk.c | 7 ++ kernel/trace/trace_stack.c | 8 +++ kernel/trace/trace_stat.c | 6 +- kernel/trace/trace_uprobe.c | 11 +++ scripts/recordmcount.h | 5 +- 15 files changed, 223 insertions(+), 132 deletions(-)
---------------------------
fs/tracefs/inode.c +5 -41
@@ -16,11 +16,11 @@#include <linux/namei.h> #include <linux/tracefs.h> #include <linux/fsnotify.h> +#include <linux/security.h> #include <linux/seq_file.h> #include <linux/parser.h> #include <linux/magic.h> #include <linux/slab.h> -#include <linux/security.h> #define TRACEFS_DEFAULT_MODE 0700
@@ -28,25 +28,6 @@ static struct vfsmount *tracefs_mount;static int tracefs_mount_count;static bool tracefs_registered; -static int default_open_file (struct inode *inode,struct file *filp) -{ -struct dentry *dentry = filp->f_path.dentry; -struct file_operations *real_fops; -int ret; - -if (!dentry) -return -EINVAL ; - - ret =security_locked_down (LOCKDOWN_TRACEFS ); -if (ret) -return ret; - - real_fops = dentry->d_fsdata; -if (!real_fops->open) -return 0 ; -return real_fops->open (inode, filp); -} -static ssize_t default_read_file (struct file *file,char __user *buf,size_t count,loff_t *ppos) {
@@ -241,12 +222,6 @@ static int tracefs_apply_options(struct super_block *sb)return 0 ; } -static void tracefs_destroy_inode (struct inode *inode) -{ -if (S_ISREG (inode->i_mode)) -kfree (inode->i_fop); -} -static int tracefs_remount (struct super_block *sb,int *flags,char *data) {int err;
@@ -283,7 +258,6 @@ static int tracefs_show_options(struct seq_file *m, struct dentry *root)static const struct super_operations tracefs_super_operations = { .statfs = simple_statfs, .remount_fs = tracefs_remount, - .destroy_inode = tracefs_destroy_inode, .show_options = tracefs_show_options, };
@@ -414,10 +388,12 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops) { - struct file_operations *proxy_fops; struct dentry *dentry;struct inode *inode; +if (security_locked_down (LOCKDOWN_TRACEFS )) +return NULL ; +if (!(mode &S_IFMT )) mode |=S_IFREG ;BUG_ON (!S_ISREG (mode));
@@ -430,20 +406,8 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode,if (unlikely (!inode))return failed_creating (dentry); - proxy_fops =kzalloc (sizeof (struct file_operations ),GFP_KERNEL ); -if (unlikely (!proxy_fops)) { -iput (inode); -return failed_creating (dentry); - } - -if (!fops) - fops = &tracefs_file_operations; - - dentry->d_fsdata = (void *)fops; -memcpy (proxy_fops, fops,sizeof (*proxy_fops)); - proxy_fops->open = default_open_file; inode->i_mode = mode; - inode->i_fop = proxy_fops; + inode->i_fop = fops ? fops : &tracefs_file_operations; inode->i_private = data;d_instantiate (dentry, inode);fsnotify_create (dentry->d_parent->d_inode, dentry);
kernel/trace/ftrace.c +43 -12
143 lines not on this page · raw message
kernel/trace/trace.c +87 -52
269 lines not on this page · raw message
kernel/trace/trace.h +2 -0
@@ -338,6 +338,7 @@ extern struct mutex trace_types_lock;extern int trace_array_get (struct trace_array *tr);extern void trace_array_put (struct trace_array *tr); +extern int tracing_check_open_get_tr (struct trace_array *tr);extern int tracing_set_time_stamp_abs (struct trace_array *tr,bool abs);extern int tracing_set_clock (struct trace_array *tr,const char *clockstr);
@@ -681,6 +682,7 @@ void tracing_reset_online_cpus(struct trace_buffer *buf);void tracing_reset_current (int cpu);void tracing_reset_all_online_cpus (void );int tracing_open_generic (struct inode *inode,struct file *filp); +int tracing_open_generic_tr (struct inode *inode,struct file *filp);bool tracing_is_disabled (void );bool tracer_tracing_is_on (struct trace_array *tr);void tracer_tracing_on (struct trace_array *tr);
kernel/trace/trace_dynevent.c +4 -0
@@ -174,6 +174,10 @@ static int dyn_event_open(struct inode *inode, struct file *file) {int ret; + ret =tracing_check_open_get_tr (NULL ); +if (ret) +return ret; +if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC )) { ret =dyn_events_release_all (NULL );if (ret <0 )
kernel/trace/trace_events.c +17 -18
@@ -12,6 +12,7 @@#define pr_fmt (fmt) fmt#include <linux/workqueue.h> +#include <linux/security.h> #include <linux/spinlock.h> #include <linux/kthread.h> #include <linux/tracefs.h>
@@ -1294,6 +1295,8 @@ static int trace_format_open(struct inode *inode, struct file *file)struct seq_file *m;int ret; +/* Do we want to hide event format files on tracefs lockdown? */ + ret =seq_open (file, &trace_format_seq_ops);if (ret <0 )return ret;
@@ -1440,28 +1443,17 @@ static int system_tr_open(struct inode *inode, struct file *filp)struct trace_array *tr = inode->i_private;int ret; -if (tracing_is_disabled ()) -return -ENODEV ; - -if (trace_array_get (tr) <0 ) -return -ENODEV ; -/* Make a temporary dir that has no system but points to tr */ dir =kzalloc (sizeof (*dir),GFP_KERNEL ); -if (!dir) { -trace_array_put (tr); +if (!dir)return -ENOMEM ; - } - dir->tr = tr; - - ret =tracing_open_generic (inode, filp); + ret =tracing_open_generic_tr (inode, filp);if (ret <0 ) { -trace_array_put (tr);kfree (dir);return ret; } - + dir->tr = tr; filp->private_data = dir;return 0 ;
@@ -1771,6 +1763,10 @@ ftrace_event_open(struct inode *inode, struct file *file,struct seq_file *m;int ret; + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + ret =seq_open (file, seq_ops);if (ret <0 )return ret;
@@ -1795,6 +1791,7 @@ ftrace_event_avail_open(struct inode *inode, struct file *file) {const struct seq_operations *seq_ops = &show_event_seq_ops; +/* Checks for tracefs lockdown */ return ftrace_event_open (inode, file, seq_ops); }
@@ -1805,8 +1802,9 @@ ftrace_event_set_open(struct inode *inode, struct file *file)struct trace_array *tr = inode->i_private;int ret; -if (trace_array_get (tr) <0 ) -return -ENODEV ; + ret =tracing_check_open_get_tr (tr); +if (ret) +return ret;if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC ))
@@ -1825,8 +1823,9 @@ ftrace_event_set_pid_open(struct inode *inode, struct file *file)struct trace_array *tr = inode->i_private;int ret; -if (trace_array_get (tr) <0 ) -return -ENODEV ; + ret =tracing_check_open_get_tr (tr); +if (ret) +return ret;if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC ))
kernel/trace/trace_events_hist.c +12 -1
@@ -7,6 +7,7 @@#include <linux/module.h> #include <linux/kallsyms.h> +#include <linux/security.h> #include <linux/mutex.h> #include <linux/slab.h> #include <linux/stacktrace.h>
@@ -1448,6 +1449,10 @@ static int synth_events_open(struct inode *inode, struct file *file) {int ret; + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC )) { ret =dyn_events_release_all (&synth_event_ops);if (ret <0 )
@@ -1680,7 +1685,7 @@ static int save_hist_vars(struct hist_trigger_data *hist_data)if (var_data)return 0 ; -if (trace_array_get (tr) <0 ) +if (tracing_check_open_get_tr (tr))return -ENODEV ; var_data =kzalloc (sizeof (*var_data),GFP_KERNEL );
@@ -5515,6 +5520,12 @@ static int hist_show(struct seq_file *m, void *v)static int event_hist_open (struct inode *inode,struct file *file) { +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +return single_open (file, hist_show, file); }
kernel/trace/trace_events_trigger.c +7 -1
@@ -5,6 +5,7 @@* Copyright (C) 2013 Tom Zanussi <[email protected]> */ +#include <linux/security.h> #include <linux/module.h> #include <linux/ctype.h> #include <linux/mutex.h>
@@ -173,7 +174,11 @@ static const struct seq_operations event_triggers_seq_ops = {static int event_trigger_regex_open (struct inode *inode,struct file *file) { -int ret =0 ; +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret;mutex_lock (&event_mutex);
@@ -292,6 +297,7 @@ event_trigger_write(struct file *filp, const char __user *ubuf,static int event_trigger_open (struct inode *inode,struct file *filp) { +/* Checks for tracefs lockdown */ return event_trigger_regex_open (inode, filp); }
kernel/trace/trace_hwlat.c +3 -1
@@ -150,7 +150,7 @@ void trace_hwlat_callback(bool enter)if (enter) nmi_ts_start =time_get ();else - nmi_total_ts =time_get () - nmi_ts_start; + nmi_total_ts +=time_get () - nmi_ts_start; }if (enter)
@@ -256,6 +256,8 @@ static int get_sample(void)/* Keep a running maximum ever recorded hardware latency */ if (sample > tr->max_latency) tr->max_latency = sample; +if (outer_sample > tr->max_latency) + tr->max_latency = outer_sample; } out:
kernel/trace/trace_kprobe.c +11 -1
@@ -7,11 +7,11 @@*/ #define pr_fmt (fmt) "trace_kprobe: " fmt +#include <linux/security.h> #include <linux/module.h> #include <linux/uaccess.h> #include <linux/rculist.h> #include <linux/error-injection.h> -#include <linux/security.h> #include <asm/setup.h> /* for COMMAND_LINE_SIZE */
@@ -936,6 +936,10 @@ static int probes_open(struct inode *inode, struct file *file) {int ret; + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC )) { ret =dyn_events_release_all (&trace_kprobe_ops);if (ret <0 )
@@ -988,6 +992,12 @@ static const struct seq_operations profile_seq_op = {static int profile_open (struct inode *inode,struct file *file) { +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +return seq_open (file, &profile_seq_op); }
kernel/trace/trace_printk.c +7 -0
@@ -6,6 +6,7 @@* */ #include <linux/seq_file.h> +#include <linux/security.h> #include <linux/uaccess.h> #include <linux/kernel.h> #include <linux/ftrace.h>
@@ -348,6 +349,12 @@ static const struct seq_operations show_format_seq_ops = {static int ftrace_formats_open (struct inode *inode,struct file *file) { +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +return seq_open (file, &show_format_seq_ops); }
kernel/trace/trace_stack.c +8 -0
@@ -5,6 +5,7 @@*/ #include <linux/sched/task_stack.h> #include <linux/stacktrace.h> +#include <linux/security.h> #include <linux/kallsyms.h> #include <linux/seq_file.h> #include <linux/spinlock.h>
@@ -470,6 +471,12 @@ static const struct seq_operations stack_trace_seq_ops = {static int stack_trace_open (struct inode *inode,struct file *file) { +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +return seq_open (file, &stack_trace_seq_ops); }
@@ -487,6 +494,7 @@ stack_trace_filter_open(struct inode *inode, struct file *file) {struct ftrace_ops *ops = inode->i_private; +/* Checks for tracefs lockdown */ return ftrace_regex_open (ops,FTRACE_ITER_FILTER , inode, file); }
kernel/trace/trace_stat.c +5 -1
@@ -9,7 +9,7 @@* */ - +#include <linux/security.h> #include <linux/list.h> #include <linux/slab.h> #include <linux/rbtree.h>
@@ -238,6 +238,10 @@ static int tracing_stat_open(struct inode *inode, struct file *file)struct seq_file *m;struct stat_session *session = inode->i_private; + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + ret =stat_seq_init (session);if (ret)return ret;
kernel/trace/trace_uprobe.c +11 -0
@@ -7,6 +7,7 @@*/ #define pr_fmt (fmt) "trace_uprobe: " fmt +#include <linux/security.h> #include <linux/ctype.h> #include <linux/module.h> #include <linux/uaccess.h>
@@ -769,6 +770,10 @@ static int probes_open(struct inode *inode, struct file *file) {int ret; + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC )) { ret =dyn_events_release_all (&trace_uprobe_ops);if (ret)
@@ -818,6 +823,12 @@ static const struct seq_operations profile_seq_op = {static int profile_open (struct inode *inode,struct file *file) { +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; +return seq_open (file, &profile_seq_op); }
scripts/recordmcount.h +1 -4
@@ -389,11 +389,8 @@ static int nop_mcount(Elf_Shdr const *const relhdr, mcountsym =get_mcountsym (sym0, relp, str0);if (mcountsym ==Elf_r_sym (relp) && !is_fake_mcount (relp)) { -if (make_nop) { +if (make_nop) ret =make_nop ((void *)ehdr,_w (shdr->sh_offset) +_w (relp->r_offset)); -if (ret <0 ) -return -1 ; - }if (warn_on_notrace_sect && !once) {printf ("Section %s has mcount callers being ignored\n" , txtname);
The pull request you sent on Sun, 13 Oct 2019 15:07:02 -0400:
The pull request you sent on Sun, 13 Oct 2019 15:07:02 -0400:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.gittrace-v5.4-rc2
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/d4615e5a46800d2193bf8ae98cb470206f5f635b
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.wiki.kernel.org/userdoc/prtracker