mirror of
https://github.com/dynup/kpatch
synced 2025-02-25 22:40:41 +00:00
Rebased to kernel-4.18.0-304.el8. Note: since RHEL-8.4 dropped klp.arch support, we can now re-enable those tests that reference static keys defined in vmlinux. Also, adjust for adjust for ppc64le inlining: Building gcc-static-local-var-4.patch on ppc64le results in test failure, as the kpatch .ko now contains a 'free_ioctx' symbol (the test expects to NOT see one). From the build log: aio.o: changed function: free_ioctx aio.o: new function: put_aio_ring_file << now un-inlined? aio.o: changed function: aio_free_ring aio.o: changed function: ioctx_alloc aio.o: changed function: aio_prep_rw aio.o: changed function: aio_read_events aio.o: new function: kpatch_aio_foo << expected new function and a source code change to free_ioctx(): % diff -upr \ <(objdump -D -j .text.free_ioctx ~/.kpatch/tmp/orig/fs/aio.o) \ <(objdump -D -j .text.free_ioctx ~/.kpatch/tmp/patched/fs/aio.o) --- /dev/fd/63 2020-10-26 14:28:18.086236019 -0400 +++ /dev/fd/62 2020-10-26 14:28:18.086236019 -0400 @@ -1,5 +1,5 @@ -/root/.kpatch/tmp/orig/fs/aio.o: file format elf64-powerpcle +/root/.kpatch/tmp/patched/fs/aio.o: file format elf64-powerpcle Disassembly of section .text.free_ioctx: @@ -53,7 +53,7 @@ Disassembly of section .text.free_ioctx: b0: 00 00 82 3c addis r4,r2,0 b4: 00 00 84 e8 ld r4,0(r4) b8: 78 fb e6 7f mr r6,r31 - bc: e0 00 63 38 addi r3,r3,224 + bc: 38 00 63 38 addi r3,r3,56 c0: 01 00 00 48 bl c0 <free_ioctx+0xb8> c4: 00 00 00 60 nop c8: 70 ff ff 4b b 38 <free_ioctx+0x30> Marking put_aio_ring_file() as __always_inline keeps the r3 / 224 offset value, leaving free_ioctx() unchanged. Since it's no longer included in the resulting .ko, gcc-static-local-var-4.test will pass once again. Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
76 lines
2.4 KiB
Diff
76 lines
2.4 KiB
Diff
diff -Nupr src.orig/fs/proc/array.c src/fs/proc/array.c
|
|
--- src.orig/fs/proc/array.c 2021-04-20 11:04:26.717100594 -0400
|
|
+++ src/fs/proc/array.c 2021-04-20 11:05:18.430230343 -0400
|
|
@@ -370,12 +370,19 @@ 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_put_decimal_ull(m, "voluntary_ctxt_switches:\t", p->nvcsw);
|
|
seq_put_decimal_ull(m, "\nnonvoluntary_ctxt_switches:\t", p->nivcsw);
|
|
seq_putc(m, '\n');
|
|
+
|
|
+ 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)
|
|
diff -Nupr src.orig/kernel/exit.c src/kernel/exit.c
|
|
--- src.orig/kernel/exit.c 2021-04-20 11:04:27.314102092 -0400
|
|
+++ src/kernel/exit.c 2021-04-20 11:05:18.430230343 -0400
|
|
@@ -701,6 +701,7 @@ static void check_stack_usage(void)
|
|
static inline void check_stack_usage(void) {}
|
|
#endif
|
|
|
|
+#include <linux/livepatch.h>
|
|
void __noreturn do_exit(long code)
|
|
{
|
|
struct task_struct *tsk = current;
|
|
@@ -794,6 +795,8 @@ void __noreturn do_exit(long code)
|
|
exit_task_work(tsk);
|
|
exit_thread(tsk);
|
|
|
|
+ klp_shadow_free(tsk, 0, NULL);
|
|
+
|
|
/*
|
|
* Flush inherited counters to the parent - before the parent
|
|
* gets woken up by child-exit notifications.
|
|
diff -Nupr src.orig/kernel/fork.c src/kernel/fork.c
|
|
--- src.orig/kernel/fork.c 2021-04-20 11:04:27.315102095 -0400
|
|
+++ src/kernel/fork.c 2021-04-20 11:05:18.431230346 -0400
|
|
@@ -2222,6 +2222,7 @@ struct mm_struct *copy_init_mm(void)
|
|
* 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,
|
|
@@ -2234,6 +2235,8 @@ long _do_fork(unsigned long clone_flags,
|
|
struct task_struct *p;
|
|
int trace = 0;
|
|
long nr;
|
|
+ int *newpid;
|
|
+ static int ctr = 0;
|
|
|
|
/*
|
|
* Determine whether and which event to report to ptracer. When
|
|
@@ -2260,6 +2263,11 @@ long _do_fork(unsigned long clone_flags,
|
|
if (IS_ERR(p))
|
|
return PTR_ERR(p);
|
|
|
|
+ newpid = klp_shadow_get_or_alloc(p, 0, sizeof(*newpid), GFP_KERNEL,
|
|
+ NULL, NULL);
|
|
+ if (newpid)
|
|
+ *newpid = ctr++;
|
|
+
|
|
/*
|
|
* Do this prior waking up the new thread - the thread pointer
|
|
* might get invalid after that point, if the thread exits quickly.
|