LoongArch: Store syscall nr in thread_info
Subsystems (3)
PATCH 1/1 LoongArch: Store syscall nr in thread_info
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take execve as an example:
sys_execve
-> do_execve
-> do_execveat_common
-> bprm_execve
-> exec_binprm
-> search_binary_handler
-> load_elf_binary
-> ELF_PLAT_INITELF_PLAT_INIT reset regs[11] to 0, later in syscall_exit_to_user_mode we get a wrong syscall nr.
Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in thread_info instead.
--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
arch/loongarch/include/asm/syscall.h +1 -1
@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,
arch/loongarch/kernel/syscall.c +1 -0
@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) {
Signature · 1 line
2.42.0
Huacai Chen
maintainerHi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INIT
Quoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.
Can we just modify ELF_PLAT_INIT and not clear regs[11]?
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Hi, Huacai,
Quoted 20 lines · Huacai Chen
Hi, Hengqi,
Quoted 16 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INIT
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.
Quoted 7 lines
Quoted 5 lines
Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?
I am uncertain about the side effects of changing ELF_PLAT_INIT. From a completeness perspective, changing ELF_PLAT_INIT is suboptimal, rt_sigreturn is affected in another code path, and there may be other syscalls that I am unaware of.
Quoted 38 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Huacai Chen
maintainerHi, Hengqi,
Quoted 28 lines · Hengqi Chen
Hi, Huacai,
Quoted 24 lines · Huacai Chen
Hi, Hengqi,
Quoted 20 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INIT
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.
Save syscall number in thread_info has more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].
And about ELF_PLAT_INIT, maybe Arnd can give us some more information.
Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?
Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?
Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].
How about the change below:
(quoted diff) +0 -0
b/arch/loongarch/include/asm/syscall.h
index e286dc58476e..954ba53bcc9a 100644
arch/loongarch/include/asm/syscall.h +3 -1
@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,
arch/loongarch/kernel/syscall.c +2 -0
@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];
@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }
* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even if rt_sigreturn clobbers all pt_regs::regs
Quoted 49 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Huacai Chen
maintainerHi, Hengqi,
Quoted 84 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +2
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }
Quoted 3 lines
* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regs
No, I still prefer to modify ELF_PLAT_INIT, we can wait Arnd's comments.
And, do you mean modifying ELF_PLAT_INIT cannot solve the rt_sigreturn's problem?
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }
Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.
OK, I am not eager, anyway, we know the root cause. :)
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?
Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Quoted 53 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Huacai Chen
maintainerQuoted 96 lines · Hengqi Chen
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.
Quoted 7 lines
OK, I am not eager, anyway, we know the root cause. :)
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Is this the expected behavior for rt_sigreturn()? Otherwise I think RISC-V has the same problem. And if we really need the 'correct' syscall number, we can overwrite regs[11] in sys_rt_sigreturn().
And another question: do you have any updates about the BPF system hang problem? :)
Huacai
Quoted 54 lines
Quoted 54 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Quoted 100 lines · Huacai Chen
Quoted 98 lines · Hengqi Chen
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.OK, I am not eager, anyway, we know the root cause. :)
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Is this the expected behavior for
rt_sigreturn()? Otherwise I think RISC-V has the same problem. And if we really need the 'correct' syscall number, we can overwrite regs[11] insys_rt_sigreturn().
I check with x86 and arm64, both have the same issue, seems no one care.
Quoted 3 lines
And another question: do you have any updates about the BPF system hang problem? :)
Let's discuss this on a new thread.
Quoted 56 lines
Huacai
Quoted 54 lines
Quoted 54 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Huacai Chen
maintainerHi, Hengqi,
Quoted 106 lines · Hengqi Chen
Quoted 104 lines · Huacai Chen
Quoted 102 lines · Hengqi Chen
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.OK, I am not eager, anyway, we know the root cause. :)
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Is this the expected behavior for
rt_sigreturn()? Otherwise I think RISC-V has the same problem. And if we really need the 'correct' syscall number, we can overwrite regs[11] insys_rt_sigreturn().I check with x86 and arm64, both have the same issue, seems no one care.
Does the rt_sigreturn issue affect execsnoop?
Huacai
Quoted 64 lines
Quoted 4 lines
And another question: do you have any updates about the BPF system hang problem? :)
Let's discuss this on a new thread.
Quoted 56 lines
Huacai
Quoted 54 lines
Quoted 54 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Quoted 110 lines · Huacai Chen
Hi, Hengqi,
Quoted 106 lines · Hengqi Chen
Quoted 104 lines · Huacai Chen
Quoted 102 lines · Hengqi Chen
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.OK, I am not eager, anyway, we know the root cause. :)
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Is this the expected behavior for
rt_sigreturn()? Otherwise I think RISC-V has the same problem. And if we really need the 'correct' syscall number, we can overwrite regs[11] insys_rt_sigreturn().I check with x86 and arm64, both have the same issue, seems no one care.
Does the
rt_sigreturnissue affect execsnoop?
No, execsnoop only relies on sys_enter_execve/sys_exit_execve.
Quoted 66 lines
Huacai
Quoted 64 lines
Quoted 4 lines
And another question: do you have any updates about the BPF system hang problem? :)
Let's discuss this on a new thread.
Quoted 56 lines
Huacai
Quoted 54 lines
Quoted 54 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Huacai Chen
maintainerHi, Hengqi,
Quoted 118 lines · Hengqi Chen
Quoted 116 lines · Huacai Chen
Hi, Hengqi,
Quoted 112 lines · Hengqi Chen
Quoted 109 lines · Huacai Chen
Quoted 96 lines · Hengqi Chen
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.Quoted 7 lines
OK, I am not eager, anyway, we know the root cause. :)
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Is this the expected behavior for
rt_sigreturn()? Otherwise I think RISC-V has the same problem. And if we really need the 'correct' syscall number, we can overwrite regs[11] insys_rt_sigreturn().
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I check with x86 and arm64, both have the same issue, seems no one care.
Does the
rt_sigreturnissue affect execsnoop?No, execsnoop only relies on sys_enter_execve/sys_exit_execve.
Then I suggest the below one line patch, though Arnd still no response, I believe it has no side effect (because ARM64 and RISC-V clear nothing here):
arch/loongarch/include/asm/elf.h +1 -1
@@ -293,7 +293,7 @@ extern const char *__elf_platform; #define ELF_PLAT_INIT(_r, load_addr) do { \ _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \ _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \ - _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \ + _r->regs[9] = _r->regs[10] = /* syscall */ = _r->regs[12] = 0; \ _r->regs[13] = _r->regs[14] = _r->regs[15] = _r->regs[16] = 0; \ _r->regs[17] = _r->regs[18] = _r->regs[19] = _r->regs[20] = 0; \ _r->regs[21] = _r->regs[22] = _r->regs[23] = _r->regs[24] = 0; \
Quoted 67 lines
Quoted 67 lines
Huacai
Quoted 64 lines
Quoted 4 lines
And another question: do you have any updates about the BPF system hang problem? :)
Let's discuss this on a new thread.
Quoted 56 lines
Huacai
Quoted 54 lines
Quoted 54 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0
Hi, Huacai,
Thanks for the suggestion, just send the fix.
Cheers,
---
Hengqi
Quoted 212 lines · Huacai Chen
Hi, Hengqi,
Quoted 118 lines · Hengqi Chen
Quoted 116 lines · Huacai Chen
Hi, Hengqi,
Quoted 112 lines · Hengqi Chen
Quoted 109 lines · Huacai Chen
Quoted 96 lines · Hengqi Chen
Quoted 84 lines · Huacai Chen
Hi, Hengqi,
Quoted 80 lines · Hengqi Chen
Quoted 36 lines · Huacai Chen
Hi, Hengqi,
Quoted 32 lines · Hengqi Chen
Hi, Huacai,
Quoted 27 lines · Huacai Chen
Hi, Hengqi,
Quoted 13 lines · Hengqi Chen
Currently, we store syscall number in pt_regs::regs[11] and it may be changed during syscall execution. Take
execveas an example:sys_execve -> do_execve -> do_execveat_common -> bprm_execve -> exec_binprm -> search_binary_handler -> load_elf_binary -> ELF_PLAT_INITQuoted 8 lines
ELF_PLAT_INITreset regs[11] to 0, later insyscall_exit_to_user_modewe get a wrong syscall nr.Known affected syscalls includes execve/execveat/rt_sigreturn. Tools like execsnoop do not work properly because the sys_exit_* tracepoints does not trigger at all.
Let's store syscall nr in
thread_infoinstead.Can we just modify
ELF_PLAT_INITand not clear regs[11]?Quoted 8 lines
Quoted 4 lines
I am uncertain about the side effects of changing
ELF_PLAT_INIT. From a completeness perspective, changingELF_PLAT_INITis suboptimal,rt_sigreturnis affected in another code path, and there may be other syscalls that I am unaware of.Save syscall number in
thread_infohas more side effects, because ptrace allows us to change the number during syscall, then we should keep consistency between syscall and regs[11].How about the change below:
arch/loongarch/include/asm/syscall.h +3
-1@@ -23,7 +23,9 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +long nr =task_thread_info (task)->syscall; + +return nr ? : regs->regs[11 ]; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-0@@ -53,6 +53,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->regs[4 ] = -ENOSYS ; nr =syscall_enter_from_user_mode (regs, nr); +current_thread_info ()->syscall = nr;if (nr < NR_syscalls) { syscall_fn = sys_call_table[nr];@@ -61,4 +62,5 @@ void noinstr do_syscall(struct pt_regs *regs) }Quoted 9 lines
Quoted 7 lines
arch/loongarch/kernel/syscall.c +1
-0syscall_exit_to_user_mode (regs); +current_thread_info ()->syscall =0 ; }* allow ptrace to change syscall nr
* sys_exit_* will also see the right syscall nr
* this works even ifrt_sigreturnclobbers allpt_regs::regsNo, I still prefer to modify
ELF_PLAT_INIT, we can wait Arnd's comments.Quoted 7 lines
OK, I am not eager, anyway, we know the root cause. :)
Quoted 3 lines
And, do you mean modifying
ELF_PLAT_INITcannot solve the rt_sigreturn's problem?Right, see https://elixir.bootlin.com/linux/latest/source/arch/loongarch/kernel/signal.c#L807
Is this the expected behavior for
rt_sigreturn()? Otherwise I think RISC-V has the same problem. And if we really need the 'correct' syscall number, we can overwrite regs[11] insys_rt_sigreturn().Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I check with x86 and arm64, both have the same issue, seems no one care.
Does the
rt_sigreturnissue affect execsnoop?No, execsnoop only relies on sys_enter_execve/sys_exit_execve.
Then I suggest the below one line patch, though Arnd still no response, I believe it has no side effect (because ARM64 and RISC-V clear nothing here):
arch/loongarch/include/asm/elf.h +1
-1@@ -293,7 +293,7 @@ extern const char *__elf_platform; #define ELF_PLAT_INIT(_r, load_addr) do { \ _r->regs[1] = _r->regs[2] = _r->regs[3] = _r->regs[4] = 0; \ _r->regs[5] = _r->regs[6] = _r->regs[7] = _r->regs[8] = 0; \ - _r->regs[9] = _r->regs[10] = _r->regs[11] = _r->regs[12] = 0; \ + _r->regs[9] = _r->regs[10] = /* syscall */ = _r->regs[12] = 0; \ _r->regs[13] = _r->regs[14] = _r->regs[15] = _r->regs[16] = 0; \ _r->regs[17] = _r->regs[18] = _r->regs[19] = _r->regs[20] = 0; \ _r->regs[21] = _r->regs[22] = _r->regs[23] = _r->regs[24] = 0; \Quoted 68 lines
Quoted 68 lines
Huacai
Quoted 64 lines
Quoted 4 lines
And another question: do you have any updates about the BPF system hang problem? :)
Let's discuss this on a new thread.
Quoted 56 lines
Huacai
Quoted 54 lines
Quoted 54 lines
Huacai
Quoted 51 lines
Quoted 50 lines
And about
ELF_PLAT_INIT, maybe Arnd can give us some more information.Hi, Arnd,
I found some new architectures, such as ARM64 and RISC-V, just do nearly nothing in
ELF_PLAT_INIT, while some old architectures, such as x86 and MIPS, clear most of the registers, do you know why?Huacai
Quoted 39 lines
Quoted 39 lines
Huacai
Quoted 36 lines
Fixes be769645a2aef ("LoongArch: Add system call support")Signed-off-by Hengqi Chen <[email protected]>--- arch/loongarch/include/asm/syscall.h | 2 +- arch/loongarch/kernel/syscall.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)arch/loongarch/include/asm/syscall.h +1
-1@@ -23,7 +23,7 @@ extern void *sys_call_table[];static inline long syscall_get_nr (struct task_struct *task,struct pt_regs *regs) { -return regs->regs[11 ]; +return task_thread_info (task)->syscall; } static inline void syscall_rollback(struct task_struct *task,arch/loongarch/kernel/syscall.c +1
-1@@ -52,6 +52,7 @@ void noinstr do_syscall(struct pt_regs *regs) regs->orig_a0 = regs->regs[4 ]; regs->regs[4 ] = -ENOSYS ; +task_thread_info (current)->syscall = nr; nr =syscall_enter_from_user_mode (regs, nr);if (nr < NR_syscalls) { --2.42.0