File: shadow-newpid.patch

package info (click to toggle)
kpatch 0.9.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,716 kB
  • sloc: ansic: 9,716; sh: 2,592; makefile: 260; asm: 35
file content (72 lines) | stat: -rw-r--r-- 2,105 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Index: kernel/fs/proc/array.c
===================================================================
--- kernel.orig/fs/proc/array.c
+++ kernel/fs/proc/array.c
@@ -395,13 +395,20 @@ static inline void task_seccomp(struct s
 	seq_putc(m, '\n');
 }
 
+#include <linux/livepatch.h>
 static inline void task_context_switch_counts(struct seq_file *m,
 						struct task_struct *p)
 {
+	int *newpid;
+
 	seq_printf(m,	"voluntary_ctxt_switches:\t%lu\n"
 			"nonvoluntary_ctxt_switches:\t%lu\n",
 			p->nvcsw,
 			p->nivcsw);
+
+	newpid = klp_shadow_get(p, 0);
+	if (newpid)
+		seq_printf(m, "newpid:\t%d\n", *newpid);
 }
 
 static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
Index: kernel/kernel/exit.c
===================================================================
--- kernel.orig/kernel/exit.c
+++ kernel/kernel/exit.c
@@ -791,6 +791,7 @@ static void check_stack_usage(void)
 static inline void check_stack_usage(void) {}
 #endif
 
+#include <linux/livepatch.h>
 void do_exit(long code)
 {
 	struct task_struct *tsk = current;
@@ -888,6 +889,8 @@ void do_exit(long code)
 	check_stack_usage();
 	exit_thread();
 
+	klp_shadow_free(tsk, 0, NULL);
+
 	/*
 	 * Flush inherited counters to the parent - before the parent
 	 * gets woken up by child-exit notifications.
Index: kernel/kernel/fork.c
===================================================================
--- kernel.orig/kernel/fork.c
+++ kernel/kernel/fork.c
@@ -1760,6 +1760,7 @@ struct task_struct *fork_idle(int cpu)
  * It copies the process, and if successful kick-starts
  * it and waits for it to finish using the VM if required.
  */
+#include <linux/livepatch.h>
 long do_fork(unsigned long clone_flags,
 	      unsigned long stack_start,
 	      unsigned long stack_size,
@@ -1797,6 +1798,13 @@ long do_fork(unsigned long clone_flags,
 	if (!IS_ERR(p)) {
 		struct completion vfork;
 		struct pid *pid;
+		int *newpid;
+		static int ctr = 0;
+
+		newpid = klp_shadow_get_or_alloc(p, 0, sizeof(*newpid), GFP_KERNEL,
+						NULL, NULL);
+		if (newpid)
+			*newpid = ctr++;
 
 		trace_sched_process_fork(current, p);