Skip to content

Commit 062aa46

Browse files
isakiisaki
authored andcommitted
m68k/fpe: Check an illegal mod/reg before decoding it.
This avoids a kernel panic if an instruction has illegal mod/reg bits like FMOVE.X FPn,#imm (Of course normally assemblers never emit these). XXX Other instructions probably need such treatment...
1 parent ff66f72 commit 062aa46

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

sys/arch/m68k/fpe/fpu_fstore.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: fpu_fstore.c,v 1.15 2025/01/03 05:42:50 isaki Exp $ */
1+
/* $NetBSD: fpu_fstore.c,v 1.16 2025/01/03 05:54:07 isaki Exp $ */
22

33
/*
44
* Copyright (c) 1995 Ken Nakata
@@ -26,7 +26,7 @@
2626
*/
2727

2828
#include <sys/cdefs.h>
29-
__KERNEL_RCSID(0, "$NetBSD: fpu_fstore.c,v 1.15 2025/01/03 05:42:50 isaki Exp $");
29+
__KERNEL_RCSID(0, "$NetBSD: fpu_fstore.c,v 1.16 2025/01/03 05:54:07 isaki Exp $");
3030

3131
#include <sys/types.h>
3232
#include <sys/signal.h>
@@ -49,6 +49,7 @@ fpu_emul_fstore(struct fpemu *fe, struct instruction *insn)
4949
int word1, sig;
5050
int regnum;
5151
int format;
52+
int modreg;
5253
uint32_t buf[3];
5354

5455
#if DEBUG_FPE
@@ -88,8 +89,17 @@ fpu_emul_fstore(struct fpemu *fe, struct instruction *insn)
8889

8990
fe->fe_fpsr &= ~FPSR_EXCP;
9091

91-
/* Get effective address. (modreg=opcode&077) */
92-
sig = fpu_decode_ea(frame, insn, &insn->is_ea, insn->is_opcode);
92+
/* Check an illegal mod/reg */
93+
modreg = insn->is_opcode & 077;
94+
if ((modreg >> 3) == 1/*An*/ || modreg >= 072/*PCrel and #imm*/) {
95+
#if DEBUG_FPE
96+
printf(" fpu_emul_fstore: illegal modreg=0%o\n", modreg);
97+
#endif
98+
return SIGILL;
99+
}
100+
101+
/* Get effective address. */
102+
sig = fpu_decode_ea(frame, insn, &insn->is_ea, modreg);
93103
if (sig) {
94104
#if DEBUG_FPE
95105
printf(" fpu_emul_fstore: failed in decode_ea sig=%d\n", sig);

0 commit comments

Comments
 (0)