From: Kefeng Wang <hidden> Date: 2021-07-28 08:07:16
There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.
1. cleanup arch specific text/data check and fix address boundary check
in kallsyms.h
2. make all the basic/core kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify
the code
After this series, we have 5 APIs about kernel sections range check in
sections.h
* is_kernel_core_data() --- come from core_kernel_data() in kernel.h
* is_kernel_rodata() --- already in sections.h
* is_kernel_text() --- come from kallsyms.h
* is_kernel_inittext() --- come from kernel.h and kallsyms.h
* is_kernel() --- come from kallsyms.h
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Cc: iommu@lists.linux-foundation.org
Cc: bpf@vger.kernel.org
v2:
- add ACK/RW to patch2, and drop inappropriate fix tag
- keep 'core' to check kernel data, suggestted by Steven Rostedt
[off-list ref], rename is_kernel_data() to is_kernel_core_data()
- drop patch8 which is merged
- drop patch9 which is resend independently
v1:
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.wang@huawei.com
Kefeng Wang (7):
kallsyms: Remove arch specific text and data check
kallsyms: Fix address-checks for kernel related range
sections: Move and rename core_kernel_data() to is_kernel_core_data()
sections: Move is_kernel_inittext() into sections.h
kallsyms: Rename is_kernel() and is_kernel_text()
sections: Add new is_kernel() and is_kernel_text()
powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
arch/powerpc/mm/pgtable_32.c | 7 +---
arch/x86/kernel/unwind_orc.c | 2 +-
arch/x86/net/bpf_jit_comp.c | 2 +-
include/asm-generic/sections.h | 71 ++++++++++++++++++++++++++--------
include/linux/kallsyms.h | 21 +++-------
include/linux/kernel.h | 2 -
kernel/cfi.c | 2 +-
kernel/extable.c | 33 ++--------------
kernel/locking/lockdep.c | 3 --
kernel/trace/ftrace.c | 2 +-
mm/kasan/report.c | 2 +-
net/sysctl_net.c | 2 +-
12 files changed, 72 insertions(+), 77 deletions(-)
--
2.26.2
@@ -34,8 +34,7 @@ static inline int is_kernel_inittext(unsigned long addr)staticinlineintis_kernel_text(unsignedlongaddr){-if((addr>=(unsignedlong)_stext&&addr<=(unsignedlong)_etext)||-arch_is_kernel_text(addr))+if((addr>=(unsignedlong)_stext&&addr<=(unsignedlong)_etext))return1;returnin_gate_area_no_mm(addr);}
From: Kefeng Wang <hidden> Date: 2021-07-28 08:07:20
The is_kernel_inittext() and init_kernel_text() are with same
functionality, let's just keep is_kernel_inittext() and move
it into sections.h, then update all the callers.
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: x86@kernel.org
Signed-off-by: Kefeng Wang <redacted>
---
arch/x86/kernel/unwind_orc.c | 2 +-
include/asm-generic/sections.h | 14 ++++++++++++++
include/linux/kallsyms.h | 8 --------
include/linux/kernel.h | 1 -
kernel/extable.c | 12 ++----------
5 files changed, 17 insertions(+), 20 deletions(-)
@@ -62,14 +62,6 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)returne;}-intinit_kernel_text(unsignedlongaddr)-{-if(addr>=(unsignedlong)_sinittext&&-addr<(unsignedlong)_einittext)-return1;-return0;-}-intnotracecore_kernel_text(unsignedlongaddr){if(addr>=(unsignedlong)_stext&&
@@ -77,7 +69,7 @@ int notrace core_kernel_text(unsigned long addr)return1;if(system_state<SYSTEM_RUNNING&&-init_kernel_text(addr))+is_kernel_inittext(addr))return1;return0;}
@@ -94,7 +86,7 @@ int __kernel_text_address(unsigned long addr)*Sinceweareafterthemodule-symbolscheck,there's*nodangerofaddressoverlap:*/-if(init_kernel_text(addr))+if(is_kernel_inittext(addr))return1;return0;}
From: Kefeng Wang <hidden> Date: 2021-07-28 08:07:23
Use is_kernel_text() and is_kernel_inittext() helper to simplify code,
also drop etext, _stext, _sinittext, _einittext declaration which
already declared in section.h.
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <redacted>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Kefeng Wang <redacted>
---
arch/powerpc/mm/pgtable_32.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
From: Kefeng Wang <hidden> Date: 2021-07-28 08:07:25
The new is_kernel() check the kernel address ranges, and the
new is_kernel_text() check the kernel text section ranges.
Then use them to make some code clear.
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Kefeng Wang <redacted>
---
include/asm-generic/sections.h | 27 +++++++++++++++++++++++++++
include/linux/kallsyms.h | 4 ++--
kernel/extable.c | 3 +--
mm/kasan/report.c | 2 +-
4 files changed, 31 insertions(+), 5 deletions(-)
@@ -82,24 +82,6 @@ int notrace core_kernel_text(unsigned long addr)return0;}-/**-*core_kernel_data-tellifaddrpointstokerneldata-*@addr:addresstotest-*-*Returnstrueif@addrpassedinisfromthecorekerneldata-*section.-*-*Note:OnsomearchsitmayreturntrueforcoreRODATA,andfalse-*forothers.ButwillalwaysbetrueforcoreRWdata.-*/-intcore_kernel_data(unsignedlongaddr)-{-if(addr>=(unsignedlong)_sdata&&-addr<(unsignedlong)_edata)-return1;-return0;-}-int__kernel_text_address(unsignedlongaddr){if(kernel_text_address(addr))
From: Kefeng Wang <hidden> Date: 2021-07-28 08:07:35
The is_kernel[_text]() function check the address whether or not
in kernel[_text] ranges, also they will check the address whether
or not in gate area, so use better name.
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: bpf@vger.kernel.org
Signed-off-by: Kefeng Wang <redacted>
---
arch/x86/net/bpf_jit_comp.c | 2 +-
include/linux/kallsyms.h | 8 ++++----
kernel/cfi.c | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
@@ -372,7 +372,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,intbpf_arch_text_poke(void*ip,enumbpf_text_poke_typet,void*old_addr,void*new_addr){-if(!is_kernel_text((long)ip)&&+if(!is_kernel_text_or_gate_area((long)ip)&&!is_bpf_text_address((long)ip))/* BPF poking in modules is not supported */return-EINVAL;
@@ -41,9 +41,9 @@ static inline int is_kernel(unsigned long addr)staticinlineintis_ksym_addr(unsignedlongaddr){if(IS_ENABLED(CONFIG_KALLSYMS_ALL))-returnis_kernel(addr);+returnis_kernel_or_gate_area(addr);-returnis_kernel_text(addr)||is_kernel_inittext(addr);+returnis_kernel_text_or_gate_area(addr)||is_kernel_inittext(addr);}staticinlinevoid*dereference_symbol_descriptor(void*ptr)
From: Kefeng Wang <hidden> Date: 2021-07-28 08:07:37
The is_kernel_inittext/is_kernel_text/is_kernel function should not
include the end address(the labels _einittext, _etext and _end) when
check the address range, the issue exists since Linux v2.6.12.
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sergey Senozhatsky <redacted>
Cc: Petr Mladek <pmladek@suse.com>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Kefeng Wang <redacted>
---
include/linux/kallsyms.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
From: Steven Rostedt <rostedt@goodmis.org> Date: 2021-07-28 14:46:55
On Wed, 28 Jul 2021 16:13:15 +0800
Kefeng Wang [off-list ref] wrote:
The is_kernel_inittext/is_kernel_text/is_kernel function should not
include the end address(the labels _einittext, _etext and _end) when
check the address range, the issue exists since Linux v2.6.12.
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sergey Senozhatsky <redacted>
Cc: Petr Mladek <pmladek@suse.com>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Kefeng Wang <redacted>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-- Steve
From: Steven Rostedt <rostedt@goodmis.org> Date: 2021-07-28 15:28:41
On Wed, 28 Jul 2021 16:13:18 +0800
Kefeng Wang [off-list ref] wrote:
The is_kernel[_text]() function check the address whether or not
in kernel[_text] ranges, also they will check the address whether
or not in gate area, so use better name.
Do you know what a gate area is?
Because I believe gate area is kernel text, so the rename just makes it
redundant and more confusing.
-- Steve
From: Kefeng Wang <hidden> Date: 2021-07-29 02:00:59
On 2021/7/28 23:28, Steven Rostedt wrote:
On Wed, 28 Jul 2021 16:13:18 +0800
Kefeng Wang [off-list ref] wrote:
quoted
The is_kernel[_text]() function check the address whether or not
in kernel[_text] ranges, also they will check the address whether
or not in gate area, so use better name.
Do you know what a gate area is?
Because I believe gate area is kernel text, so the rename just makes it
redundant and more confusing.
Yes, the gate area(eg, vectors part on ARM32, similar on x86/ia64) is
kernel text.
I want to keep the 'basic' section boundaries check, which only check
the start/end
of sections, all in section.h, could we use 'generic' or 'basic' or
'core' in the naming?
* is_kernel_generic_data() --- come from core_kernel_data() in kernel.h
* is_kernel_generic_text()
The old helper could remain unchanged, any suggestion, thanks.
From: Kefeng Wang <hidden> Date: 2021-07-29 02:03:33
On 2021/7/28 22:46, Steven Rostedt wrote:
On Wed, 28 Jul 2021 16:13:15 +0800
Kefeng Wang [off-list ref] wrote:
quoted
The is_kernel_inittext/is_kernel_text/is_kernel function should not
include the end address(the labels _einittext, _etext and _end) when
check the address range, the issue exists since Linux v2.6.12.
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sergey Senozhatsky <redacted>
Cc: Petr Mladek <pmladek@suse.com>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Kefeng Wang <redacted>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
From: Steven Rostedt <rostedt@goodmis.org> Date: 2021-07-29 04:05:42
On Thu, 29 Jul 2021 10:00:51 +0800
Kefeng Wang [off-list ref] wrote:
On 2021/7/28 23:28, Steven Rostedt wrote:
quoted
On Wed, 28 Jul 2021 16:13:18 +0800
Kefeng Wang [off-list ref] wrote:
quoted
The is_kernel[_text]() function check the address whether or not
in kernel[_text] ranges, also they will check the address whether
or not in gate area, so use better name.
Do you know what a gate area is?
Because I believe gate area is kernel text, so the rename just makes it
redundant and more confusing.
Yes, the gate area(eg, vectors part on ARM32, similar on x86/ia64) is
kernel text.
I want to keep the 'basic' section boundaries check, which only check
the start/end
of sections, all in section.h, could we use 'generic' or 'basic' or
'core' in the naming?
* is_kernel_generic_data() --- come from core_kernel_data() in kernel.h
* is_kernel_generic_text()
The old helper could remain unchanged, any suggestion, thanks.
Because it looks like the check of just being in the range of "_stext"
to "_end" is just an internal helper, why not do what we do all over
the kernel, and just prefix the function with a couple of underscores,
that denote that it's internal?
__is_kernel_text()
Then you have:
static inline int is_kernel_text(unsigned long addr)
{
if (__is_kernel_text(addr))
return 1;
return in_gate_area_no_mm(addr);
}
-- Steve
From: Kefeng Wang <hidden> Date: 2021-07-29 11:06:14
On 2021/7/29 12:05, Steven Rostedt wrote:
On Thu, 29 Jul 2021 10:00:51 +0800
Kefeng Wang [off-list ref] wrote:
quoted
On 2021/7/28 23:28, Steven Rostedt wrote:
quoted
On Wed, 28 Jul 2021 16:13:18 +0800
Kefeng Wang [off-list ref] wrote:
quoted
The is_kernel[_text]() function check the address whether or not
in kernel[_text] ranges, also they will check the address whether
or not in gate area, so use better name.
Do you know what a gate area is?
Because I believe gate area is kernel text, so the rename just makes it
redundant and more confusing.
Yes, the gate area(eg, vectors part on ARM32, similar on x86/ia64) is
kernel text.
I want to keep the 'basic' section boundaries check, which only check
the start/end
of sections, all in section.h, could we use 'generic' or 'basic' or
'core' in the naming?
* is_kernel_generic_data() --- come from core_kernel_data() in kernel.h
* is_kernel_generic_text()
The old helper could remain unchanged, any suggestion, thanks.
Because it looks like the check of just being in the range of "_stext"
to "_end" is just an internal helper, why not do what we do all over
the kernel, and just prefix the function with a couple of underscores,
that denote that it's internal?
__is_kernel_text()
OK, thanks for your advise, there's already a __is_kernel_text() in
arch/x86/mm/init_32.c,
I will change it to is_x32_kernel_text() to avoid conflict on x86_32.
Then you have:
static inline int is_kernel_text(unsigned long addr)
{
if (__is_kernel_text(addr))
return 1;
return in_gate_area_no_mm(addr);
}
-- Steve
.