[PATCH 6/6] ftrace: Revert the FTRACE_MCOUNT_MAX_OFFSET workaround

2024-06-13 Thread Zheng Yejian
9181f7c690 ("ftrace: Add FTRACE_MCOUNT_MAX_OFFSET to avoid adding weak function") 2. commit 7af82ff90a2b ("powerpc/ftrace: Ignore weak functions") 3. commit f6834c8c59a8 ("powerpc/ftrace: Fix dropping weak symbols with older toolchains") Signed-off-by: Zheng Yejian

[PATCH 3/6] module: kallsyms: Determine exact function size

2024-06-13 Thread Zheng Yejian
this issue, check that an given address is within the size of the function found. Signed-off-by: Zheng Yejian --- include/linux/module.h | 7 +++ kernel/module/kallsyms.c | 19 +-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/linux/module.h b/include

[PATCH 5/6] ftrace: Fix possible out-of-bound issue in ftrace_process_locs()

2024-06-13 Thread Zheng Yejian
quot;) Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 18 +- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 0e8628e4d296..c46c35ac9b42 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -657

[PATCH 1/6] kallsyms: Optimize multiple times of realloc() to one time of malloc()

2024-06-13 Thread Zheng Yejian
is generally 10+ times. As an optimization, introduce linked list 'sym_list' to associate and count all symbols, then store them into 'table' at one time. Signed-off-by: Zheng Yejian --- scripts/kallsyms.c | 33 - 1 file changed, 20 insertions(+), 13 deletions(-) diff

[PATCH 0/6] kallsyms: Emit symbol for holes in text and fix weak function issue

2024-06-13 Thread Zheng Yejian
T solution, also two related definition for powerpc. [1] https://lore.kernel.org/all/20240607150228.gr8...@noisy.programming.kicks-ass.net/ [2] https://lore.kernel.org/all/20240611092157.gu40...@noisy.programming.kicks-ass.net/ Zheng Yejian (6): kallsyms: Optimize multiple times of realloc() to o

[PATCH 4/6] ftrace: Skip invalid __fentry__ in ftrace_process_locs()

2024-06-13 Thread Zheng Yejian
Fixes: aebfd12521d9 ("x86/ibt,ftrace: Search for __fentry__ location") Signed-off-by: Zheng Yejian --- include/linux/kallsyms.h | 13 + include/linux/module.h | 7 +++ kernel/module/kallsyms.c | 23 +-- kernel/trace/ftrace.c| 15 ++-

[PATCH 2/6] kallsyms: Emit symbol at the holes in the text

2024-06-13 Thread Zheng Yejian
d-by: Peter Zijlstra Signed-off-by: Zheng Yejian --- scripts/kallsyms.c | 101 +++- scripts/link-vmlinux.sh | 4 +- scripts/mksysmap| 2 +- 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.

Re: [RFC PATCH] ftrace: Skip __fentry__ location of overridden weak functions

2024-06-11 Thread Zheng Yejian
On 2024/6/11 17:21, Peter Zijlstra wrote: On Tue, Jun 11, 2024 at 09:56:51AM +0800, Zheng Yejian wrote: On 2024/6/7 23:02, Peter Zijlstra wrote: Oh gawd, sodding weak functions again. I would suggest changing scipts/kallsyms.c to emit readily identifiable symbol names for all the weak junk

Re: [RFC PATCH] ftrace: Skip __fentry__ location of overridden weak functions

2024-06-10 Thread Zheng Yejian
On 2024/6/7 23:02, Peter Zijlstra wrote: On Fri, Jun 07, 2024 at 07:52:11PM +0800, Zheng Yejian wrote: ftrace_location() was changed to not only return the __fentry__ location when called for the __fentry__ location, but also when called for the sym+0 location after commit aebfd12521d9 (&quo

[RFC PATCH] ftrace: Skip __fentry__ location of overridden weak functions

2024-06-07 Thread Zheng Yejian
ry record in __mount_loc table will slow down system boot and module load. Solution 1 and 2 need every arch to handle the complex fentry location case, I use solution 3 as RFC. Fixes: aebfd12521d9 ("x86/ibt,ftrace: Search for __fentry__ location") Signed-off-by: Zheng Yejian --- includ

[PATCH v4] ftrace: Fix possible use-after-free issue in ftrace_location()

2024-05-09 Thread Zheng Yejian
()/ftrace_free_mem(). Fixes: ae6aa16fdc16 ("kprobes: introduce ftrace based optimization") Suggested-by: Steven Rostedt Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 39 +++ 1 file changed, 23 insertions(+), 16 deletions(-) v4: - Simp

Re: [PATCH v3] ftrace: Fix possible use-after-free issue in ftrace_location()

2024-05-08 Thread Zheng Yejian
On 2024/5/3 05:07, Steven Rostedt wrote: On Wed, 17 Apr 2024 11:28:30 +0800 Zheng Yejian wrote: diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index da1710499698..e05d3e3dc06a 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1581,7 +1581,7 @@ static struct

[PATCH v3] ftrace: Fix possible use-after-free issue in ftrace_location()

2024-04-16 Thread Zheng Yejian
()/ftrace_free_mem(). Fixes: ae6aa16fdc16 ("kprobes: introduce ftrace based optimization") Suggested-by: Steven Rostedt Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 46 --- 1 file changed, 30 insertions(+), 16 deletions(-) v3:

[PATCH v2] ftrace: Fix possible use-after-free issue in ftrace_location()

2024-04-16 Thread Zheng Yejian
, and call synchronize_rcu() before freeing any ftrace pages. Fixes: ae6aa16fdc16 ("kprobes: introduce ftrace based optimization") Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 43 +++ 1 file changed, 27 insertions(+), 16 deletions(-) v2:

Re: [PATCH] ftrace: Fix use-after-free issue in ftrace_location()

2024-04-10 Thread Zheng Yejian
On 2024/4/10 23:28, Steven Rostedt wrote: On Mon, 1 Apr 2024 20:55:43 +0800 Zheng Yejian wrote: KASAN reports a bug: BUG: KASAN: use-after-free in ftrace_location+0x90/0x120 Read of size 8 at addr 888141d40010 by task insmod/424 CPU: 8 PID: 424 Comm: insmod Tainted: GW

[PATCH v3] kprobes: Fix possible use-after-free issue on kprobe registration

2024-04-09 Thread Zheng Yejian
text_address()` and `__module_text_address()`, but use only `__module_text_address()` once and do `try_module_get(module)` which is only available with MODULE_STATE_LIVE. Signed-off-by: Zheng Yejian --- kernel/kprobes.c | 18 -- 1 file changed, 12 insertions(+), 6 deletions(-) v

Re: [PATCH v2] kprobes: Avoid possible warn in __arm_kprobe_ftrace()

2024-04-09 Thread Zheng Yejian
On 2024/4/9 21:49, Masami Hiramatsu (Google) wrote: On Tue, 9 Apr 2024 14:20:45 +0800 Zheng Yejian wrote: On 2024/4/8 20:41, Masami Hiramatsu (Google) wrote: Hi Zheng, On Mon, 8 Apr 2024 16:34:03 +0800 Zheng Yejian wrote: There is once warn in __arm_kprobe_ftrace() on: ret

Re: [PATCH v2] kprobes: Avoid possible warn in __arm_kprobe_ftrace()

2024-04-09 Thread Zheng Yejian
On 2024/4/8 20:41, Masami Hiramatsu (Google) wrote: Hi Zheng, On Mon, 8 Apr 2024 16:34:03 +0800 Zheng Yejian wrote: There is once warn in __arm_kprobe_ftrace() on: ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); if (WARN_ONCE(..., "Failed to arm kprobe-ftrac

[PATCH v2] kprobes: Avoid possible warn in __arm_kprobe_ftrace()

2024-04-08 Thread Zheng Yejian
ret = -EINVAL; goto out; } Signed-off-by: Zheng Yejian --- kernel/kprobes.c | 18 -- 1 file changed, 12 insertions(+), 6 deletions(-) v2: - Update commit messages and comments as suggested by Masami. Link: https://lore.kernel.org/all/20240408115038.b0c857

Re: [PATCH] kprobes: Fix possible warn in __arm_kprobe_ftrace()

2024-04-07 Thread Zheng Yejian
On 2024/4/8 10:50, Masami Hiramatsu (Google) wrote: On Sun, 7 Apr 2024 11:59:04 +0800 Zheng Yejian wrote: There is once warn in __arm_kprobe_ftrace() on: ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); if (WARN_ONCE(..., "Failed to arm kprobe-ftrace at %pS (err

[PATCH] kprobes: Fix possible warn in __arm_kprobe_ftrace()

2024-04-06 Thread Zheng Yejian
hen //the return value would still be 0 !!! *probed_mod = __module_text_address((unsigned long) p->addr); ... } So adjust the module text check to fix it. Signed-off-by: Zheng Yejian --- kernel/kprobes.c | 13 + 1 file changed, 9 insertions(+), 4 deletions(-) dif

[PATCH] ftrace: Fix use-after-free issue in ftrace_location()

2024-04-01 Thread Zheng Yejian
records in ftrace_location(), so is ftrace_location_range(). Fixes: ae6aa16fdc16 ("kprobes: introduce ftrace based optimization") Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ke

[PATCH v3] tracing: Fix uaf issue when open the hist or hist_debug file

2023-12-13 Thread Zheng Yejian
el0_svc+0x34/0x68 el0t_64_sync_handler+0xb8/0xc0 el0t_64_sync+0x168/0x170 Suggested-by: Steven Rostedt Signed-off-by: Zheng Yejian --- kernel/trace/trace.c | 6 ++ kernel/trace/trace.h | 1 + kernel/trace/trace_events_hist.c | 12 3 files changed, 15

[PATCH v2] tracing: Fix uaf issue when open the hist or hist_debug file

2023-12-12 Thread Zheng Yejian
el0_svc+0x34/0x68 el0t_64_sync_handler+0xb8/0xc0 el0t_64_sync+0x168/0x170 Suggested-by: Steven Rostedt Signed-off-by: Zheng Yejian --- kernel/trace/trace_events_hist.c | 18 ++ 1 file changed, 14 insertions(+), 4 deletions(-) Steve, thanks for your review! v2: - Introduce

[PATCH] tracing: Fix uaf issue when open the hist or hist_debug file

2023-12-12 Thread Zheng Yejian
el0t_64_sync+0x168/0x170 Signed-off-by: Zheng Yejian --- kernel/trace/trace_events_hist.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 1abc07fba1b9..00447ea7dabd 100644 --- a/kernel/trace

[PATCH] ring-buffer: Fix bytes info in per_cpu buffer stats

2023-09-21 Thread Zheng Yejian
mments of ring_buffer_bytes_cpu() in this patch. Fixes: c64e148a3be3 ("trace: Add ring buffer stats to measure rate of events") Signed-off-by: Zheng Yejian --- kernel/trace/ring_buffer.c | 28 +++- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/kernel/tra

[PATCH] livepatch: Fix missing newline character in klp_resolve_symbols()

2023-09-14 Thread Zheng Yejian
Without the newline character, the log may not be printed immediately after the error occurs. Fixes: ca376a937486 ("livepatch: Prevent module-specific KLP rela sections from referencing vmlinux symbols") Signed-off-by: Zheng Yejian --- kernel/livepatch/core.c | 2 +- 1 file

[PATCH 4.4 v2 0/3] Backport patch series to update Futex from 4.9

2021-03-10 Thread Zheng Yejian
Changelog for 'v2': Complete commit messages with needed git commit ids as Greg and Lee suggested. Lee sent a patchset to update Futex for v4.9, see https://www.spinics.net/lists/stable/msg443081.html, Then Xiaoming sent a follow-up patch for it, see

[PATCH 4.4 v2 3/3] futex: fix dead code in attach_to_pi_owner()

2021-03-10 Thread Zheng Yejian
4409 ("futex: Provide distinct return value when owner is exiting") ... and is the correct fix for this issue. Fixes: 9c3f39860367 ("futex: Cure exit race") Cc: sta...@vger.kernel.org # v4.9.258 Signed-off-by: Xiaoming Ni Reviewed-by: Lee Jones Signed-off-by: Greg Kroah-Hartman Si

[PATCH 4.4 v2 2/3] futex: Cure exit race

2021-03-10 Thread Zheng Yejian
ned-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman Signed-off-by: Zheng Yejian --- kernel/futex.c | 71 +- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index b410752f5ad1..116766ef7de6 100644 --- a/ke

[PATCH 4.4 v2 1/3] futex: Change locking rules

2021-03-10 Thread Zheng Yejian
evious futex back-port attempt] Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman Signed-off-by: Zheng Yejian --- kernel/futex.c | 138 +++-- 1 file changed, 112 insertions(+), 26 deletions(-) diff --git a/kernel/futex.c b/kernel/f

[PATCH 4.4 2/3] futex: Cure exit race

2021-03-08 Thread Zheng Yejian
ee: Required to satisfy functional dependency from futex back-port. Re-add the missing handle_exit_race() parts from: 3d4775df0a89 ("futex: Replace PF_EXITPIDONE with a state")] Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman Signed-off-by: Zheng

[PATCH 4.4 1/3] futex: Change locking rules

2021-03-08 Thread Zheng Yejian
m Link: http://lkml.kernel.org/r/20170322104151.751993...@infradead.org Signed-off-by: Thomas Gleixner [Lee: Back-ported in support of a previous futex back-port attempt] Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman Signed-off-by: Zheng Yejian --- kernel/f

[PATCH 4.4 0/3] Backport patch series to update Futex from 4.9

2021-03-08 Thread Zheng Yejian
Lee sent a patchset to update Futex for 4.9, see https://www.spinics.net/lists/stable/msg443081.html, Then Xiaoming sent a follow-up patch for it, see https://lore.kernel.org/lkml/20210225093120.GD641347@dell/. These patchsets may also resolve following issues in 4.4.260 which have been

[PATCH 4.4 3/3] futex: fix dead code in attach_to_pi_owner()

2021-03-08 Thread Zheng Yejian
y: Xiaoming Ni Reviewed-by: Lee Jones Signed-off-by: Greg Kroah-Hartman Signed-off-by: Zheng Yejian --- kernel/futex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 116766ef7de6..98c65b3c3a00 100644 --- a/kernel/futex.c +++ b

[PATCH 4.9.y 0/1] Bugfix for 781691c797de ("futex: Avoid violating the 10th rule of futex")

2021-02-23 Thread Zheng Yejian
This patch may fix the following bug: Link: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/?h=linux-4.9.y=5b1d078507bd33ebf6c2083fa363cf5832809c19 > static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, > struct

[PATCH 4.9.y 1/1] futex: Fix OWNER_DEAD fixup

2021-02-23 Thread Zheng Yejian
Cc: Thomas Gleixner Fixes: c1e2f0eaf015 ("futex: Avoid violating the 10th rule of futex") Link: http://lkml.kernel.org/r/20180122103947.gd2...@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar Signed-off-by: Zheng Yejian --- kernel/futex.c | 6 +++--- 1 file changed, 3 insert

[PATCH 4.9.257 1/1] futex: Fix OWNER_DEAD fixup

2021-02-22 Thread Zheng Yejian
Cc: Thomas Gleixner Fixes: c1e2f0eaf015 ("futex: Avoid violating the 10th rule of futex") Link: http://lkml.kernel.org/r/20180122103947.gd2...@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar Signed-off-by: Zheng Yejian --- kernel/futex.c | 7 +++ 1 file changed, 3 insert

[PATCH 4.9.257 0/1] Bugfix for 781691c797de ("futex: Avoid violating the 10th rule of futex")

2021-02-22 Thread Zheng Yejian
This patch may fix the following bug: Link: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/kernel/futex.c?h=linux-4.9.y=282aeb477a10d09cc5c4d73c54bb996964723f96 > static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, >