[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/15] target/mips: Fix potential integer overflow (CID 1452921)
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 01/15] target/mips: Fix potential integer overflow (CID 1452921) |
Date: |
Fri, 25 Jun 2021 11:23:15 +0200 |
Use the BIT_ULL() macro to ensure we use 64-bit arithmetic.
This fixes the following Coverity issue (OVERFLOW_BEFORE_WIDEN):
CID 1452921: Integer handling issues:
Potentially overflowing expression "1 << w" with type "int"
(32 bits, signed) is evaluated using 32-bit arithmetic, and
then used in a context that expects an expression of type
"uint64_t" (64 bits, unsigned).
Fixes: 074cfcb4dae ("target/mips: Implement hardware page table walker")
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20210505215119.1517465-1-f4bug@amsat.org>
---
target/mips/tcg/sysemu/tlb_helper.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/target/mips/tcg/sysemu/tlb_helper.c
b/target/mips/tcg/sysemu/tlb_helper.c
index 259f780d19f..a150a014ec1 100644
--- a/target/mips/tcg/sysemu/tlb_helper.c
+++ b/target/mips/tcg/sysemu/tlb_helper.c
@@ -17,6 +17,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu/osdep.h"
+#include "qemu/bitops.h"
#include "cpu.h"
#include "internal.h"
@@ -659,7 +660,7 @@ static int walk_directory(CPUMIPSState *env, uint64_t
*vaddr,
w = directory_index - 1;
if (directory_index & 0x1) {
/* Generate adjacent page from same PTE for odd TLB page */
- lsb = (1 << w) >> 6;
+ lsb = BIT_ULL(w) >> 6;
*pw_entrylo0 = entry & ~lsb; /* even page */
*pw_entrylo1 = entry | lsb; /* odd page */
} else if (dph) {
--
2.31.1
- [PULL 00/15] MIPS patches for 2021-06-25, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 01/15] target/mips: Fix potential integer overflow (CID 1452921),
Philippe Mathieu-Daudé <=
- [PULL 02/15] target/mips: Fix TCG temporary leaks in gen_pool32a5_nanomips_insn(), Philippe Mathieu-Daudé, 2021/06/25
- [PULL 03/15] target/mips: Fix more TCG temporary leaks in gen_pool32a5_nanomips_insn, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 04/15] target/mips: Raise exception when DINSV opcode used with DSP disabled, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 05/15] target/mips: Do not abort on invalid instruction, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 06/15] target/mips: Move TCG trace events to tcg/ sub directory, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 07/15] target/mips: Move translate.h to tcg/ sub directory, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 08/15] target/mips: Restrict some system specific declarations to sysemu, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 09/15] target/mips: Remove SmartMIPS / MDMX unuseful comments, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 10/15] target/mips: Remove microMIPS BPOSGE32 / BPOSGE64 unuseful cases, Philippe Mathieu-Daudé, 2021/06/25
- [PULL 11/15] target/mips: fix emulation of nanoMIPS BPOSGE32 instruction, Philippe Mathieu-Daudé, 2021/06/25