Playing around with syscall framework macros broke the syscall tracing badly, see: commit bb3fbc44e783 ("arm64/syscalls: Allow syscalls to return capabilities") and: https://git.morello-project.org/morello/kernel/linux/-/issues/35 for the corresponding bug report.
This series in an attempt to remedy that. The first patch does some rather controversial thing, but there is already a precedent for that (as of ARCH_HAS_SYSCALL_MATCH_SYM_NAME), so one could say it can be somehow exonerated.
The second one tries to get the SYSCALL_METADATA macro aligned with the changes that caused the issue in the first place and, sadly, it is touching other archs code, though the changes are minimal and safe.
Note: checkpatch will complain about few things but those are to be ignored.
Tracing selftests seem to be happy with the changes. Also verified with some random syscall events.
v2: - split [PATCH 2/3] into generic and Morello specific changes - added dependency on CONFIG_FTRACE_SYSCALLS for ARCH_HAS_SYSCALL_ADDR - improved (hopefully) commit message for previous PATCH 2-3 - small formatting clean-up
Review branch: https://git.morello-project.org/Bea/linux/-/commits/morello/ftrace_syscalls/
Beata Michalska (4): tracing/syscalls: Reshape arch_syscall_addr tracing/syscalls: Allow amending metadata macro arguments arm64:morello: Get a grip on syscall tracing tracing/signal: Use explicit conversion instead of vague downcast
Documentation/trace/ftrace-design.rst | 5 +++-- arch/arm64/include/asm/ftrace.h | 4 ++++ arch/arm64/include/asm/syscall_wrapper.h | 9 ++++++--- arch/arm64/kernel/syscall.c | 12 ++++++++++++ arch/mips/include/asm/ftrace.h | 4 ++++ arch/s390/include/asm/syscall_wrapper.h | 6 +++--- arch/x86/include/asm/syscall_wrapper.h | 2 +- include/linux/syscalls.h | 13 +++++++++---- include/trace/events/signal.h | 4 ++-- kernel/trace/trace_syscalls.c | 4 +++- 10 files changed, 47 insertions(+), 16 deletions(-)
Despite having the generic arch_syscall_addr being weak, as per commit:
commit c763ba06bd9b ("tracing/syscalls: Make arch_syscall_addr weak")
the level of flexibility provided towards supporting customization of the sys_call_table is still insufficient for certain architectures, making arch_syscall_addr being susceptible to compile-time errors, whenever sys_call_table entries end up being more than just regular function pointer (as in the case of Morello and PCuABI :
commit bb3fbc44e783 ("arm64/syscalls: Allow syscalls to return capabilities")
Instead, drop the generic implementation (and assumptions made there) for archs that explicitly request not to use it.
Signed-off-by: Beata Michalska beata.michalska@arm.com --- Documentation/trace/ftrace-design.rst | 5 +++-- arch/mips/include/asm/ftrace.h | 4 ++++ kernel/trace/trace_syscalls.c | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Documentation/trace/ftrace-design.rst b/Documentation/trace/ftrace-design.rst index 6893399157f0..d7c17901cb5a 100644 --- a/Documentation/trace/ftrace-design.rst +++ b/Documentation/trace/ftrace-design.rst @@ -241,8 +241,9 @@ You need very few things to get the syscalls tracing in an arch. - Put the trace_sys_enter() and trace_sys_exit() tracepoints calls from ptrace in the ptrace syscalls tracing path. - If the system call table on this arch is more complicated than a simple array - of addresses of the system calls, implement an arch_syscall_addr to return - the address of a given system call. + of addresses of the system calls or requires custom handling, define + ARCH_HAS_SYSCALL_ADDR in asm/ftrace.h and implement arch_syscall_addr to + return the address of a given system call. - If the symbol names of the system calls do not match the function names on this arch, define ARCH_HAS_SYSCALL_MATCH_SYM_NAME in asm/ftrace.h and implement arch_syscall_match_sym_name with the appropriate logic to return diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h index db497a8167da..a93b8e1c8d2c 100644 --- a/arch/mips/include/asm/ftrace.h +++ b/arch/mips/include/asm/ftrace.h @@ -10,6 +10,10 @@ #ifndef _ASM_MIPS_FTRACE_H #define _ASM_MIPS_FTRACE_H
+#ifdef CONFIG_FTRACE_SYSCALLS +#define ARCH_HAS_SYSCALL_ADDR +#endif + #ifdef CONFIG_FUNCTION_TRACER
#define MCOUNT_ADDR ((unsigned long)(_mcount)) diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index f755bde42fd0..ad3bb8e8c651 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -516,10 +516,12 @@ struct trace_event_class __refdata event_class_syscall_exit = { .raw_init = init_syscall_trace, };
-unsigned long __init __weak arch_syscall_addr(int nr) +#ifndef ARCH_HAS_SYSCALL_ADDR +unsigned long __init arch_syscall_addr(int nr) { return (unsigned long)sys_call_table[nr]; } +#endif
void __init init_ftrace_syscalls(void) {
The way in which the tracing framework defines its syscall metadata is tightly coupled with the syscall wrappers and those might be subject to architecture specific fine-tuning. For most cases this is not an issue, as SYSCALL_METADATA is simply piggy-backing on the arguments provided to those wrappers, though for arm64/Morello this proves to be problematic. To overcome this, split the SYSCALL_METADATA into a double-phased setup, allow amending the arguments themselves, so that whatever changes the arch code decides to do there, get sanitised prior to expanding the actual metadata wrapper. Additionally, the order of the arguments here gets align with the rest of the syscall framework.
Signed-off-by: Beata Michalska beata.michalska@arm.com --- arch/arm64/include/asm/syscall_wrapper.h | 4 ++-- arch/s390/include/asm/syscall_wrapper.h | 6 +++--- arch/x86/include/asm/syscall_wrapper.h | 2 +- include/linux/syscalls.h | 13 +++++++++---- 4 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h index b823aee59b6c..97e08c4a6520 100644 --- a/arch/arm64/include/asm/syscall_wrapper.h +++ b/arch/arm64/include/asm/syscall_wrapper.h @@ -68,7 +68,7 @@ struct pt_regs; }
#define __SYSCALL_DEFINE0(sname, ret_type) \ - SYSCALL_METADATA(sname, 0); \ + SYSCALL_METADATA(0, sname,); \ asmlinkage ret_type __arm64_sys##sname(const struct pt_regs *__unused); \ ALLOW_ERROR_INJECTION(__arm64_sys##sname, ERRNO); \ asmlinkage ret_type __arm64_compatentry_sys##sname(const struct pt_regs *__unused)\ @@ -94,7 +94,7 @@ struct pt_regs; #define __ARM64_SYS_STUBx(x, name, ...)
#define __SYSCALL_DEFINE0(sname, ret_type) \ - SYSCALL_METADATA(sname, 0); \ + SYSCALL_METADATA(0, sname,); \ asmlinkage ret_type __arm64_sys##sname(const struct pt_regs *__unused); \ ALLOW_ERROR_INJECTION(__arm64_sys##sname, ERRNO); \ asmlinkage ret_type __arm64_sys##sname(const struct pt_regs *__unused) diff --git a/arch/s390/include/asm/syscall_wrapper.h b/arch/s390/include/asm/syscall_wrapper.h index fde7e6b1df48..dee9c319734d 100644 --- a/arch/s390/include/asm/syscall_wrapper.h +++ b/arch/s390/include/asm/syscall_wrapper.h @@ -72,13 +72,13 @@ * named __s390x_sys_*() */ #define COMPAT_SYSCALL_DEFINE0(sname) \ - SYSCALL_METADATA(_##sname, 0); \ + SYSCALL_METADATA(0, _##sname); \ long __s390_compat_sys_##sname(void); \ ALLOW_ERROR_INJECTION(__s390_compat_sys_##sname, ERRNO); \ long __s390_compat_sys_##sname(void)
#define SYSCALL_DEFINE0(sname) \ - SYSCALL_METADATA(_##sname, 0); \ + SYSCALL_METADATA(0, _##sname); \ long __s390x_sys_##sname(void); \ ALLOW_ERROR_INJECTION(__s390x_sys_##sname, ERRNO); \ long __s390_sys_##sname(void) \ @@ -129,7 +129,7 @@ #define __S390_SYS_STUBx(x, fullname, name, ...)
#define SYSCALL_DEFINE0(sname) \ - SYSCALL_METADATA(_##sname, 0); \ + SYSCALL_METADATA(0, _##sname); \ long __s390x_sys_##sname(void); \ ALLOW_ERROR_INJECTION(__s390x_sys_##sname, ERRNO); \ long __s390x_sys_##sname(void) diff --git a/arch/x86/include/asm/syscall_wrapper.h b/arch/x86/include/asm/syscall_wrapper.h index 59358d1bf880..c39adc4810f0 100644 --- a/arch/x86/include/asm/syscall_wrapper.h +++ b/arch/x86/include/asm/syscall_wrapper.h @@ -247,7 +247,7 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs); * macros to work correctly. */ #define SYSCALL_DEFINE0(sname) \ - SYSCALL_METADATA(_##sname, 0); \ + SYSCALL_METADATA(0, _##sname); \ static long __do_sys_##sname(const struct pt_regs *__unused); \ __X64_SYS_STUB0(sname) \ __IA32_SYS_STUB0(sname) \ diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 8a6f561ce1de..4bd6d9a4c6ea 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -193,7 +193,7 @@ extern struct trace_event_functions exit_syscall_print_funcs; __section("_ftrace_events") \ *__event_exit_##sname = &event_exit_##sname;
-#define SYSCALL_METADATA(sname, nb, ...) \ +#define __SYSCALL_METADATA(nb, sname, ...) \ static const char *types_##sname[] = { \ __MAP(nb,__SC_STR_TDECL,__VA_ARGS__) \ }; \ @@ -224,7 +224,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) }
#else -#define SYSCALL_METADATA(sname, nb, ...) +#define __SYSCALL_METADATA(nb, sname, ...)
static inline int is_syscall_trace_event(struct trace_event_call *tp_event) { @@ -232,6 +232,11 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) } #endif
+#ifndef SYSCALL_METADATA +#define SYSCALL_METADATA(nb, sname, ...) \ + __SYSCALL_METADATA(nb, sname, __VA_ARGS__) +#endif + #ifndef __retptr__ #define __retptr__(name) name #undef SYSCALL_PREP @@ -240,7 +245,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
#ifndef SYSCALL_DEFINE0 #define SYSCALL_DEFINE0(sname) \ - SYSCALL_METADATA(_##sname, 0); \ + SYSCALL_METADATA(0, _##sname); \ asmlinkage long sys_##sname(void); \ ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ asmlinkage long sys_##sname(void) @@ -256,7 +261,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) #define SYSCALL_DEFINE_MAXARGS 6
#define SYSCALL_DEFINEx(x, sname, ...) \ - SYSCALL_METADATA(sname, x, __VA_ARGS__) \ + SYSCALL_METADATA(x, sname, __VA_ARGS__) \ __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
#define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
The alterations around the syscall framework made to enable support for capabilities, did spin the syscalls tracing out of control and broke a number of things on the way. In order to get it back in line (eventually), make necessary adjustments to SYSCALL_METADATA and provide dedicated implementation for arch_syscall_addr.
Fixes: bb3fbc44e783 ("arm64/syscalls: Allow syscalls to return capabilities") Signed-off-by: Beata Michalska beata.michalska@arm.com --- arch/arm64/include/asm/ftrace.h | 4 ++++ arch/arm64/include/asm/syscall_wrapper.h | 5 ++++- arch/arm64/kernel/syscall.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 665373f441e1..89ff574a4a91 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -102,6 +102,10 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) return is_32bit_compat_task(); }
+#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_CHERI_PURECAP_UABI) +#define ARCH_HAS_SYSCALL_ADDR +#endif + #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
static inline bool arch_syscall_match_sym_name(const char *sym, diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h index 97e08c4a6520..39957e54f8d3 100644 --- a/arch/arm64/include/asm/syscall_wrapper.h +++ b/arch/arm64/include/asm/syscall_wrapper.h @@ -141,7 +141,10 @@ struct pt_regs; #define __retptr__(name) name, _PTR #define __SYSCALL_ANNOTATE(name, ret_type) name, __SYSCALL_RET_T##ret_type #define SYSCALL_PREP(name, ...) __SYSCALL_ANNOTATE(_##name, __VA_ARGS__) - +#ifdef CONFIG_FTRACE_SYSCALLS +#define SYSCALL_METADATA(x, name, ret_type, ...) \ + __SYSCALL_METADATA(x, name, __VA_ARGS__) +#endif /* * Some syscalls with no parameters return valid capabilities, so __SYSCALL_DEFINE0 * is added to handle such cases. diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index a0e91ea7b74b..4942fcb4d299 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -105,6 +105,18 @@ static inline bool has_syscall_work(unsigned long flags) return unlikely(flags & _TIF_SYSCALL_WORK); }
+#if defined(CONFIG_CHERI_PURECAP_UABI) && defined(CONFIG_FTRACE_SYSCALLS) +unsigned long __init arch_syscall_addr(int nr) +{ + /* + * In this particular case, it makes no difference, + * which member of the syscall_entry_t instance is being + * provided - the address is all that matters here + */ + return (unsigned long)sys_call_table[nr].syscall_fn; +} +#endif + int syscall_trace_enter(struct pt_regs *regs); void syscall_trace_exit(struct pt_regs *regs);
Commit title: there should be a space between each tag, i.e. "arm64: morello:".
On 12/10/2022 16:27, Beata Michalska wrote:
The alterations around the syscall framework made to enable support for capabilities, did spin the syscalls tracing out of control and broke a number of things on the way.
It would probably be helpful to say what was actually broken (i.e. it simply didn't build with CONFIG_FTRACE_SYSCALLS). Also worth separating the two issues - the SYSCALL_METADATA() override is required to fix things in any configuration for arm64, while the arch_syscall_addr() issue is specific to PCuABI.
In order to get it back in line (eventually), make necessary adjustments to SYSCALL_METADATA and provide dedicated implementation for arch_syscall_addr.
Fixes: bb3fbc44e783 ("arm64/syscalls: Allow syscalls to return capabilities") Signed-off-by: Beata Michalska beata.michalska@arm.com
arch/arm64/include/asm/ftrace.h | 4 ++++ arch/arm64/include/asm/syscall_wrapper.h | 5 ++++- arch/arm64/kernel/syscall.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 665373f441e1..89ff574a4a91 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -102,6 +102,10 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) return is_32bit_compat_task(); } +#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_CHERI_PURECAP_UABI) +#define ARCH_HAS_SYSCALL_ADDR +#endif
- #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
static inline bool arch_syscall_match_sym_name(const char *sym, diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h index 97e08c4a6520..39957e54f8d3 100644 --- a/arch/arm64/include/asm/syscall_wrapper.h +++ b/arch/arm64/include/asm/syscall_wrapper.h @@ -141,7 +141,10 @@ struct pt_regs; #define __retptr__(name) name, _PTR #define __SYSCALL_ANNOTATE(name, ret_type) name, __SYSCALL_RET_T##ret_type #define SYSCALL_PREP(name, ...) __SYSCALL_ANNOTATE(_##name, __VA_ARGS__)
I still think that newline should stay.
+#ifdef CONFIG_FTRACE_SYSCALLS +#define SYSCALL_METADATA(x, name, ret_type, ...) \
- __SYSCALL_METADATA(x, name, __VA_ARGS__)
+#endif /*
- Some syscalls with no parameters return valid capabilities, so __SYSCALL_DEFINE0
- is added to handle such cases.
diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index a0e91ea7b74b..4942fcb4d299 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -105,6 +105,18 @@ static inline bool has_syscall_work(unsigned long flags) return unlikely(flags & _TIF_SYSCALL_WORK); } +#if defined(CONFIG_CHERI_PURECAP_UABI) && defined(CONFIG_FTRACE_SYSCALLS)
Nit: would be better in the same order as above (FTRACE_SYSCALLS first).
Kevin
+unsigned long __init arch_syscall_addr(int nr) +{
- /*
* In this particular case, it makes no difference,
* which member of the syscall_entry_t instance is being
* provided - the address is all that matters here
*/
- return (unsigned long)sys_call_table[nr].syscall_fn;
+} +#endif
- int syscall_trace_enter(struct pt_regs *regs); void syscall_trace_exit(struct pt_regs *regs);
On Wed, Oct 12, 2022 at 05:18:02PM +0200, Kevin Brodsky wrote:
Commit title: there should be a space between each tag, i.e. "arm64: morello:".
On 12/10/2022 16:27, Beata Michalska wrote:
The alterations around the syscall framework made to enable support for capabilities, did spin the syscalls tracing out of control and broke a number of things on the way.
It would probably be helpful to say what was actually broken (i.e. it simply didn't build with CONFIG_FTRACE_SYSCALLS). Also worth separating the two issues - the SYSCALL_METADATA() override is required to fix things in any configuration for arm64, while the arch_syscall_addr() issue is specific to PCuABI.
I'll cover the details in the updated version. But while at it: maybe it would be better to further split the patch into two, with one covering the SYSCALL_METADATA changes that are needed for arm64 in general, and then the second one with Morello specific changes for arch_syscall_addr ? Or do you believe having the details in the commit message is enough even despite the title depicting Morello explicitly ?
In order to get it back in line (eventually), make necessary adjustments to SYSCALL_METADATA and provide dedicated implementation for arch_syscall_addr.
Fixes: bb3fbc44e783 ("arm64/syscalls: Allow syscalls to return capabilities") Signed-off-by: Beata Michalska beata.michalska@arm.com
arch/arm64/include/asm/ftrace.h | 4 ++++ arch/arm64/include/asm/syscall_wrapper.h | 5 ++++- arch/arm64/kernel/syscall.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 665373f441e1..89ff574a4a91 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -102,6 +102,10 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) return is_32bit_compat_task(); } +#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_CHERI_PURECAP_UABI) +#define ARCH_HAS_SYSCALL_ADDR +#endif
- #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME static inline bool arch_syscall_match_sym_name(const char *sym,
diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h index 97e08c4a6520..39957e54f8d3 100644 --- a/arch/arm64/include/asm/syscall_wrapper.h +++ b/arch/arm64/include/asm/syscall_wrapper.h @@ -141,7 +141,10 @@ struct pt_regs; #define __retptr__(name) name, _PTR #define __SYSCALL_ANNOTATE(name, ret_type) name, __SYSCALL_RET_T##ret_type #define SYSCALL_PREP(name, ...) __SYSCALL_ANNOTATE(_##name, __VA_ARGS__)
I still think that newline should stay.
Noted
+#ifdef CONFIG_FTRACE_SYSCALLS +#define SYSCALL_METADATA(x, name, ret_type, ...) \
- __SYSCALL_METADATA(x, name, __VA_ARGS__)
+#endif /*
- Some syscalls with no parameters return valid capabilities, so __SYSCALL_DEFINE0
- is added to handle such cases.
diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index a0e91ea7b74b..4942fcb4d299 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -105,6 +105,18 @@ static inline bool has_syscall_work(unsigned long flags) return unlikely(flags & _TIF_SYSCALL_WORK); } +#if defined(CONFIG_CHERI_PURECAP_UABI) && defined(CONFIG_FTRACE_SYSCALLS)
Nit: would be better in the same order as above (FTRACE_SYSCALLS first).
Ditto
--- BR B.
Kevin
+unsigned long __init arch_syscall_addr(int nr) +{
- /*
* In this particular case, it makes no difference,
* which member of the syscall_entry_t instance is being
* provided - the address is all that matters here
*/
- return (unsigned long)sys_call_table[nr].syscall_fn;
+} +#endif
- int syscall_trace_enter(struct pt_regs *regs); void syscall_trace_exit(struct pt_regs *regs);
On 13/10/2022 11:10, Beata Michalska wrote:
On Wed, Oct 12, 2022 at 05:18:02PM +0200, Kevin Brodsky wrote:
Commit title: there should be a space between each tag, i.e. "arm64: morello:".
On 12/10/2022 16:27, Beata Michalska wrote:
The alterations around the syscall framework made to enable support for capabilities, did spin the syscalls tracing out of control and broke a number of things on the way.
It would probably be helpful to say what was actually broken (i.e. it simply didn't build with CONFIG_FTRACE_SYSCALLS). Also worth separating the two issues - the SYSCALL_METADATA() override is required to fix things in any configuration for arm64, while the arch_syscall_addr() issue is specific to PCuABI.
I'll cover the details in the updated version. But while at it: maybe it would be better to further split the patch into two, with one covering the SYSCALL_METADATA changes that are needed for arm64 in general, and then the second one with Morello specific changes for arch_syscall_addr ? Or do you believe having the details in the commit message is enough even despite the title depicting Morello explicitly ?
Splitting the patch further sounds like a good idea actually, as conceptually those two things are distinct and splitting removes the need to explain that :)
Kevin
In order to get it back in line (eventually), make necessary adjustments to SYSCALL_METADATA and provide dedicated implementation for arch_syscall_addr.
Fixes: bb3fbc44e783 ("arm64/syscalls: Allow syscalls to return capabilities") Signed-off-by: Beata Michalska beata.michalska@arm.com
arch/arm64/include/asm/ftrace.h | 4 ++++ arch/arm64/include/asm/syscall_wrapper.h | 5 ++++- arch/arm64/kernel/syscall.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 665373f441e1..89ff574a4a91 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -102,6 +102,10 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) return is_32bit_compat_task(); } +#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_CHERI_PURECAP_UABI) +#define ARCH_HAS_SYSCALL_ADDR +#endif
- #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME static inline bool arch_syscall_match_sym_name(const char *sym,
diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h index 97e08c4a6520..39957e54f8d3 100644 --- a/arch/arm64/include/asm/syscall_wrapper.h +++ b/arch/arm64/include/asm/syscall_wrapper.h @@ -141,7 +141,10 @@ struct pt_regs; #define __retptr__(name) name, _PTR #define __SYSCALL_ANNOTATE(name, ret_type) name, __SYSCALL_RET_T##ret_type #define SYSCALL_PREP(name, ...) __SYSCALL_ANNOTATE(_##name, __VA_ARGS__)
I still think that newline should stay.
Noted
+#ifdef CONFIG_FTRACE_SYSCALLS +#define SYSCALL_METADATA(x, name, ret_type, ...) \
- __SYSCALL_METADATA(x, name, __VA_ARGS__)
+#endif /* * Some syscalls with no parameters return valid capabilities, so __SYSCALL_DEFINE0 * is added to handle such cases. diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index a0e91ea7b74b..4942fcb4d299 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -105,6 +105,18 @@ static inline bool has_syscall_work(unsigned long flags) return unlikely(flags & _TIF_SYSCALL_WORK); } +#if defined(CONFIG_CHERI_PURECAP_UABI) && defined(CONFIG_FTRACE_SYSCALLS)
Nit: would be better in the same order as above (FTRACE_SYSCALLS first).
Ditto
BR B.
Kevin
+unsigned long __init arch_syscall_addr(int nr) +{
- /*
* In this particular case, it makes no difference,
* which member of the syscall_entry_t instance is being
* provided - the address is all that matters here
*/
- return (unsigned long)sys_call_table[nr].syscall_fn;
+} +#endif
- int syscall_trace_enter(struct pt_regs *regs); void syscall_trace_exit(struct pt_regs *regs);
The trace event framework, at this point, lacks support for capabilities as there is no way to properly output those when logging events, and casting a user pointer to a type that cannot actually hold a CHERI capability brings its own issues, so, for the time being, use user_ptr_addr to extract the address from a user pointer of interest.
Signed-off-by: Beata Michalska beata.michalska@arm.com --- include/trace/events/signal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/trace/events/signal.h b/include/trace/events/signal.h index 1db7e4b07c01..f3a83f8ce9ce 100644 --- a/include/trace/events/signal.h +++ b/include/trace/events/signal.h @@ -103,14 +103,14 @@ TRACE_EVENT(signal_deliver, __field( int, sig ) __field( int, errno ) __field( int, code ) - __field( unsigned long, sa_handler ) + __field( ptraddr_t, sa_handler ) __field( unsigned long, sa_flags ) ),
TP_fast_assign( __entry->sig = sig; TP_STORE_SIGINFO(__entry, info); - __entry->sa_handler = (unsigned long)ka->sa.sa_handler; + __entry->sa_handler = user_ptr_addr(ka->sa.sa_handler); __entry->sa_flags = ka->sa.sa_flags; ),
linux-morello@op-lists.linaro.org