From 773b57b676526975059e5ba3858cfde6d8b50ceb Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 16 Aug 2014 21:04:41 +0200 Subject: [PATCH] kernel: fix todfix() race we have to recheck the condition under tod lock, otherwise another process can come in and updated tod.last and tod.off and once we have the lock, we would make time jump backwards. --- sys/src/9/port/tod.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/src/9/port/tod.c b/sys/src/9/port/tod.c index 424e0f290..b88f721af 100644 --- a/sys/src/9/port/tod.c +++ b/sys/src/9/port/tod.c @@ -198,11 +198,13 @@ todfix(void) uvlong x; ticks = fastticks(nil); + diff = ticks - tod.last; + if(diff <= tod.hz) + return; + ilock(&tod); diff = ticks - tod.last; if(diff > tod.hz){ - ilock(&tod); - /* convert to epoch */ mul64fract(&x, diff, tod.multiplier); if(x > 30000000000ULL) iprint("todfix %llud\n", x); @@ -211,9 +213,8 @@ if(x > 30000000000ULL) iprint("todfix %llud\n", x); /* protect against overflows */ tod.last = ticks; tod.off = x; - - iunlock(&tod); } + iunlock(&tod); } long