Skip to contentSkip to conversation

sandbox: fix signed integer overflow

PATCH Applied Ahmad Fatoum 2 participants 3 messages Feb 3, 2020 – Feb 10, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sandbox: fix signed integer overflow

On a 32-bit host system, UBSan reports:

===============================================================

UBSAN: Undefined behaviour in ./arch/sandbox/os/common.c:115:32

signed integer overflow:
83598 * 1000000000 cannot be represented in type 'long int'
===============================================================

Fix this.

---
 arch/sandbox/os/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/os/common.c +1 -1
index 3ad12b4a30cd..3f9cc70770f6 100644
@@ -112,7 +112,7 @@ uint64_t linux_get_time(void)
 
 	clock_gettime(CLOCK_MONOTONIC, &ts);
 
-	now = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
+	now = ts.tv_sec * 1000ULL * 1000 * 1000 + ts.tv_nsec;
 
 	return now;
 }
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/2 sandbox: hostfile: fix UB-inducing shift

On 32-bit hosts, UBSan reports:

====================================================================

UBSAN: Undefined behaviour in ./arch/sandbox/board/hostfile.c:135:12

shift exponent 32 is too large for 32-bit type 'long unsigned int'
====================================================================

Fix this by using a unsigned long long for base. The upper 32-bit won't be set, but device tree fixups can now read them.

---
 arch/sandbox/mach-sandbox/include/mach/hostfile.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/mach-sandbox/include/mach/hostfile.h +1 -1
index 627fe28e765b..54f690be5f7f 100644
@@ -3,7 +3,7 @@
 
 struct hf_info {
 	int fd;
-	unsigned long base;
+	unsigned long long base;
 	size_t size;
 	const char *devname;
 	const char *filename;
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#2 lore raw
In reply to Ahmad Fatoum
Quoted 8 lines · Ahmad Fatoum

On a 32-bit host system, UBSan reports:

===============================================================

UBSAN: Undefined behaviour in ./arch/sandbox/os/common.c:115:32

signed integer overflow:
83598 * 1000000000 cannot be represented in type 'long int'
===============================================================

Quoted 6 lines

Fix this.

---
 arch/sandbox/os/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox