probes: Fixes for v6.12-rc4-2
Hi Linus,
Probes fixes for v6.12-rc4(2):
- objpool: Fix choosing allocation for percpu slots
Fixes to allocate objpool's percpu slots correctly according to the GFP flag. It checks whether "any bit" in GFP_ATOMIC is set to choose the vmalloc source, but it should check "all bits" in GFP_ATOMIC flag is set, because GFP_ATOMIC is a combined flag.
- tracing/probes: Fix MAX_TRACE_ARGS limit handling
If more than MAX_TRACE_ARGS are passed for creating a probe event, the entries over MAX_TRACE_ARG in trace_arg array are not initialized. Thus if the kernel accesses those entries, it crashes. This rejects creating event if the number of arguments is over MAX_TRACE_ARGS.
- tracing: Consider the NULL character when validating the event length A strlen() is used when parsing the event name, and the original code does not consider the terminal null byte. Thus it can pass the name 1 byte longer than the buffer. This fixes to check it correctly.
Please pull the latest probes-fixes-v6.12-rc4.2 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
probes-fixes-v6.12-rc4.2
Tag SHA1: 62eeda86599cd8c8fe92b4bc6181ef6d2c1e6e03 Head SHA1: 0b6e2e22cb23105fcb171ab92f0f7516c69c8471
Leo Yan (1):
tracing: Consider the NULL character when validating the event length
Mikel Rychliski (1):
tracing/probes: Fix MAX_TRACE_ARGS limit handling
Viktor Malik (1):
objpool: fix choosing allocation for percpu slots
----
kernel/trace/trace_eprobe.c | 7 ++++++- kernel/trace/trace_fprobe.c | 6 +++++- kernel/trace/trace_kprobe.c | 6 +++++- kernel/trace/trace_probe.c | 2 +- kernel/trace/trace_uprobe.c | 4 +++- lib/objpool.c | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-)
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 7 lines · Masami Hiramatsu
- objpool: Fix choosing allocation for percpu slots
Fixes to allocate objpool's percpu slots correctly according to the GFP flag. It checks whether "any bit" in
GFP_ATOMICis set to choose the vmalloc source, but it should check "all bits" inGFP_ATOMICflag is set, becauseGFP_ATOMICis a combined flag.
So the old code was buggy, but I don't think the new code is wonderful either.
For example, it does not recognized GFP_NOWAIT, which has very similar characteristics to GFP_ATOMIC (it's basically the same thing as GFP_ATOMIC, but without the "try to allocate urgently", and with an added "don't warn on failure" as a result).
So what I think that code *should* test for is "can I sleep".
Which is indicated by __GFP_IO or __GFP_FS (and, I guess also __GFP_DIRECT_RECLAIM).
Linus
Quoted 10 lines · On Thu, 24 Oct 2024 14:05:08 -0700 Linus Torvalds…
Quoted 7 lines · Masami Hiramatsu
- objpool: Fix choosing allocation for percpu slots
Fixes to allocate objpool's percpu slots correctly according to the GFP flag. It checks whether "any bit" in
GFP_ATOMICis set to choose the vmalloc source, but it should check "all bits" inGFP_ATOMICflag is set, becauseGFP_ATOMICis a combined flag.So the old code was buggy, but I don't think the new code is wonderful either.
Agreed.
Quoted 10 lines
For example, it does not recognized
GFP_NOWAIT, which has very similar characteristics toGFP_ATOMIC(it's basically the same thing asGFP_ATOMIC, but without the "try to allocate urgently", and with an added "don't warn on failure" as a result).So what I think that code *should* test for is "can I sleep".
Which is indicated by
__GFP_IOor__GFP_FS(and, I guess also__GFP_DIRECT_RECLAIM).
This code is for switching __vmalloc_node() to kmalloc_node() based on GFP_ATOMIC, because __vmalloc_node() does not support GFP_ATOMIC.
---
/**
* __vmalloc_node_range - allocate virtually contiguous memory
...
*
* Allocate enough pages to cover @size from the page level
* allocator with @gfp_mask flags. Please note that the full set of gfp
* flags are not supported. GFP_KERNEL, GFP_NOFS and GFP_NOIO are all
* supported.
---
(BTW, the above kerneldoc is a bit outdated, because the function name has been changed to __vmalloc_node_range_noprof())
As above said, it supports GFP_KENEL & GFP_NOFS & GFP_NOIO, which means __GFP_RECLAIM (= ___GFP_DIRECT_RECLAIM|___GFP_KSWAPD_RECLAIM) is required.
Since GFP_ATOMIC is __GFP_HIGH | __GFP_KSWAPD_RECLAIM, the difference is ___GFP_DIRECT_RECLAIM is not set if GFP_ATOMIC is specified.
But I don't want to touch such bitflags deeper. What about simply masking with GFP_ATOMIC | GFP_KERNEL? I mean
if ((gfp & (GFP_ATOMIC | GFP_KERNEL)) == GFP_ATOMIC)
/* use kmalloc_node() because vmalloc does not support GFP_ATOMIC */ slot = kmalloc_node(...) else slot = __vmalloc_node(...)
Or, simply failback to kmalloc_node() if __vmalloc_node() fails. (I think this is more robust.)
slot = __vmalloc_node(...)
if (!slot)
slot = kmalloc_node(...)
(Note that slot is freed by kvfree() so either works)
Thank you,
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
The pull request you sent on Wed, 23 Oct 2024 23:36:00 +0900:
The pull request you sent on Wed, 23 Oct 2024 23:36:00 +0900:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.gitprobes-fixes-v6.12-rc4.2
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/c2cd8e4592c04b6725611ccce60f2d0f85383f09
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html