lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1508822823-31231-1-git-send-email-ayush.m@samsung.com>
Date:   Tue, 24 Oct 2017 10:57:03 +0530
From:   Ayush Mittal <ayush.m@...sung.com>
To:     aryabinin@...tuozzo.com, dhowells@...hat.com,
        james.l.morris@...cle.com, linux-kernel@...r.kernel.org
Cc:     v.narang@...sung.com, a.sahrawat@...sung.com, pankaj.m@...sung.com,
        Ayush Mittal <ayush.m@...sung.com>
Subject: [PATCH 1/1] mpi: check for shift exponent greater than 31.

This patch check for shift exponent greater than 31,
detected by UBSAN.

1)UBSAN: Undefined behaviour in lib/mpi/generic_mpih-lshift.c:57:22
 shift exponent 32 is too large for 32-bit type 'long unsigned int'

2)UBSAN: Undefined behaviour in lib/mpi/generic_mpih-lshift.c:60:20
shift exponent 32 is too large for 32-bit type 'long unsigned int'

3)UBSAN: Undefined behaviour in lib/mpi/generic_mpih-rshift.c:57:21
shift exponent 32 is too large for 32-bit type 'long unsigned int'

4) UBSAN: Undefined behaviour in lib/mpi/generic_mpih-rshift.c:60:19
shift exponent 32 is too large for 32-bit type 'long unsigned int'

So instead of undefined behaviour defining behaviour when shift exponent 
is greater than 31 then value will be Zero .

Signed-off-by: Ayush Mittal <ayush.m@...sung.com>
Signed-off-by: Vaneet Narang <v.narang@...sung.com>
---
 lib/mpi/generic_mpih-lshift.c | 6 +++---
 lib/mpi/generic_mpih-rshift.c | 6 +++---
 lib/mpi/mpi-internal.h        | 3 +++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/mpi/generic_mpih-lshift.c b/lib/mpi/generic_mpih-lshift.c
index 8631892..1c8277e 100644
--- a/lib/mpi/generic_mpih-lshift.c
+++ b/lib/mpi/generic_mpih-lshift.c
@@ -50,14 +50,14 @@
 	sh_2 = BITS_PER_MPI_LIMB - sh_1;
 	i = usize - 1;
 	low_limb = up[i];
-	retval = low_limb >> sh_2;
+	retval = MPI_RSHIFT(low_limb, sh_2);
 	high_limb = low_limb;
 	while (--i >= 0) {
 		low_limb = up[i];
-		wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
+		wp[i] = MPI_LSHIFT(high_limb, sh_1) | MPI_RSHIFT(low_limb, sh_2);
 		high_limb = low_limb;
 	}
-	wp[i] = high_limb << sh_1;
+	wp[i] = MPI_LSHIFT(high_limb, sh_1);
 
 	return retval;
 }
diff --git a/lib/mpi/generic_mpih-rshift.c b/lib/mpi/generic_mpih-rshift.c
index ffa3288..3a28bdd 100644
--- a/lib/mpi/generic_mpih-rshift.c
+++ b/lib/mpi/generic_mpih-rshift.c
@@ -50,14 +50,14 @@
 	wp -= 1;
 	sh_2 = BITS_PER_MPI_LIMB - sh_1;
 	high_limb = up[0];
-	retval = high_limb << sh_2;
+	retval = MPI_LSHIFT(high_limb, sh_2);
 	low_limb = high_limb;
 	for (i = 1; i < usize; i++) {
 		high_limb = up[i];
-		wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
+		wp[i] = MPI_RSHIFT(low_limb, sh_1) | MPI_LSHIFT(high_limb, sh_2);
 		low_limb = high_limb;
 	}
-	wp[i] = low_limb >> sh_1;
+	wp[i] = MPI_RSHIFT(low_limb, sh_1);
 
 	return retval;
 }
diff --git a/lib/mpi/mpi-internal.h b/lib/mpi/mpi-internal.h
index 7eceedd..9c94a98 100644
--- a/lib/mpi/mpi-internal.h
+++ b/lib/mpi/mpi-internal.h
@@ -37,6 +37,9 @@
 #include <linux/mpi.h>
 #include <linux/errno.h>
 
+#define MPI_LSHIFT(val, shift) (shift >= BITS_PER_MPI_LIMB ? 0 : (val << shift))
+#define MPI_RSHIFT(val, shift) (shift >= BITS_PER_MPI_LIMB ? 0 : (val >> shift))
+
 #define log_debug printk
 #define log_bug printk
 
-- 
1.9.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ