Skip to content

Commit fd59351

Browse files
beaubelgraverostedt
authored andcommitted
tracing/user_events: Track fork/exec/exit for mm lifetime
During tracefs discussions it was decided instead of requiring a mapping within a user-process to track the lifetime of memory descriptors we should hook the appropriate calls. Do this by adding the minimal stubs required for task fork, exec, and exit. Currently this is just a NOP. Future patches will implement these calls fully. Link: https://lkml.kernel.org/r/20230328235219.203-3-beaub@linux.microsoft.com Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent e5a26a4 commit fd59351

5 files changed

Lines changed: 29 additions & 0 deletions

File tree

fs/exec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <linux/syscall_user_dispatch.h>
6666
#include <linux/coredump.h>
6767
#include <linux/time_namespace.h>
68+
#include <linux/user_events.h>
6869

6970
#include <linux/uaccess.h>
7071
#include <asm/mmu_context.h>
@@ -1859,6 +1860,7 @@ static int bprm_execve(struct linux_binprm *bprm,
18591860
current->fs->in_exec = 0;
18601861
current->in_execve = 0;
18611862
rseq_execve(current);
1863+
user_events_execve(current);
18621864
acct_update_integrals(current);
18631865
task_numa_free(current, false);
18641866
return retval;

include/linux/sched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct sighand_struct;
6969
struct signal_struct;
7070
struct task_delay_info;
7171
struct task_group;
72+
struct user_event_mm;
7273

7374
/*
7475
* Task state bitmask. NOTE! These bits are also
@@ -1528,6 +1529,10 @@ struct task_struct {
15281529
union rv_task_monitor rv[RV_PER_TASK_MONITORS];
15291530
#endif
15301531

1532+
#ifdef CONFIG_USER_EVENTS
1533+
struct user_event_mm *user_event_mm;
1534+
#endif
1535+
15311536
/*
15321537
* New fields for task_struct should be added above here, so that
15331538
* they are included in the randomized portion of task_struct.

include/linux/user_events.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,22 @@
1111

1212
#include <uapi/linux/user_events.h>
1313

14+
#ifdef CONFIG_USER_EVENTS
15+
struct user_event_mm {
16+
};
17+
#endif
18+
19+
static inline void user_events_fork(struct task_struct *t,
20+
unsigned long clone_flags)
21+
{
22+
}
23+
24+
static inline void user_events_execve(struct task_struct *t)
25+
{
26+
}
27+
28+
static inline void user_events_exit(struct task_struct *t)
29+
{
30+
}
31+
1432
#endif /* _LINUX_USER_EVENTS_H */

kernel/exit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include <linux/kprobes.h>
6969
#include <linux/rethook.h>
7070
#include <linux/sysfs.h>
71+
#include <linux/user_events.h>
7172

7273
#include <linux/uaccess.h>
7374
#include <asm/unistd.h>
@@ -818,6 +819,7 @@ void __noreturn do_exit(long code)
818819

819820
coredump_task_exit(tsk);
820821
ptrace_event(PTRACE_EVENT_EXIT, code);
822+
user_events_exit(tsk);
821823

822824
validate_creds_for_do_exit(tsk);
823825

kernel/fork.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#include <linux/io_uring.h>
9898
#include <linux/bpf.h>
9999
#include <linux/stackprotector.h>
100+
#include <linux/user_events.h>
100101

101102
#include <asm/pgalloc.h>
102103
#include <linux/uaccess.h>
@@ -2505,6 +2506,7 @@ static __latent_entropy struct task_struct *copy_process(
25052506

25062507
trace_task_newtask(p, clone_flags);
25072508
uprobe_copy_process(p, clone_flags);
2509+
user_events_fork(p, clone_flags);
25082510

25092511
copy_oom_score_adj(clone_flags, p);
25102512

0 commit comments

Comments
 (0)