#include #include /* * Any file that uses trace points, must include the header. * But only one file, must include the header by defining * CREATE_TRACE_POINTS first. This will make the C code that * creates the handles for the trace points. */ #define CREATE_TRACE_POINTS #include "trace-events-sample.h" static const char *random_strings[] = { "Mother Goose", "Snoopy", "Gandalf", "Frodo", "One ring to rule them all" }; static void simple_thread_func(int cnt) { int array[6]; int len = cnt % 5; int i; set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ); for (i = 0; i < len; i++) array[i] = i + 1; array[i] = 0; /* Silly tracepoints */ trace_foo_bar("hello", cnt, array, random_strings[len], tsk_cpus_allowed(current)); trace_foo_with_template_simple("HELLO", cnt); trace_foo_bar_with_cond("Some times print", cnt); trace_foo_with_template_cond("prints other times", cnt); trace_foo_with_template_print("I have to be different", cnt); } static int simple_thread(void *arg) { int cnt = 0; while (!kthread_should_stop()) simple_thread_func(cnt++); return 0; } static struct task_struct *simple_tsk; static struct task_struct *simple_tsk_fn; static void simple_thread_func_fn(int cnt) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ); /* More silly tracepoints */ trace_foo_bar_with_fn("Look at me", cnt); trace_foo_with_template_fn("Look at me too", cnt); } static int simple_thread_fn(void *arg) { int cnt = 0; while (!kthread_should_stop()) simple_thread_func_fn(cnt++); return 0; } static DEFINE_MUTEX(thread_mutex); int foo_bar_reg(void) { pr_info("Starting thread for foo_bar_fn\n"); /* * We shouldn't be able to start a trace when the module is * unloading (there's other locks to prevent that). But * for consistency sake, we still take the thread_mutex. */ mutex_lock(&thread_mutex); simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn"); mutex_unlock(&thread_mutex); return 0; } void foo_bar_unreg(void) { pr_info("Killing thread for foo_bar_fn\n"); /* protect against module unloading */ mutex_lock(&thread_mutex); if (simple_tsk_fn) kthread_stop(simple_tsk_fn); simple_tsk_fn = NULL; mutex_unlock(&thread_mutex); } static int __init trace_event_init(void) { simple_tsk = kthread_run(simple_thread, NULL, "event-sample"); if (IS_ERR(simple_tsk)) return -1; return 0; } static void __exit trace_event_exit(void) { kthread_stop(simple_tsk); mutex_lock(&thread_mutex); if (simple_tsk_fn) kthread_stop(simple_tsk_fn); simple_tsk_fn = NULL; mutex_unlock(&thread_mutex); } module_init(trace_event_init); module_exit(trace_event_exit); MODULE_AUTHOR("Steven Rostedt"); MODULE_DESCRIPTION("trace-events-sample"); MODULE_LICENSE("GPL"); rch'/>
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2017-01-26 16:47:28 -0500
committerTejun Heo <tj@kernel.org>2017-01-26 16:47:28 -0500
commit07cd12945551b63ecb1a349d50a6d69d1d6feb4a (patch)
tree75f65eba7eac9277971082a2d5a4cf1370562c0c /net/ipv6/ip6_vti.c
parent7ce7d89f48834cefece7804d38fc5d85382edf77 (diff)
cgroup: don't online subsystems before cgroup_name/path() are operational
While refactoring cgroup creation, a5bca2152036 ("cgroup: factor out cgroup_create() out of cgroup_mkdir()") incorrectly onlined subsystems before the new cgroup is associated with it kernfs_node. This is fine for cgroup proper but cgroup_name/path() depend on the associated kernfs_node and if a subsystem makes the new cgroup_subsys_state visible, which they're allowed to after onlining, it can lead to NULL dereference. The current code performs cgroup creation and subsystem onlining in cgroup_create() and cgroup_mkdir() makes the cgroup and subsystems visible afterwards. There's no reason to online the subsystems early and we can simply drop cgroup_apply_control_enable() call from cgroup_create() so that the subsystems are onlined and made visible at the same time. Signed-off-by: Tejun Heo <tj@kernel.org> Reported-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Fixes: a5bca2152036 ("cgroup: factor out cgroup_create() out of cgroup_mkdir()") Cc: stable@vger.kernel.org # v4.6+
Diffstat (limited to 'net/ipv6/ip6_vti.c')