[PATCH v2] tracing: Avoid possible softlockup in tracing_iter_reset()

2024-08-27 Thread Zheng Yejian
many entries were skipped in the loop that reset every cpu buffer, so add cond_resched() to avoid it. Suggested-by: Steven Rostedt Signed-off-by: Zheng Yejian --- kernel/trace/trace.c | 2 ++ 1 file changed, 2 insertions(+) v2: - Change to add cond_resched() in tracing_iter_reset() Link

Re: [PATCH] tracing: Mitigate possible softlockup in __tracing_open()

2024-08-26 Thread Zheng Yejian
On 2024/8/26 22:35, Steven Rostedt wrote: On Sat, 24 Aug 2024 11:03:43 +0800 Zheng Yejian wrote: In __tracing_open(), when max latency tracers took place on the cpu, the time start of its buffer would be updated, then event entries with timestamps being earlier than start of the buffer would

Re: [PATCH] tracing: Mitigate possible softlockup in __tracing_open()

2024-08-25 Thread Zheng Yejian
On 2024/8/25 23:05, Masami Hiramatsu (Google) wrote: On Sat, 24 Aug 2024 11:03:43 +0800 Zheng Yejian wrote: In __tracing_open(), when max latency tracers took place on the cpu, the time start of its buffer would be updated, then event entries with timestamps being earlier than start of the

[PATCH] tracing: Mitigate possible softlockup in __tracing_open()

2024-08-23 Thread Zheng Yejian
many entries were skipped in the loop that reset every cpu buffer, so add cond_resched() to avoid it. Signed-off-by: Zheng Yejian --- kernel/trace/trace.c | 9 + 1 file changed, 9 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index ebe7ce2f5f4a..88faa95b457b

[PATCH v2 1/5] kallsyms: Emit symbol at the holes in the text

2024-07-22 Thread Zheng Yejian
-by: Peter Zijlstra Suggested-by: Masahiro Yamada Signed-off-by: Zheng Yejian --- scripts/kallsyms.c | 94 +++-- scripts/link-vmlinux.sh | 4 +- scripts/mksysmap| 2 +- 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/scripts/kallsyms.c

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

2024-07-22 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 fff5d3466c41..6947be8801d9 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -708

[PATCH v2 3/5] ftrace: Skip invalid __fentry__ in ftrace_process_locs()

2024-07-22 Thread Zheng Yejian
will find module of the passed address first, but as ftrace_process_locs() is called, the module has not been fully loaded, so those lookup functions can not work. Fixes: aebfd12521d9 ("x86/ibt,ftrace: Search for __fentry__ location") Signed-off-by: Zheng Yejian --- include/linu

[PATCH v2 5/5] ftrace: Revert the FTRACE_MCOUNT_MAX_OFFSET workaround

2024-07-22 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 v2 2/5] module: kallsyms: Determine exact function size

2024-07-22 Thread Zheng Yejian
issue, check that 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/linux

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

2024-07-22 Thread Zheng Yejian
ll/cak7lnarir5z9hprg932t7yjrwqkx_qz7wkmbxx7ito2w5yj...@mail.gmail.com/ - Changes in PATCH 3/5: - Now name of hole symbol is NULL, so if __fentry__ is located in a hole, kallsyms_lookup() find an NULL name then will return 0, so drop the needless kallsyms_is_hole_symbol(). Zheng Yejia

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

2024-07-21 Thread Zheng Yejian
On 2024/7/20 22:14, Masahiro Yamada wrote: On Thu, Jul 18, 2024 at 12:45 PM Zheng Yejian wrote: On 2024/7/16 16:33, Masahiro Yamada wrote: On Thu, Jun 13, 2024 at 10:36 PM Zheng Yejian wrote: When a weak type function is overridden, its symbol will be removed from the symbol table, but

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

2024-07-17 Thread Zheng Yejian
On 2024/7/16 16:33, Masahiro Yamada wrote: On Thu, Jun 13, 2024 at 10:36 PM Zheng Yejian wrote: When a weak type function is overridden, its symbol will be removed from the symbol table, but its code will not be removed. Besides, due to lacking of size for kallsyms, kernel compute function

[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
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
hat the expansion 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,

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

2024-06-13 Thread Zheng Yejian
_MAX_OFFSET 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 real

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

2024-06-13 Thread Zheng Yejian
not work. 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
fs_context Suggested-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

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
f every 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 --- i

[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: - Co

[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-08 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
d long) p->addr)) { // check again! 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://l

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
d_mod is NULL, but then //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(+),

[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
mon.constprop.0+0xb0/0x280 do_el0_svc+0x44/0x60 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_ev

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

2023-12-12 Thread Zheng Yejian
mon.constprop.0+0xb0/0x280 do_el0_svc+0x44/0x60 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(-)

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

2023-12-12 Thread Zheng Yejian
4/0x68 el0t_64_sync_handler+0xb8/0xc0 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

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

2023-09-21 Thread Zheng Yejian
nting for page-based read/remove/overrun. Also correct the comments 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 fi

[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 https://lore.kernel.org/lkml/20210225093120

[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
")] Signed-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

[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
oah-Hartman [Lee: 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 Signe

[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 reporte

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

2021-03-08 Thread Zheng Yejian
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&id=5b1d078507bd33ebf6c2083fa363cf5832809c19 > static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, > struct task_

[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&id=282aeb477a10d09cc5c4d73c54bb996964723f96 > static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q, >