From 26ce518d4605db37083404615268b2341340ecb4 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sun, 29 Apr 2018 14:34:33 +0200 Subject: [PATCH 1/5] Avoid out of bounds reads from blas_quick_divide_table on big systems Should fix #1541 --- common_x86_64.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common_x86_64.h b/common_x86_64.h index bee88d3ce..0542653a1 100644 --- a/common_x86_64.h +++ b/common_x86_64.h @@ -195,7 +195,9 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){ unsigned int result; if (y <= 1) return x; - + + if (y > 64) return x/y; + y = blas_quick_divide_table[y]; __asm__ __volatile__ ("mull %0" :"=d" (result) :"a"(x), "0" (y)); From 8145ecd70bdfae44f62b5ff9a9e0ee427a2db3db Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sun, 29 Apr 2018 14:38:55 +0200 Subject: [PATCH 2/5] Avoid out-of-bounds reads from blas_quick_divide_table on big systems --- common_x86.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common_x86.h b/common_x86.h index 4363fb2f4..de014064e 100644 --- a/common_x86.h +++ b/common_x86.h @@ -179,6 +179,10 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){ return result; #else + if ( y > 64) { + result = x/y; + return result; + } y = blas_quick_divide_table[y]; __asm__ __volatile__ ("mull %0" :"=d" (result) :"a"(x), "0" (y)); From c1eb06e102f4598efee7f766bf0142653f8c8f73 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sun, 29 Apr 2018 14:40:12 +0200 Subject: [PATCH 3/5] Update common_x86_64.h --- common_x86_64.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common_x86_64.h b/common_x86_64.h index 0542653a1..a145abc14 100644 --- a/common_x86_64.h +++ b/common_x86_64.h @@ -196,7 +196,10 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){ if (y <= 1) return x; - if (y > 64) return x/y; + if (y > 64) { + result = x / y; + return result; + } y = blas_quick_divide_table[y]; From e93355e5e1fe1b00a7a9587118c5d3b58ce94922 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 2 May 2018 14:43:08 +0200 Subject: [PATCH 4/5] Omit the table overflow check when building for small systems --- common_x86.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common_x86.h b/common_x86.h index de014064e..75b1e1247 100644 --- a/common_x86.h +++ b/common_x86.h @@ -178,11 +178,13 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){ result = x/y; return result; #else - +#if (MAX_CPU_NUMBER > 64) if ( y > 64) { result = x/y; return result; - } + } +#endif + y = blas_quick_divide_table[y]; __asm__ __volatile__ ("mull %0" :"=d" (result) :"a"(x), "0" (y)); From d0c0506588281b34717a3e7b17e9cc2c4a5cef8d Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 2 May 2018 14:44:50 +0200 Subject: [PATCH 5/5] Omit the divide table overflow check on small systems --- common_x86_64.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common_x86_64.h b/common_x86_64.h index a145abc14..9d0ef4e75 100644 --- a/common_x86_64.h +++ b/common_x86_64.h @@ -195,11 +195,13 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){ unsigned int result; if (y <= 1) return x; - + +#if (MAX_CPU_NUMBER > 64) if (y > 64) { result = x / y; return result; } +#endif y = blas_quick_divide_table[y];