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>] [day] [month] [year] [list]
Date:   Wed, 4 Dec 2019 00:25:58 -0500
From:   George Spelvin <lkml@....org>
To:     linux-kernel@...r.kernel.org, lkml@....org
Cc:     Akinobu Mita <akinobu.mita@...il.com>,
        Anton Blanchard <anton@...ba.org>
Subject: [RFC PATCH v1 02/50] lib/fault-inject.c: Fix off-by-one error in probability

This is the combination of two fixes.  First, use prandom_u32_max() for
efficiency:
-	if (attr->probability <= prandom_u32() % 100)
+	if (attr->probability <= prandom_u32_max(100))
 		return false

And then a bug-fix:
-	if (attr->probability <= prandom_u32_max(100))
+	if (attr->probability < prandom_u32_max(100))
 		return false

Before, probability = 1 would succeed 2% of the time and 99 would
succeed 100% of the time.  (0% was caught by an earlier test.)

Signed-off-by: George Spelvin <lkml@....org>
Cc: Akinobu Mita <akinobu.mita@...il.com>
Cc: Anton Blanchard <anton@...ba.org>
---
 lib/fault-inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 8186ca84910bc..e20151fa5515e 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -134,7 +134,7 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 			return false;
 	}
 
-	if (attr->probability <= prandom_u32() % 100)
+	if (attr->probability < prandom_u32_max(100))
 		return false;
 
 	if (!fail_stacktrace(attr))
-- 
2.26.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ