| 1 |
Disabled due to https://github.com/dynup/kpatch/issues/940 |
| 2 |
--- |
| 3 |
diff -Nupr src.orig/fs/proc/array.c src/fs/proc/array.c |
| 4 |
--- src.orig/fs/proc/array.c 2020-03-17 01:12:55.154895731 -0400 |
| 5 |
+++ src/fs/proc/array.c 2020-03-17 01:14:09.668569881 -0400 |
| 6 |
@@ -370,12 +370,19 @@ static inline void task_seccomp(struct s |
| 7 |
seq_putc(m, '\n'); |
| 8 |
} |
| 9 |
|
| 10 |
+#include <linux/livepatch.h> |
| 11 |
static inline void task_context_switch_counts(struct seq_file *m, |
| 12 |
struct task_struct *p) |
| 13 |
{ |
| 14 |
+ int *newpid; |
| 15 |
+ |
| 16 |
seq_put_decimal_ull(m, "voluntary_ctxt_switches:\t", p->nvcsw); |
| 17 |
seq_put_decimal_ull(m, "\nnonvoluntary_ctxt_switches:\t", p->nivcsw); |
| 18 |
seq_putc(m, '\n'); |
| 19 |
+ |
| 20 |
+ newpid = klp_shadow_get(p, 0); |
| 21 |
+ if (newpid) |
| 22 |
+ seq_printf(m, "newpid:\t%d\n", *newpid); |
| 23 |
} |
| 24 |
|
| 25 |
static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) |
| 26 |
diff -Nupr src.orig/kernel/exit.c src/kernel/exit.c |
| 27 |
--- src.orig/kernel/exit.c 2020-03-17 01:12:55.490921320 -0400 |
| 28 |
+++ src/kernel/exit.c 2020-03-17 01:14:09.668569881 -0400 |
| 29 |
@@ -762,6 +762,7 @@ static void check_stack_usage(void) |
| 30 |
static inline void check_stack_usage(void) {} |
| 31 |
#endif |
| 32 |
|
| 33 |
+#include <linux/livepatch.h> |
| 34 |
void __noreturn do_exit(long code) |
| 35 |
{ |
| 36 |
struct task_struct *tsk = current; |
| 37 |
@@ -868,6 +869,8 @@ void __noreturn do_exit(long code) |
| 38 |
exit_thread(tsk); |
| 39 |
exit_umh(tsk); |
| 40 |
|
| 41 |
+ klp_shadow_free(tsk, 0, NULL); |
| 42 |
+ |
| 43 |
/* |
| 44 |
* Flush inherited counters to the parent - before the parent |
| 45 |
* gets woken up by child-exit notifications. |
| 46 |
diff -Nupr src.orig/kernel/fork.c src/kernel/fork.c |
| 47 |
--- src.orig/kernel/fork.c 2020-03-17 01:12:55.500922081 -0400 |
| 48 |
+++ src/kernel/fork.c 2020-03-17 01:14:09.668569881 -0400 |
| 49 |
@@ -2206,6 +2206,7 @@ struct task_struct *fork_idle(int cpu) |
| 50 |
* It copies the process, and if successful kick-starts |
| 51 |
* it and waits for it to finish using the VM if required. |
| 52 |
*/ |
| 53 |
+#include <linux/livepatch.h> |
| 54 |
long _do_fork(unsigned long clone_flags, |
| 55 |
unsigned long stack_start, |
| 56 |
unsigned long stack_size, |
| 57 |
@@ -2218,6 +2219,8 @@ long _do_fork(unsigned long clone_flags, |
| 58 |
struct task_struct *p; |
| 59 |
int trace = 0; |
| 60 |
long nr; |
| 61 |
+ int *newpid; |
| 62 |
+ static int ctr = 0; |
| 63 |
|
| 64 |
/* |
| 65 |
* Determine whether and which event to report to ptracer. When |
| 66 |
@@ -2244,6 +2247,11 @@ long _do_fork(unsigned long clone_flags, |
| 67 |
if (IS_ERR(p)) |
| 68 |
return PTR_ERR(p); |
| 69 |
|
| 70 |
+ newpid = klp_shadow_get_or_alloc(p, 0, sizeof(*newpid), GFP_KERNEL, |
| 71 |
+ NULL, NULL); |
| 72 |
+ if (newpid) |
| 73 |
+ *newpid = ctr++; |
| 74 |
+ |
| 75 |
/* |
| 76 |
* Do this prior waking up the new thread - the thread pointer |
| 77 |
* might get invalid after that point, if the thread exits quickly. |