* [PATCH v4 01/11] kallsyms: Remove arch specific text and data check
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 02/11] kallsyms: Fix address-checks for kernel related range Kefeng Wang
` (9 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy, Kefeng Wang
After commit 4ba66a976072 ("arch: remove blackfin port"),
no need arch-specific text/data check.
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
include/asm-generic/sections.h | 16 ----------------
include/linux/kallsyms.h | 3 +--
kernel/locking/lockdep.c | 3 ---
3 files changed, 1 insertion(+), 21 deletions(-)
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index d16302d3eb59..817309e289db 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -64,22 +64,6 @@ extern __visible const void __nosave_begin, __nosave_end;
#define dereference_kernel_function_descriptor(p) ((void *)(p))
#endif
-/* random extra sections (if any). Override
- * in asm/sections.h */
-#ifndef arch_is_kernel_text
-static inline int arch_is_kernel_text(unsigned long addr)
-{
- return 0;
-}
-#endif
-
-#ifndef arch_is_kernel_data
-static inline int arch_is_kernel_data(unsigned long addr)
-{
- return 0;
-}
-#endif
-
/*
* Check if an address is part of freed initmem. This is needed on architectures
* with virt == phys kernel mapping, for code that wants to check if an address
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 6851c2313cad..2a241e3f063f 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -34,8 +34,7 @@ static inline int is_kernel_inittext(unsigned long addr)
static inline int is_kernel_text(unsigned long addr)
{
- if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
- arch_is_kernel_text(addr))
+ if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext))
return 1;
return in_gate_area_no_mm(addr);
}
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 7096384dc60f..dcdbcee391cd 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -803,9 +803,6 @@ static int static_obj(const void *obj)
if ((addr >= start) && (addr < end))
return 1;
- if (arch_is_kernel_data(addr))
- return 1;
-
/*
* in-kernel percpu var?
*/
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 02/11] kallsyms: Fix address-checks for kernel related range
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 01/11] kallsyms: Remove arch specific text and data check Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 03/11] sections: Move and rename core_kernel_data() to is_kernel_core_data() Kefeng Wang
` (8 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy,
Kefeng Wang, Sergey Senozhatsky, Petr Mladek, Sergey Senozhatsky
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 <sergey.senozhatsky@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
include/linux/kallsyms.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 2a241e3f063f..b016c62f30a6 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -27,21 +27,21 @@ struct module;
static inline int is_kernel_inittext(unsigned long addr)
{
if (addr >= (unsigned long)_sinittext
- && addr <= (unsigned long)_einittext)
+ && addr < (unsigned long)_einittext)
return 1;
return 0;
}
static inline int is_kernel_text(unsigned long addr)
{
- if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext))
+ if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
return 1;
return in_gate_area_no_mm(addr);
}
static inline int is_kernel(unsigned long addr)
{
- if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
+ if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
return 1;
return in_gate_area_no_mm(addr);
}
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 03/11] sections: Move and rename core_kernel_data() to is_kernel_core_data()
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 01/11] kallsyms: Remove arch specific text and data check Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 02/11] kallsyms: Fix address-checks for kernel related range Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 04/11] sections: Move is_kernel_inittext() into sections.h Kefeng Wang
` (7 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy, Kefeng Wang
Move core_kernel_data() into sections.h and rename it to
is_kernel_core_data(), also make it return bool value, then
update all the callers.
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
include/asm-generic/sections.h | 16 ++++++++++++++++
include/linux/kernel.h | 1 -
kernel/extable.c | 18 ------------------
kernel/trace/ftrace.c | 2 +-
net/sysctl_net.c | 2 +-
5 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 817309e289db..24780c0f40b1 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -142,6 +142,22 @@ static inline bool init_section_intersects(void *virt, size_t size)
return memory_intersects(__init_begin, __init_end, virt, size);
}
+/**
+ * is_kernel_core_data - checks if the pointer address is located in the
+ * .data section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .data, false otherwise.
+ * Note: On some archs it may return true for core RODATA, and false
+ * for others. But will always be true for core RW data.
+ */
+static inline bool is_kernel_core_data(unsigned long addr)
+{
+ return addr >= (unsigned long)_sdata &&
+ addr < (unsigned long)_edata;
+}
+
/**
* is_kernel_rodata - checks if the pointer address is located in the
* .rodata section
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2776423a587e..e5a9af8a4e20 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -230,7 +230,6 @@ extern char *next_arg(char *args, char **param, char **val);
extern int core_kernel_text(unsigned long addr);
extern int init_kernel_text(unsigned long addr);
-extern int core_kernel_data(unsigned long addr);
extern int __kernel_text_address(unsigned long addr);
extern int kernel_text_address(unsigned long addr);
extern int func_ptr_is_kernel_text(void *ptr);
diff --git a/kernel/extable.c b/kernel/extable.c
index b0ea5eb0c3b4..da26203841d4 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -82,24 +82,6 @@ int notrace core_kernel_text(unsigned long addr)
return 0;
}
-/**
- * core_kernel_data - tell if addr points to kernel data
- * @addr: address to test
- *
- * Returns true if @addr passed in is from the core kernel data
- * section.
- *
- * Note: On some archs it may return true for core RODATA, and false
- * for others. But will always be true for core RW data.
- */
-int core_kernel_data(unsigned long addr)
-{
- if (addr >= (unsigned long)_sdata &&
- addr < (unsigned long)_edata)
- return 1;
- return 0;
-}
-
int __kernel_text_address(unsigned long addr)
{
if (kernel_text_address(addr))
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 7efbc8aaf7f6..f15badf31f52 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -323,7 +323,7 @@ int __register_ftrace_function(struct ftrace_ops *ops)
if (!ftrace_enabled && (ops->flags & FTRACE_OPS_FL_PERMANENT))
return -EBUSY;
- if (!core_kernel_data((unsigned long)ops))
+ if (!is_kernel_core_data((unsigned long)ops))
ops->flags |= FTRACE_OPS_FL_DYNAMIC;
add_ftrace_ops(&ftrace_ops_list, ops);
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index f6cb0d4d114c..4b45ed631eb8 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -144,7 +144,7 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path,
addr = (unsigned long)ent->data;
if (is_module_address(addr))
where = "module";
- else if (core_kernel_data(addr))
+ else if (is_kernel_core_data(addr))
where = "kernel";
else
continue;
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 04/11] sections: Move is_kernel_inittext() into sections.h
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (2 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 03/11] sections: Move and rename core_kernel_data() to is_kernel_core_data() Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 05/11] x86: mm: Rename __is_kernel_text() to is_x86_32_kernel_text() Kefeng Wang
` (6 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy,
Kefeng Wang, Thomas Gleixner, x86
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 <tglx@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: x86@kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
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(-)
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index a1202536fc57..d92ec2ced059 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -175,7 +175,7 @@ static struct orc_entry *orc_find(unsigned long ip)
}
/* vmlinux .init slow lookup: */
- if (init_kernel_text(ip))
+ if (is_kernel_inittext(ip))
return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
__stop_orc_unwind_ip - __start_orc_unwind_ip, ip);
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 24780c0f40b1..811583ca8bd0 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -172,4 +172,18 @@ static inline bool is_kernel_rodata(unsigned long addr)
addr < (unsigned long)__end_rodata;
}
+/**
+ * is_kernel_inittext - checks if the pointer address is located in the
+ * .init.text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .init.text, false otherwise.
+ */
+static inline bool is_kernel_inittext(unsigned long addr)
+{
+ return addr >= (unsigned long)_sinittext &&
+ addr < (unsigned long)_einittext;
+}
+
#endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index b016c62f30a6..8a9d329c927c 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -24,14 +24,6 @@
struct cred;
struct module;
-static inline int is_kernel_inittext(unsigned long addr)
-{
- if (addr >= (unsigned long)_sinittext
- && addr < (unsigned long)_einittext)
- return 1;
- return 0;
-}
-
static inline int is_kernel_text(unsigned long addr)
{
if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e5a9af8a4e20..445d0dceefb8 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -229,7 +229,6 @@ extern bool parse_option_str(const char *str, const char *option);
extern char *next_arg(char *args, char **param, char **val);
extern int core_kernel_text(unsigned long addr);
-extern int init_kernel_text(unsigned long addr);
extern int __kernel_text_address(unsigned long addr);
extern int kernel_text_address(unsigned long addr);
extern int func_ptr_is_kernel_text(void *ptr);
diff --git a/kernel/extable.c b/kernel/extable.c
index da26203841d4..98ca627ac5ef 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -62,14 +62,6 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
return e;
}
-int init_kernel_text(unsigned long addr)
-{
- if (addr >= (unsigned long)_sinittext &&
- addr < (unsigned long)_einittext)
- return 1;
- return 0;
-}
-
int notrace core_kernel_text(unsigned long addr)
{
if (addr >= (unsigned long)_stext &&
@@ -77,7 +69,7 @@ int notrace core_kernel_text(unsigned long addr)
return 1;
if (system_state < SYSTEM_RUNNING &&
- init_kernel_text(addr))
+ is_kernel_inittext(addr))
return 1;
return 0;
}
@@ -94,7 +86,7 @@ int __kernel_text_address(unsigned long addr)
* Since we are after the module-symbols check, there's
* no danger of address overlap:
*/
- if (init_kernel_text(addr))
+ if (is_kernel_inittext(addr))
return 1;
return 0;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 05/11] x86: mm: Rename __is_kernel_text() to is_x86_32_kernel_text()
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (3 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 04/11] sections: Move is_kernel_inittext() into sections.h Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 06/11] sections: Provide internal __is_kernel() and __is_kernel_text() helper Kefeng Wang
` (5 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy,
Kefeng Wang, Borislav Petkov, x86
Commit b56cd05c55a1 ("x86/mm: Rename is_kernel_text to __is_kernel_text"),
add '__' prefix not to get in conflict with existing is_kernel_text() in
<linux/kallsyms.h>.
We will add __is_kernel_text() for the basic kernel text range check in the
next patch, so use private is_x86_32_kernel_text() naming for x86 special
check.
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
arch/x86/mm/init_32.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index bd90b8fe81e4..523743ee9dea 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -238,11 +238,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
}
}
-/*
- * The <linux/kallsyms.h> already defines is_kernel_text,
- * using '__' prefix not to get in conflict.
- */
-static inline int __is_kernel_text(unsigned long addr)
+static inline int is_x86_32_kernel_text(unsigned long addr)
{
if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
return 1;
@@ -333,8 +329,8 @@ kernel_physical_mapping_init(unsigned long start,
addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
PAGE_OFFSET + PAGE_SIZE-1;
- if (__is_kernel_text(addr) ||
- __is_kernel_text(addr2))
+ if (is_x86_32_kernel_text(addr) ||
+ is_x86_32_kernel_text(addr2))
prot = PAGE_KERNEL_LARGE_EXEC;
pages_2m++;
@@ -359,7 +355,7 @@ kernel_physical_mapping_init(unsigned long start,
*/
pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
- if (__is_kernel_text(addr))
+ if (is_x86_32_kernel_text(addr))
prot = PAGE_KERNEL_EXEC;
pages_4k++;
@@ -820,7 +816,7 @@ static void mark_nxdata_nx(void)
*/
unsigned long start = PFN_ALIGN(_etext);
/*
- * This comes from __is_kernel_text upper limit. Also HPAGE where used:
+ * This comes from is_x86_32_kernel_text upper limit. Also HPAGE where used:
*/
unsigned long size = (((unsigned long)__init_end + HPAGE_SIZE) & HPAGE_MASK) - start;
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 06/11] sections: Provide internal __is_kernel() and __is_kernel_text() helper
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (4 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 05/11] x86: mm: Rename __is_kernel_text() to is_x86_32_kernel_text() Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 07/11] mm: kasan: Use is_kernel() helper Kefeng Wang
` (4 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy, Kefeng Wang
An internal __is_kernel() helper which only check the
kernel address ranges, and an internal __is_kernel_text()
helper which only check text section ranges.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
include/asm-generic/sections.h | 29 +++++++++++++++++++++++++++++
include/linux/kallsyms.h | 4 ++--
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 811583ca8bd0..a7abeadddc7a 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -186,4 +186,33 @@ static inline bool is_kernel_inittext(unsigned long addr)
addr < (unsigned long)_einittext;
}
+/**
+ * __is_kernel_text - checks if the pointer address is located in the
+ * .text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .text, false otherwise.
+ * Note: an internal helper, only check the range of _stext to _etext.
+ */
+static inline bool __is_kernel_text(unsigned long addr)
+{
+ return addr >= (unsigned long)_stext &&
+ addr < (unsigned long)_etext;
+}
+
+/**
+ * __is_kernel - checks if the pointer address is located in the kernel range
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in the kernel range, false otherwise.
+ * Note: an internal helper, only check the range of _stext to _end.
+ */
+static inline bool __is_kernel(unsigned long addr)
+{
+ return addr >= (unsigned long)_stext &&
+ addr < (unsigned long)_end;
+}
+
#endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 8a9d329c927c..5fb17dd4b6fa 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -26,14 +26,14 @@ struct module;
static inline int is_kernel_text(unsigned long addr)
{
- if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
+ if (__is_kernel_text(addr))
return 1;
return in_gate_area_no_mm(addr);
}
static inline int is_kernel(unsigned long addr)
{
- if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
+ if (__is_kernel(addr))
return 1;
return in_gate_area_no_mm(addr);
}
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 07/11] mm: kasan: Use is_kernel() helper
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (5 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 06/11] sections: Provide internal __is_kernel() and __is_kernel_text() helper Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 15:45 ` Alexander Potapenko
2021-10-03 17:19 ` Andrey Konovalov
2021-09-30 7:11 ` [PATCH v4 08/11] extable: Use is_kernel_text() helper Kefeng Wang
` (3 subsequent siblings)
10 siblings, 2 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy,
Kefeng Wang, Alexander Potapenko, Andrey Konovalov,
Dmitry Vyukov
Directly use is_kernel() helper in kernel_or_module_addr().
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
mm/kasan/report.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 3239fd8f8747..1c955e1c98d5 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -226,7 +226,7 @@ static void describe_object(struct kmem_cache *cache, void *object,
static inline bool kernel_or_module_addr(const void *addr)
{
- if (addr >= (void *)_stext && addr < (void *)_end)
+ if (is_kernel((unsigned long)addr))
return true;
if (is_module_address((unsigned long)addr))
return true;
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v4 07/11] mm: kasan: Use is_kernel() helper
2021-09-30 7:11 ` [PATCH v4 07/11] mm: kasan: Use is_kernel() helper Kefeng Wang
@ 2021-09-30 15:45 ` Alexander Potapenko
2021-10-03 17:19 ` Andrey Konovalov
1 sibling, 0 replies; 15+ messages in thread
From: Alexander Potapenko @ 2021-09-30 15:45 UTC (permalink / raw)
To: Kefeng Wang
Cc: Arnd Bergmann, Linux-Arch, LKML, linuxppc-dev, Steven Rostedt,
Ingo Molnar, David Miller, Alexei Starovoitov, Andrey Ryabinin,
Andrew Morton, Michael Ellerman, Benjamin Herrenschmidt,
Paul Mackerras, bpf, linux-alpha, Christophe Leroy,
Andrey Konovalov, Dmitry Vyukov
On Thu, Sep 30, 2021 at 9:09 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>
> Directly use is_kernel() helper in kernel_or_module_addr().
>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
> ---
> mm/kasan/report.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index 3239fd8f8747..1c955e1c98d5 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -226,7 +226,7 @@ static void describe_object(struct kmem_cache *cache, void *object,
>
> static inline bool kernel_or_module_addr(const void *addr)
> {
> - if (addr >= (void *)_stext && addr < (void *)_end)
> + if (is_kernel((unsigned long)addr))
> return true;
> if (is_module_address((unsigned long)addr))
> return true;
> --
> 2.26.2
>
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v4 07/11] mm: kasan: Use is_kernel() helper
2021-09-30 7:11 ` [PATCH v4 07/11] mm: kasan: Use is_kernel() helper Kefeng Wang
2021-09-30 15:45 ` Alexander Potapenko
@ 2021-10-03 17:19 ` Andrey Konovalov
1 sibling, 0 replies; 15+ messages in thread
From: Andrey Konovalov @ 2021-10-03 17:19 UTC (permalink / raw)
To: Kefeng Wang
Cc: Arnd Bergmann, linux-arch, LKML, linuxppc-dev, Steven Rostedt,
mingo, David Miller, Alexei Starovoitov, Andrey Ryabinin,
Andrew Morton, mpe, benh, paulus, bpf, linux-alpha,
Christophe Leroy, Alexander Potapenko, Dmitry Vyukov
On Thu, Sep 30, 2021 at 9:09 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>
> Directly use is_kernel() helper in kernel_or_module_addr().
>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> mm/kasan/report.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index 3239fd8f8747..1c955e1c98d5 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -226,7 +226,7 @@ static void describe_object(struct kmem_cache *cache, void *object,
>
> static inline bool kernel_or_module_addr(const void *addr)
> {
> - if (addr >= (void *)_stext && addr < (void *)_end)
> + if (is_kernel((unsigned long)addr))
> return true;
> if (is_module_address((unsigned long)addr))
> return true;
> --
> 2.26.2
>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v4 08/11] extable: Use is_kernel_text() helper
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (6 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 07/11] mm: kasan: Use is_kernel() helper Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 09/11] powerpc/mm: Use core_kernel_text() helper Kefeng Wang
` (2 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy, Kefeng Wang
The core_kernel_text() should check the gate area, as it is part
of kernel text range, use is_kernel_text() in core_kernel_text().
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
kernel/extable.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/extable.c b/kernel/extable.c
index 98ca627ac5ef..0ba383d850ff 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -64,8 +64,7 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
int notrace core_kernel_text(unsigned long addr)
{
- if (addr >= (unsigned long)_stext &&
- addr < (unsigned long)_etext)
+ if (is_kernel_text(addr))
return 1;
if (system_state < SYSTEM_RUNNING &&
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 09/11] powerpc/mm: Use core_kernel_text() helper
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (7 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 08/11] extable: Use is_kernel_text() helper Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 10/11] microblaze: Use is_kernel_text() helper Kefeng Wang
2021-09-30 7:11 ` [PATCH v4 11/11] alpha: " Kefeng Wang
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy, Kefeng Wang
Use core_kernel_text() 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 <paulus@samba.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
arch/powerpc/mm/pgtable_32.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index dcf5ecca19d9..079abbf45a33 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -33,8 +33,6 @@
#include <mm/mmu_decl.h>
-extern char etext[], _stext[], _sinittext[], _einittext[];
-
static u8 early_fixmap_pagetable[FIXMAP_PTE_SIZE] __page_aligned_data;
notrace void __init early_ioremap_init(void)
@@ -104,14 +102,13 @@ static void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
{
unsigned long v, s;
phys_addr_t p;
- int ktext;
+ bool ktext;
s = offset;
v = PAGE_OFFSET + s;
p = memstart_addr + s;
for (; s < top; s += PAGE_SIZE) {
- ktext = ((char *)v >= _stext && (char *)v < etext) ||
- ((char *)v >= _sinittext && (char *)v < _einittext);
+ ktext = core_kernel_text(v);
map_kernel_page(v, p, ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL);
v += PAGE_SIZE;
p += PAGE_SIZE;
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v4 10/11] microblaze: Use is_kernel_text() helper
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (8 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 09/11] powerpc/mm: Use core_kernel_text() helper Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
2021-09-30 10:13 ` Michal Simek
2021-09-30 7:11 ` [PATCH v4 11/11] alpha: " Kefeng Wang
10 siblings, 1 reply; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy,
Kefeng Wang, Michal Simek
Use is_kernel_text() helper to simplify code.
Cc: Michal Simek <monstr@monstr.eu>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
arch/microblaze/mm/pgtable.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
index c1833b159d3b..9f73265aad4e 100644
--- a/arch/microblaze/mm/pgtable.c
+++ b/arch/microblaze/mm/pgtable.c
@@ -34,6 +34,7 @@
#include <linux/mm_types.h>
#include <linux/pgtable.h>
#include <linux/memblock.h>
+#include <linux/kallsyms.h>
#include <asm/pgalloc.h>
#include <linux/io.h>
@@ -171,7 +172,7 @@ void __init mapin_ram(void)
for (s = 0; s < lowmem_size; s += PAGE_SIZE) {
f = _PAGE_PRESENT | _PAGE_ACCESSED |
_PAGE_SHARED | _PAGE_HWEXEC;
- if ((char *) v < _stext || (char *) v >= _etext)
+ if (!is_kernel_text(v))
f |= _PAGE_WRENABLE;
else
/* On the MicroBlaze, no user access
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v4 10/11] microblaze: Use is_kernel_text() helper
2021-09-30 7:11 ` [PATCH v4 10/11] microblaze: Use is_kernel_text() helper Kefeng Wang
@ 2021-09-30 10:13 ` Michal Simek
0 siblings, 0 replies; 15+ messages in thread
From: Michal Simek @ 2021-09-30 10:13 UTC (permalink / raw)
To: Kefeng Wang, arnd, linux-arch, linux-kernel, linuxppc-dev,
rostedt, mingo, davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy
On 9/30/21 9:11 AM, Kefeng Wang wrote:
> Use is_kernel_text() helper to simplify code.
>
> Cc: Michal Simek <monstr@monstr.eu>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
> arch/microblaze/mm/pgtable.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
> index c1833b159d3b..9f73265aad4e 100644
> --- a/arch/microblaze/mm/pgtable.c
> +++ b/arch/microblaze/mm/pgtable.c
> @@ -34,6 +34,7 @@
> #include <linux/mm_types.h>
> #include <linux/pgtable.h>
> #include <linux/memblock.h>
> +#include <linux/kallsyms.h>
>
> #include <asm/pgalloc.h>
> #include <linux/io.h>
> @@ -171,7 +172,7 @@ void __init mapin_ram(void)
> for (s = 0; s < lowmem_size; s += PAGE_SIZE) {
> f = _PAGE_PRESENT | _PAGE_ACCESSED |
> _PAGE_SHARED | _PAGE_HWEXEC;
> - if ((char *) v < _stext || (char *) v >= _etext)
> + if (!is_kernel_text(v))
> f |= _PAGE_WRENABLE;
> else
> /* On the MicroBlaze, no user access
>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Thanks,
Michal
--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v4 11/11] alpha: Use is_kernel_text() helper
2021-09-30 7:11 [PATCH v4 00/11] sections: Unify kernel sections range check and use Kefeng Wang
` (9 preceding siblings ...)
2021-09-30 7:11 ` [PATCH v4 10/11] microblaze: Use is_kernel_text() helper Kefeng Wang
@ 2021-09-30 7:11 ` Kefeng Wang
10 siblings, 0 replies; 15+ messages in thread
From: Kefeng Wang @ 2021-09-30 7:11 UTC (permalink / raw)
To: arnd, linux-arch, linux-kernel, linuxppc-dev, rostedt, mingo,
davem, ast, ryabinin.a.a, akpm
Cc: mpe, benh, paulus, bpf, linux-alpha, Christophe Leroy,
Kefeng Wang, Richard Henderson, Ivan Kokshaysky, Matt Turner
Use is_kernel_text() helper to simplify code.
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
arch/alpha/kernel/traps.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index e805106409f7..2ae34702456c 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -129,9 +129,7 @@ dik_show_trace(unsigned long *sp, const char *loglvl)
extern char _stext[], _etext[];
unsigned long tmp = *sp;
sp++;
- if (tmp < (unsigned long) &_stext)
- continue;
- if (tmp >= (unsigned long) &_etext)
+ if (!is_kernel_text(tmp))
continue;
printk("%s[<%lx>] %pSR\n", loglvl, tmp, (void *)tmp);
if (i > 40) {
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread