ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls
PATCH 1/1 ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls
In https://bugs.gentoo.org/769614 Dmitry noticed that ptrace(PTRACE_GET_SYSCALL_INFO) does not work for syscalls called via glibc's syscall() wrapper.
ia64 has two ways to call syscalls from userspace: via break and via eps instructions.
The difference is in stack layout:
1. eps creates simple stack frame: no locals, in{0..7} = out{0..8}
2. break uses userspace stack frame: may be locals (glibc provides one), in{0..7} = out{0..8}.
Both work fine in syscall handling cde itself.
But ptrace(PTRACE_GET_SYSCALL_INFO) uses unwind mechanism to re-extract syscall arguments but it does not account for locals.
The change always skips locals registers. It should not change eps path as kernel's handler already enforces locals=0 and fixes break.
Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
--- arch/ia64/kernel/ptrace.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
arch/ia64/kernel/ptrace.c +18 -5
@@ -2013,27 +2013,39 @@ static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) {struct syscall_get_set_args *args = data;struct pt_regs *pt = args->regs; -unsigned long *krbs, cfm, ndirty; +unsigned long *krbs, cfm, ndirty, nlocals, nouts;int i, count;if (unw_unwind_to_user (info) <0 )return ; +/* +* We get here via a few paths: +* - break instruction: cfm is shared with caller. +* syscall args are in out= regs, locals are non-empty. +* - epsinstruction: cfm is set by br.call +* locals don't exist. +* +* For both cases argguments are reachable in cfm.sof - cfm.sol. +* CFM: [ ... | sor: 17..14 | sol : 13..7 | sof : 6..0 ] +*/ cfm = pt->cr_ifs; + nlocals = (cfm >>7 ) &0x7f ;/* aka sol */ + nouts = (cfm &0x7f ) - nlocals;/* aka sof - sol */ krbs = (unsigned long *)info->task +IA64_RBS_OFFSET /8 ; ndirty =ia64_rse_num_regs (krbs, krbs + (pt->loadrs >>19 )); count =0 ;if (in_syscall (pt)) - count =min_t (int, args->n, cfm &0x7f ); + count =min_t (int, args->n, nouts); +/* Iterate over outs. */ for (i =0 ; i < count; i++) { +int j = ndirty + nlocals + i + args->i;if (args->rw) - *ia64_rse_skip_regs (krbs, ndirty + i + args->i) - args->args[i]; + *ia64_rse_skip_regs (krbs, j) = args->args[i];else - args->args[i] = *ia64_rse_skip_regs (krbs, - ndirty + i + args->i); + args->args[i] = *ia64_rse_skip_regs (krbs, j); }if (!args->rw) {
Signature · 1 line
2.30.1
PATCH 1/1 ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
In https://bugs.gentoo.org/769614 Dmitry noticed that ptrace(PTRACE_GET_SYSCALL_INFO) does not return error sign properly.
The bug is in mismatch between get/set errors:
static inline long syscall_get_error(struct task_struct *task,
struct pt_regs *regs)
{
return regs->r10 = -1 ? regs->r8:0;
}static inline long syscall_get_return_value(struct task_struct *task,
struct pt_regs *regs)
{
return regs->r8;
}static inline void syscall_set_return_value(struct task_struct *task,
struct pt_regs *regs, int error, long val)
{
if (error) {
/* error < 0, but ia64 uses > 0 return value */
regs->r8 = -error;
regs->r10 = -1;
} else {
regs->r8 = val;
regs->r10 = 0;
}
}Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
--- arch/ia64/include/asm/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/include/asm/syscall.h +1 -1
@@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct *task,static inline long syscall_get_error (struct task_struct *task,struct pt_regs *regs) { -return regs->r10 =-1 ? regs->r8:0 ; +return regs->r10 =-1 ? -regs->r8:0 ; } static inline long syscall_get_return_value(struct task_struct *task,
Signature · 1 line
2.30.1
Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
Hi Sergei!
Quoted 3 lines · Sergei Trofimovich
In https://bugs.gentoo.org/769614 Dmitry noticed that
ptrace(PTRACE_GET_SYSCALL_INFO)does not return error sign properly. (...)
Do these two patches unbreak gdb on ia64?
And have you, by any chance, managed to get the hpsa driver working again?
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
Quoted 8 lines · On Sun, 21 Feb 2021 10:21:56 +0100 John Paul Adrian Glaubitz…
Hi Sergei!
Quoted 3 lines · Sergei Trofimovich
In https://bugs.gentoo.org/769614 Dmitry noticed that
ptrace(PTRACE_GET_SYSCALL_INFO)does not return error sign properly. (...)Do these two patches unbreak gdb on ia64?
gdb was somewhat working on ia64 for Gentoo. strace was the main impacted here.
But I did not try anything complicated recently. Anything specific that breaks for you?
$ uname -r 5.10.0 (even without the patches above)
$ cat c.c
int main(){}
$ gcc c.c -o a -ggdb3
$ gdb --quiet ./a
Reading symbols from ./a...
(gdb) start
Temporary breakpoint 1 at 0x7f2: file c.c, line 1.
Starting program: /home/slyfox/a
Failed to read a valid object file image from memory.Temporary breakpoint 1, main () at c.c:1
1 int main(){}
(gdb) disassemble
Dump of assembler code for function main:
0x20000008000007f0 <+0>: [MII] mov r2=r12 0x20000008000007f1 <+1>: mov r14=r0;; => 0x20000008000007f2 <+2>: mov r8=r14 0x2000000800000800 <+16>: [MIB] mov r12=r2 0x2000000800000801 <+17>: nop.i 0x0 0x2000000800000802 <+18>: br.ret.sptk.many b0;;
End of assembler dump.
(gdb) break *0x2000000800000800
Breakpoint 2 at 0x2000000800000800: file c.c, line 1. (gdb) continue
Continuing.
Breakpoint 2, 0x2000000800000800 in main () at c.c:1
1 int main(){}
Looks ok for minor stuff.
Quoted 1 line
And have you, by any chance, managed to get the hpsa driver working again?
v5.10 seems to boot off hpsa just fine without extra patches:
14:01.0 RAID bus controller: Hewlett-Packard Company Smart Array P600
Subsystem: Hewlett-Packard Company 3 Gb/s SAS RAID Kernel driver in use: hpsa
v5.11 does not boot yet. Kernel does not see some files while boots after init is started (but I'm not sure it's a block device problem). Bisecting now why.
Signature · 1 line
Sergei
Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
In reply to Sergei TrofimovichQuoted 59 lines · On Sun, 21 Feb 2021 00:25:54 +0000 Sergei Trofimovich <[email protected]> wrote:
In https://bugs.gentoo.org/769614 Dmitry noticed that
ptrace(PTRACE_GET_SYSCALL_INFO)does not return error sign properly.The bug is in mismatch between get/set errors:
static inline long syscall_get_error(struct
task_struct*task,
structpt_regs*regs){ return regs->r10 = -1 ? regs->r8:0; }static inline long syscall_get_return_value(struct
task_struct*task,
structpt_regs*regs){ return regs->r8; }static inline void syscall_set_return_value(struct
task_struct*task,
structpt_regs*regs, int error, long val){ if (error) { /* error < 0, but ia64 uses > 0 return value */ regs->r8 = -error; regs->r10 = -1; } else { regs->r8 = val; regs->r10 = 0; } }Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
CC Andrew Morton <[email protected]>Reported-by Dmitry V. Levin <[email protected]>Signed-off-by Sergei Trofimovich <[email protected]>--- arch/ia64/include/asm/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/ia64/include/asm/syscall.h +1
-1@@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct *task,static inline long syscall_get_error (struct task_struct *task,struct pt_regs *regs) { -return regs->r10 =-1 ? regs->r8:0 ; +return regs->r10 =-1 ? -regs->r8:0 ; } static inline long syscall_get_return_value(struct task_struct *task,Signature · 1 line
2.30.1
Andrew, would it be fine to pass it through misc tree? Or should it go through Oleg as it's mostly about ptrace?
Signature · 1 line
Sergei
Oleg Nesterov
maintainerRe: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
Quoted 11 lines · Sergei Trofimovich
Quoted 11 lines
arch/ia64/include/asm/syscall.h +1
-1@@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct *task,static inline long syscall_get_error (struct task_struct *task,struct pt_regs *regs) { -return regs->r10 =-1 ? regs->r8:0 ; +return regs->r10 =-1 ? -regs->r8:0 ; }
Quoted 7 lines
Quoted 4 lines
arch/ia64/include/asm/syscall.h +0
-1static inline long syscall_get_return_value(struct task_struct *task, --2.30.1
Andrew, would it be fine to pass it through misc tree? Or should it go through Oleg as it's mostly about ptrace?
We usually route ptrace fixes via mm tree.
But this fix and another patch from you "ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls" look very much ia64 specific. I don't think it's actually about ptrace, and I didn't even try to review these patches because I do not understand this low level ia64 code.
Can it be routed via ia64 tree? Add Tony and Fenghua...
Oleg.
Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
Quoted 20 lines · Oleg Nesterov
Quoted 11 lines · Sergei Trofimovich
Quoted 11 lines
arch/ia64/include/asm/syscall.h +1
-1@@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct *task,static inline long syscall_get_error (struct task_struct *task,struct pt_regs *regs) { -return regs->r10 =-1 ? regs->r8:0 ; +return regs->r10 =-1 ? -regs->r8:0 ; }Quoted 7 lines
Quoted 4 lines
arch/ia64/include/asm/syscall.h +0
-1static inline long syscall_get_return_value(struct task_struct *task, --2.30.1
Andrew, would it be fine to pass it through misc tree? Or should it go through Oleg as it's mostly about ptrace?
Quoted 8 lines
We usually route ptrace fixes via mm tree.
But this fix and another patch from you "ia64: fix
ia64_syscall_get_set_arguments()for break-based syscalls" look very much ia64 specific. I don't think it's actually about ptrace, and I didn't even try to review these patches because I do not understand this low level ia64 code.Can it be routed via ia64 tree? Add Tony and Fenghua...
Apparently [1], ia64 architecture is now orphaned, so we don't have this option anymore.
[1] https://git.kernel.org/torvalds/c/96ec72a3425d1515b69b7f9dc34a4a6ce5862a37
Signature · 1 line
ldv
Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign
In reply to Sergei TrofimovichQuoted 48 lines · Sergei Trofimovich
In https://bugs.gentoo.org/769614 Dmitry noticed that
ptrace(PTRACE_GET_SYSCALL_INFO)does not return error sign properly.The bug is in mismatch between get/set errors:
static inline long syscall_get_error(struct
task_struct*task,
structpt_regs*regs){ return regs->r10 = -1 ? regs->r8:0; }static inline long syscall_get_return_value(struct
task_struct*task,
structpt_regs*regs){ return regs->r8; }static inline void syscall_set_return_value(struct
task_struct*task,
structpt_regs*regs, int error, long val){ if (error) { /* error < 0, but ia64 uses > 0 return value */ regs->r8 = -error; regs->r10 = -1; } else { regs->r8 = val; regs->r10 = 0; } }Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
CC Andrew Morton <[email protected]>Reported-by Dmitry V. Levin <[email protected]>Signed-off-by Sergei Trofimovich <[email protected]>--- arch/ia64/include/asm/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/ia64/include/asm/syscall.h +0
-0
arch/ia64/include/asm/syscall.h static inline void syscall_rollback(struct task_struct *task, · line 38
Quoted 8 lines
arch/ia64/include/asm/syscall.h +1
-1@@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct *task,static inline long syscall_get_error (struct task_struct *task,struct pt_regs *regs) { -return regs->r10 =-1 ? regs->r8:0 ; +return regs->r10 =-1 ? -regs->r8:0 ; } static inline long syscall_get_return_value(struct task_struct *task,
Signature · 1 line
ldv
Quoted 86 lines · On Sun, 21 Feb 2021 00:25:53 +0000 Sergei Trofimovich <[email protected]> wrote:
In https://bugs.gentoo.org/769614 Dmitry noticed that
ptrace(PTRACE_GET_SYSCALL_INFO)does not work for syscalls called via glibc'ssyscall()wrapper.ia64 has two ways to call syscalls from userspace: via
breakand viaepsinstructions.The difference is in stack layout:
1.
epscreates simple stack frame: no locals, in{0..7} = out{0..8}
2.breakuses userspace stack frame: may be locals (glibc provides one), in{0..7} = out{0..8}.Both work fine in syscall handling cde itself.
But
ptrace(PTRACE_GET_SYSCALL_INFO)uses unwind mechanism to re-extract syscall arguments but it does not account for locals.The change always skips locals registers. It should not change
epspath as kernel's handler already enforces locals=0 and fixesbreak.Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
CC Oleg Nesterov <[email protected]>CC Andrew Morton <[email protected]>Reported-by Dmitry V. Levin <[email protected]>Signed-off-by Sergei Trofimovich <[email protected]>--- arch/ia64/kernel/ptrace.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)arch/ia64/kernel/ptrace.c +18
-5@@ -2013,27 +2013,39 @@ static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) {struct syscall_get_set_args *args = data;struct pt_regs *pt = args->regs; -unsigned long *krbs, cfm, ndirty; +unsigned long *krbs, cfm, ndirty, nlocals, nouts;int i, count;if (unw_unwind_to_user (info) <0 )return ; +/* +* We get here via a few paths: +* - break instruction: cfm is shared with caller. +* syscall args are in out= regs, locals are non-empty. +* - epsinstruction: cfm is set by br.call +* locals don't exist. +* +* For both cases argguments are reachable in cfm.sof - cfm.sol. +* CFM: [ ... | sor: 17..14 | sol : 13..7 | sof : 6..0 ] +*/ cfm = pt->cr_ifs; + nlocals = (cfm >>7 ) &0x7f ;/* aka sol */ + nouts = (cfm &0x7f ) - nlocals;/* aka sof - sol */ krbs = (unsigned long *)info->task +IA64_RBS_OFFSET /8 ; ndirty =ia64_rse_num_regs (krbs, krbs + (pt->loadrs >>19 )); count =0 ;if (in_syscall (pt)) - count =min_t (int, args->n, cfm &0x7f ); + count =min_t (int, args->n, nouts); +/* Iterate over outs. */ for (i =0 ; i < count; i++) { +int j = ndirty + nlocals + i + args->i;if (args->rw) - *ia64_rse_skip_regs (krbs, ndirty + i + args->i) > - args->args[i]; + *ia64_rse_skip_regs (krbs, j) = args->args[i];else - args->args[i] = *ia64_rse_skip_regs (krbs, - ndirty + i + args->i); + args->args[i] = *ia64_rse_skip_regs (krbs, j); }if (!args->rw) {Signature · 1 line
2.30.1
Andrew, would it be fine to pass it through misc tree? Or should it go through Oleg as it's about ptrace?
Signature · 1 line
Sergei
Quoted 45 lines · Sergei Trofimovich
In https://bugs.gentoo.org/769614 Dmitry noticed that
ptrace(PTRACE_GET_SYSCALL_INFO)does not work for syscalls called via glibc'ssyscall()wrapper.ia64 has two ways to call syscalls from userspace: via
breakand viaepsinstructions.The difference is in stack layout:
1.
epscreates simple stack frame: no locals, in{0..7} = out{0..8}
2.breakuses userspace stack frame: may be locals (glibc provides one), in{0..7} = out{0..8}.Both work fine in syscall handling cde itself.
But
ptrace(PTRACE_GET_SYSCALL_INFO)uses unwind mechanism to re-extract syscall arguments but it does not account for locals.The change always skips locals registers. It should not change
epspath as kernel's handler already enforces locals=0 and fixesbreak.Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
CC Oleg Nesterov <[email protected]>CC Andrew Morton <[email protected]>Reported-by Dmitry V. Levin <[email protected]>Signed-off-by Sergei Trofimovich <[email protected]>--- arch/ia64/kernel/ptrace.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)arch/ia64/kernel/ptrace.c +1
-1@@ -2013,27 +2013,39 @@ static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) {struct syscall_get_set_args *args = data;struct pt_regs *pt = args->regs; -unsigned long *krbs, cfm, ndirty; +unsigned long *krbs, cfm, ndirty, nlocals, nouts;int i, count;
arch/ia64/kernel/ptrace.c static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) · line 2027
Quoted 10 lines
arch/ia64/kernel/ptrace.c +6
-0if (unw_unwind_to_user (info) <0 )return ; +/* +* We get here via a few paths: +* - break instruction: cfm is shared with caller. +* syscall args are in out= regs, locals are non-empty. +* - epsinstruction: cfm is set by br.call +* locals don't exist.
typo: epsinstruction
arch/ia64/kernel/ptrace.c static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) · line 2029
Quoted 2 lines
arch/ia64/kernel/ptrace.c +2
-0+* +* For both cases argguments are reachable in cfm.sof - cfm.sol.
typo: argguments
Quoted 16 lines
arch/ia64/kernel/ptrace.c +7
-1+* CFM: [ ... | sor: 17..14 | sol : 13..7 | sof : 6..0 ] +*/ cfm = pt->cr_ifs; + nlocals = (cfm >>7 ) &0x7f ;/* aka sol */ + nouts = (cfm &0x7f ) - nlocals;/* aka sof - sol */ krbs = (unsigned long *)info->task +IA64_RBS_OFFSET /8 ; ndirty =ia64_rse_num_regs (krbs, krbs + (pt->loadrs >>19 )); count =0 ;if (in_syscall (pt)) - count =min_t (int, args->n, cfm &0x7f ); + count =min_t (int, args->n, nouts); +/* Iterate over outs. */ for (i =0 ; i < count; i++) { +int j = ndirty + nlocals + i + args->i;
arch/ia64/kernel/ptrace.c static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) · line 2051
Quoted 10 lines
arch/ia64/kernel/ptrace.c +2
-3if (args->rw) - *ia64_rse_skip_regs (krbs, ndirty + i + args->i) > - args->args[i]; + *ia64_rse_skip_regs (krbs, j) = args->args[i];else - args->args[i] = *ia64_rse_skip_regs (krbs, - ndirty + i + args->i); + args->args[i] = *ia64_rse_skip_regs (krbs, j); }if (!args->rw) {
This stuff is too ia64 specific, so I cannot properly review this patch, but it definitely fixes ia64 PTRACE_GET_SYSCALL_INFO on entering syscall.
Signature · 1 line
ldv