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-prev] [day] [month] [year] [list]
Date:	Sat, 12 Jul 2008 14:14:34 +0100
From:	Gerrit Renker <gerrit@....abdn.ac.uk>
To:	David Howells <dhowells@...hat.com>
Cc:	akpm@...ux-foundation.org, acme@...stprotocols.net,
	netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Fix dccp_timestamp()'s use of do_div()

Quoting David Howells:
| Fix dccp_timestamps()'s use of do_div() on an s64 by making delta a u64
| instead and dividing that.
| 
| Possibly this should be guarded lest the interval calculation turn up negative,
| but the possible negativity of the result of the division ignored anyway, and,
| indeed, should not happen.
| 
| This was introduced by patch 4c70f383e0c0273c4092c4efdb414be0966978b7.
| 
| Signed-off-by: David Howells <dhowells@...hat.com>
| ---
| 
|  net/dccp/timer.c |    4 +++-
|  1 files changed, 3 insertions(+), 1 deletions(-)
| 
| 
| diff --git a/net/dccp/timer.c b/net/dccp/timer.c
| index 8703a79..27218c5 100644
| --- a/net/dccp/timer.c
| +++ b/net/dccp/timer.c
| @@ -300,8 +300,10 @@ static ktime_t dccp_timestamp_seed;
|   */
|  u32 dccp_timestamp(void)
|  {
| -	s64 delta = ktime_us_delta(ktime_get_real(), dccp_timestamp_seed);
| +	u64 delta = ktime_us_delta(ktime_get_real(), dccp_timestamp_seed);
|  
| +	/* This will produce huge values if the current time should happen to
| +	 * be earlier than the initial timestamp, but that shouldn't happen */
|  	do_div(delta, 10);
|  	return delta;
|  }
| 
I agree that the use of do_div() is problematic but I don't this is a
good solution. It would be better to use div_u64() with the same effect
as shown below (taken from a patch soon to be submitted).

--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -74,6 +74,9 @@ extern void dccp_time_wait(struct sock *
 #define DCCP_TIMEWAIT_LEN (60 * HZ) /* how long to wait to destroy TIME-WAIT
 				     * state, about 60 seconds */
 
+/* DCCP base time resolution - 10 microseconds (RFC 4340, 13.1 ... 13.3) */
+#define DCCP_TIME_RESOLUTION	10
+
 /* RFC 1122, 4.2.3.1 initial RTO value */
 #define DCCP_TIMEOUT_INIT ((unsigned)(3 * HZ))
 
--- a/net/dccp/timer.c
+++ b/net/dccp/timer.c
@@ -281,8 +281,7 @@ u32 dccp_timestamp(void)
 {
 	s64 delta = ktime_us_delta(ktime_get_real(), dccp_timestamp_seed);
 
-	do_div(delta, 10);
-	return delta;
+	return div_u64(delta, DCCP_TIME_RESOLUTION);
 }
 EXPORT_SYMBOL_GPL(dccp_timestamp);
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ