Blame test/integration/rhel-8.0/shadow-newpid.patch.disabled

Packit Service da4517
Disabled due to https://github.com/dynup/kpatch/issues/940
Packit Service da4517
---
Packit Service da4517
diff --git a/fs/proc/array.c b/fs/proc/array.c
Packit Service da4517
index 0ceb3b6..1b44c7f 100644
Packit Service da4517
--- a/fs/proc/array.c
Packit Service da4517
+++ b/fs/proc/array.c
Packit Service da4517
@@ -370,12 +370,19 @@ static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
Packit Service da4517
 	seq_putc(m, '\n');
Packit Service da4517
 }
Packit Service da4517
 
Packit Service da4517
+#include <linux/livepatch.h>
Packit Service da4517
 static inline void task_context_switch_counts(struct seq_file *m,
Packit Service da4517
 						struct task_struct *p)
Packit Service da4517
 {
Packit Service da4517
+	int *newpid;
Packit Service da4517
+
Packit Service da4517
 	seq_put_decimal_ull(m, "voluntary_ctxt_switches:\t", p->nvcsw);
Packit Service da4517
 	seq_put_decimal_ull(m, "\nnonvoluntary_ctxt_switches:\t", p->nivcsw);
Packit Service da4517
 	seq_putc(m, '\n');
Packit Service da4517
+
Packit Service da4517
+	newpid = klp_shadow_get(p, 0);
Packit Service da4517
+	if (newpid)
Packit Service da4517
+		seq_printf(m, "newpid:\t%d\n", *newpid);
Packit Service da4517
 }
Packit Service da4517
 
Packit Service da4517
 static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
Packit Service da4517
diff --git a/kernel/exit.c b/kernel/exit.c
Packit Service da4517
index deaa53a..01f5776 100644
Packit Service da4517
--- a/kernel/exit.c
Packit Service da4517
+++ b/kernel/exit.c
Packit Service da4517
@@ -760,6 +760,7 @@ static void check_stack_usage(void)
Packit Service da4517
 static inline void check_stack_usage(void) {}
Packit Service da4517
 #endif
Packit Service da4517
 
Packit Service da4517
+#include <linux/livepatch.h>
Packit Service da4517
 void __noreturn do_exit(long code)
Packit Service da4517
 {
Packit Service da4517
 	struct task_struct *tsk = current;
Packit Service da4517
@@ -865,6 +866,8 @@ void __noreturn do_exit(long code)
Packit Service da4517
 	exit_task_work(tsk);
Packit Service da4517
 	exit_thread(tsk);
Packit Service da4517
 
Packit Service da4517
+	klp_shadow_free(tsk, 0, NULL);
Packit Service da4517
+
Packit Service da4517
 	/*
Packit Service da4517
 	 * Flush inherited counters to the parent - before the parent
Packit Service da4517
 	 * gets woken up by child-exit notifications.
Packit Service da4517
diff --git a/kernel/fork.c b/kernel/fork.c
Packit Service da4517
index 3311231..2c12c1a 100644
Packit Service da4517
--- a/kernel/fork.c
Packit Service da4517
+++ b/kernel/fork.c
Packit Service da4517
@@ -2093,6 +2093,7 @@ struct task_struct *fork_idle(int cpu)
Packit Service da4517
  * It copies the process, and if successful kick-starts
Packit Service da4517
  * it and waits for it to finish using the VM if required.
Packit Service da4517
  */
Packit Service da4517
+#include <linux/livepatch.h>
Packit Service da4517
 long _do_fork(unsigned long clone_flags,
Packit Service da4517
 	      unsigned long stack_start,
Packit Service da4517
 	      unsigned long stack_size,
Packit Service da4517
@@ -2105,6 +2106,8 @@ long _do_fork(unsigned long clone_flags,
Packit Service da4517
 	struct task_struct *p;
Packit Service da4517
 	int trace = 0;
Packit Service da4517
 	long nr;
Packit Service da4517
+	int *newpid;
Packit Service da4517
+	static int ctr = 0;
Packit Service da4517
 
Packit Service da4517
 	/*
Packit Service da4517
 	 * Determine whether and which event to report to ptracer.  When
Packit Service da4517
@@ -2131,6 +2134,11 @@ long _do_fork(unsigned long clone_flags,
Packit Service da4517
 	if (IS_ERR(p))
Packit Service da4517
 		return PTR_ERR(p);
Packit Service da4517
 
Packit Service da4517
+	newpid = klp_shadow_get_or_alloc(p, 0, sizeof(*newpid), GFP_KERNEL,
Packit Service da4517
+					 NULL, NULL);
Packit Service da4517
+	if (newpid)
Packit Service da4517
+		*newpid = ctr++;
Packit Service da4517
+
Packit Service da4517
 	/*
Packit Service da4517
 	 * Do this prior waking up the new thread - the thread pointer
Packit Service da4517
 	 * might get invalid after that point, if the thread exits quickly.