linux-loongson/arch/parisc/math-emu
Helge Deller de3629baf5 parisc: Fix double SIGFPE crash
Camm noticed that on parisc a SIGFPE exception will crash an application with
a second SIGFPE in the signal handler.  Dave analyzed it, and it happens
because glibc uses a double-word floating-point store to atomically update
function descriptors. As a result of lazy binding, we hit a floating-point
store in fpe_func almost immediately.

When the T bit is set, an assist exception trap occurs when when the
co-processor encounters *any* floating-point instruction except for a double
store of register %fr0.  The latter cancels all pending traps.  Let's fix this
by clearing the Trap (T) bit in the FP status register before returning to the
signal handler in userspace.

The issue can be reproduced with this test program:

root@parisc:~# cat fpe.c

static void fpe_func(int sig, siginfo_t *i, void *v) {
        sigset_t set;
        sigemptyset(&set);
        sigaddset(&set, SIGFPE);
        sigprocmask(SIG_UNBLOCK, &set, NULL);
        printf("GOT signal %d with si_code %ld\n", sig, i->si_code);
}

int main() {
        struct sigaction action = {
                .sa_sigaction = fpe_func,
                .sa_flags = SA_RESTART|SA_SIGINFO };
        sigaction(SIGFPE, &action, 0);
        feenableexcept(FE_OVERFLOW);
        return printf("%lf\n",1.7976931348623158E308*1.7976931348623158E308);
}

root@parisc:~# gcc fpe.c -lm
root@parisc:~# ./a.out
 Floating point exception

root@parisc:~# strace -f ./a.out
 execve("./a.out", ["./a.out"], 0xf9ac7034 /* 20 vars */) = 0
 getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
 ...
 rt_sigaction(SIGFPE, {sa_handler=0x1110a, sa_mask=[], sa_flags=SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
 --- SIGFPE {si_signo=SIGFPE, si_code=FPE_FLTOVF, si_addr=0x1078f} ---
 --- SIGFPE {si_signo=SIGFPE, si_code=FPE_FLTOVF, si_addr=0xf8f21237} ---
 +++ killed by SIGFPE +++
 Floating point exception

Signed-off-by: Helge Deller <deller@gmx.de>
Suggested-by: John David Anglin <dave.anglin@bell.net>
Reported-by: Camm Maguire <camm@maguirefamily.org>
Cc: stable@vger.kernel.org
2025-05-04 17:30:03 +02:00
..
cnv_float.h Merge branch 'parisc-5.2-3' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux 2019-06-06 13:13:09 -07:00
dbl_float.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
decode_exc.c parisc: align '*' in comment in math-emu code 2022-06-26 00:19:27 +02:00
denormal.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
dfadd.c parisc: Fix typos in comments 2022-05-08 20:01:12 +02:00
dfcmp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
dfdiv.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
dfmpy.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
dfrem.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
dfsqrt.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
dfsub.c parisc: Fix typos in comments 2022-05-08 20:01:12 +02:00
driver.c parisc: Fix double SIGFPE crash 2025-05-04 17:30:03 +02:00
fcnvff.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
fcnvfu.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
fcnvfut.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
fcnvfx.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
fcnvfxt.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
fcnvuf.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
fcnvxf.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
float.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
fmpyfadd.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
fpbits.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
fpu.h parisc: math-emu: Few spelling fixes in the file fpu.h 2021-04-06 15:34:14 +02:00
fpudispatch.c parisc: math-emu: Fix fall-through warnings 2021-09-01 22:18:18 +02:00
frnd.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
hppa.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
Makefile parisc: math-emu: Avoid compiler warnings with W=1 2023-07-03 18:56:03 +02:00
math-emu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
README
sfadd.c parisc: Fix typos in comments 2022-05-08 20:01:12 +02:00
sfcmp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
sfdiv.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
sfmpy.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
sfrem.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00
sfsqrt.c parisc: avoid c23 'nullptr' idenitifier 2024-02-27 22:51:44 +01:00
sfsub.c parisc: Fix typos in comments 2022-05-08 20:01:12 +02:00
sgl_float.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 150 2019-05-30 11:25:19 -07:00

All files except driver.c are snapshots from the HP-UX kernel.  They've
been modified as little as possible.  Even though they don't fit the
Linux coding style, please leave them in their funny format just in case
someone in the future, with access to HP-UX source code, is generous
enough to update our copies with later changes from HP-UX -- it'll
make their 'diff' job easier if our code is relatively unmodified.

Required Disclaimer: Hewlett-Packard makes no implied or expressed
warranties about this code nor any promises to maintain or test it
in any way.  This copy of this snapshot is no longer the property
of Hewlett-Packard.