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: <20240830015459.2937-1-chenyufan@vivo.com>
Date: Fri, 30 Aug 2024 09:54:59 +0800
From: Chen Yufan <chenyufan@...o.com>
To: John Stultz <jstultz@...gle.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Stephen Boyd <sboyd@...nel.org>,
	linux-kernel@...r.kernel.org
Cc: opensource.kernel@...o.com,
	Chen Yufan <chenyufan@...o.com>
Subject: [PATCH v3] timekeeping: Use time_after() in timekeeping_check_update()

Use time_after because the open coded comparison 
does not handle wrap arounds correctly.

Signed-off-by: Chen Yufan <chenyufan@...o.com>
---
The modifications made compared to the previous version are as follows:
1. change the type of timekeeper::last_warning to
unsigned long because time_after() requires its
parameters to be unsigned long.
---
 include/linux/timekeeper_internal.h | 2 +-
 kernel/time/timekeeping.c           | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index 84ff2844df2a..928a9258b7dd 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -125,7 +125,7 @@ struct timekeeper {
 	/* Flag used to avoid updating NTP twice with same second */
 	u32			skip_second_overflow;
 #ifdef CONFIG_DEBUG_TIMEKEEPING
-	long			last_warning;
+	unsigned long			last_warning;
 	/*
 	 * These simple flag variables are managed
 	 * without locks, which is racy, but they are
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 5391e4167d60..6cda65dbe18f 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -217,7 +217,7 @@ static void timekeeping_check_update(struct timekeeper *tk, u64 offset)
 	}
 
 	if (tk->underflow_seen) {
-		if (jiffies - tk->last_warning > WARNING_FREQ) {
+		if (time_after(jiffies, tk->last_warning + WARNING_FREQ)) {
 			printk_deferred("WARNING: Underflow in clocksource '%s' observed, time update ignored.\n", name);
 			printk_deferred("         Please report this, consider using a different clocksource, if possible.\n");
 			printk_deferred("         Your kernel is probably still fine.\n");
@@ -227,7 +227,7 @@ static void timekeeping_check_update(struct timekeeper *tk, u64 offset)
 	}
 
 	if (tk->overflow_seen) {
-		if (jiffies - tk->last_warning > WARNING_FREQ) {
+		if (time_after(jiffies, tk->last_warning + WARNING_FREQ)) {
 			printk_deferred("WARNING: Overflow in clocksource '%s' observed, time update capped.\n", name);
 			printk_deferred("         Please report this, consider using a different clocksource, if possible.\n");
 			printk_deferred("         Your kernel is probably still fine.\n");
-- 
2.39.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ