Skip to content

Commit 7de5f68

Browse files
committed
signal/alpha: si_trapno is only used with SIGFPE and SIGTRAP TRAP_UNK
While reviewing the signal handlers on alpha it became clear that si_trapno is only set to a non-zero value when sending SIGFPE and when sending SITGRAP with si_code TRAP_UNK. Add send_sig_fault_trapno and send SIGTRAP TRAP_UNK, and SIGFPE with it. Remove the define of __ARCH_SI_TRAPNO and remove the always zero si_trapno parameter from send_sig_fault and force_sig_fault. v1: https://lkml.kernel.org/r/m1eeers7q7.fsf_-_@fess.ebiederm.org v2: https://lkml.kernel.org/r/20210505141101.11519-7-ebiederm@xmission.com Link: https://lkml.kernel.org/r/87h7gvxx7l.fsf_-_@disp2133 Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 2c9f7ea commit 7de5f68

7 files changed

Lines changed: 41 additions & 20 deletions

File tree

arch/alpha/include/uapi/asm/siginfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#ifndef _ALPHA_SIGINFO_H
33
#define _ALPHA_SIGINFO_H
44

5-
#define __ARCH_SI_TRAPNO
6-
75
#include <asm-generic/siginfo.h>
86

97
#endif

arch/alpha/kernel/osf_sys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
876876
if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
877877
if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
878878

879-
send_sig_fault(SIGFPE, si_code,
879+
send_sig_fault_trapno(SIGFPE, si_code,
880880
(void __user *)NULL, /* FIXME */
881881
0, current);
882882
}

arch/alpha/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)
219219

220220
/* Send SIGTRAP if we're single-stepping: */
221221
if (ptrace_cancel_bpt (current)) {
222-
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *) regs->pc, 0,
222+
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *) regs->pc,
223223
current);
224224
}
225225
return;
@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)
247247

248248
/* Send SIGTRAP if we're single-stepping: */
249249
if (ptrace_cancel_bpt (current)) {
250-
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *) regs->pc, 0,
250+
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *) regs->pc,
251251
current);
252252
}
253253
return;

arch/alpha/kernel/traps.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask,
227227
}
228228
die_if_kernel("Arithmetic fault", regs, 0, NULL);
229229

230-
send_sig_fault(SIGFPE, si_code, (void __user *) regs->pc, 0, current);
230+
send_sig_fault_trapno(SIGFPE, si_code, (void __user *) regs->pc, 0, current);
231231
}
232232

233233
asmlinkage void
@@ -268,13 +268,13 @@ do_entIF(unsigned long type, struct pt_regs *regs)
268268
regs->pc -= 4; /* make pc point to former bpt */
269269
}
270270

271-
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->pc, 0,
271+
send_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->pc,
272272
current);
273273
return;
274274

275275
case 1: /* bugcheck */
276-
send_sig_fault(SIGTRAP, TRAP_UNK, (void __user *) regs->pc, 0,
277-
current);
276+
send_sig_fault_trapno(SIGTRAP, TRAP_UNK,
277+
(void __user *) regs->pc, 0, current);
278278
return;
279279

280280
case 2: /* gentrap */
@@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)
335335
break;
336336
}
337337

338-
send_sig_fault(signo, code, (void __user *) regs->pc, regs->r16,
339-
current);
338+
send_sig_fault_trapno(signo, code, (void __user *) regs->pc,
339+
regs->r16, current);
340340
return;
341341

342342
case 4: /* opDEC */
@@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)
360360
if (si_code == 0)
361361
return;
362362
if (si_code > 0) {
363-
send_sig_fault(SIGFPE, si_code,
364-
(void __user *) regs->pc, 0,
365-
current);
363+
send_sig_fault_trapno(SIGFPE, si_code,
364+
(void __user *) regs->pc,
365+
0, current);
366366
return;
367367
}
368368
}
@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
387387
;
388388
}
389389

390-
send_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)regs->pc, 0, current);
390+
send_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)regs->pc, current);
391391
}
392392

393393
/* There is an ifdef in the PALcode in MILO that enables a
@@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs)
402402
{
403403
die_if_kernel("Instruction fault", regs, 0, NULL);
404404

405-
force_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)regs->pc, 0);
405+
force_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)regs->pc);
406406
}
407407

408408

@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode,
964964
si_code = SEGV_MAPERR;
965965
mmap_read_unlock(mm);
966966
}
967-
send_sig_fault(SIGSEGV, si_code, va, 0, current);
967+
send_sig_fault(SIGSEGV, si_code, va, current);
968968
return;
969969

970970
give_sigbus:
971971
regs->pc -= 4;
972-
send_sig_fault(SIGBUS, BUS_ADRALN, va, 0, current);
972+
send_sig_fault(SIGBUS, BUS_ADRALN, va, current);
973973
return;
974974
}
975975

arch/alpha/mm/fault.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
219219
mmap_read_unlock(mm);
220220
/* Send a sigbus, regardless of whether we were in kernel
221221
or user mode. */
222-
force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *) address, 0);
222+
force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *) address);
223223
if (!user_mode(regs))
224224
goto no_context;
225225
return;
226226

227227
do_sigsegv:
228-
force_sig_fault(SIGSEGV, si_code, (void __user *) address, 0);
228+
force_sig_fault(SIGSEGV, si_code, (void __user *) address);
229229
return;
230230

231231
#ifdef CONFIG_ALPHA_LARGE_VMALLOC

include/linux/sched/signal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data);
330330

331331
int force_sig_ptrace_errno_trap(int errno, void __user *addr);
332332
int force_sig_fault_trapno(int sig, int code, void __user *addr, int trapno);
333+
int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
334+
struct task_struct *t);
333335

334336
extern int send_sig_info(int, struct kernel_siginfo *, struct task_struct *);
335337
extern void force_sigsegv(int sig);

kernel/signal.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,23 @@ int force_sig_fault_trapno(int sig, int code, void __user *addr, int trapno)
18241824
return force_sig_info(&info);
18251825
}
18261826

1827+
/* For the rare architectures that include trap information using
1828+
* si_trapno.
1829+
*/
1830+
int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
1831+
struct task_struct *t)
1832+
{
1833+
struct kernel_siginfo info;
1834+
1835+
clear_siginfo(&info);
1836+
info.si_signo = sig;
1837+
info.si_errno = 0;
1838+
info.si_code = code;
1839+
info.si_addr = addr;
1840+
info.si_trapno = trapno;
1841+
return send_sig_info(info.si_signo, &info, t);
1842+
}
1843+
18271844
int kill_pgrp(struct pid *pid, int sig, int priv)
18281845
{
18291846
int ret;
@@ -3262,6 +3279,10 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)
32623279
else if (IS_ENABLED(CONFIG_SPARC) &&
32633280
(sig == SIGILL) && (si_code == ILL_ILLTRP))
32643281
layout = SIL_FAULT_TRAPNO;
3282+
else if (IS_ENABLED(CONFIG_ALPHA) &&
3283+
((sig == SIGFPE) ||
3284+
((sig == SIGTRAP) && (si_code == TRAP_UNK))))
3285+
layout = SIL_FAULT_TRAPNO;
32653286
#ifdef __ARCH_SI_TRAPNO
32663287
else if (layout == SIL_FAULT)
32673288
layout = SIL_FAULT_TRAPNO;

0 commit comments

Comments
 (0)