mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sunrpc: Fix incorrect parsing of expiry time
@ 2023-03-07 22:05 Jerry Zhang
  2023-03-07 22:30 ` NeilBrown
  0 siblings, 1 reply; 7+ messages in thread
From: Jerry Zhang @ 2023-03-07 22:05 UTC (permalink / raw)
  Cc: embedded, Jerry Zhang, Chuck Lever, Jeff Layton, Trond Myklebust,
	Anna Schumaker, NeilBrown, J. Bruce Fields, linux-nfs,
	linux-kernel

The expiry time field is mean to be expressed in seconds since boot.
The get_expiry() function parses a relative time value in seconds.
In order to get the absolute time of seconds since boot that the given
message will expire, the right thing is to add seconds_since_boot()
to the given relative value.

Previously this logic was subtracting boot.tv_sec from the relative
value, which was causing some confusing behavior. The return type of
time64_t could possibly underflow if time since boot is greater than
the passed in relative argument. Also several checks in nfs code compare
the return value to 0 to indicate failure, and this could spuriously
be tripped if seconds since boot happened to match the argument.

Fixes: c5b29f885afe ("sunrpc: use seconds since boot in expiry cache")
Signed-off-by: Jerry Zhang <Jerry@skydio.com>
---
 include/linux/sunrpc/cache.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index ec5a555df96f..b96b1319c93d 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -301,16 +301,14 @@ static inline int get_time(char **bpp, time64_t *time)
 }
 
 static inline time64_t get_expiry(char **bpp)
 {
 	time64_t rv;
-	struct timespec64 boot;
 
 	if (get_time(bpp, &rv))
 		return 0;
 	if (rv < 0)
 		return 0;
-	getboottime64(&boot);
-	return rv - boot.tv_sec;
+	return rv + seconds_since_boot();
 }
 
 #endif /*  _LINUX_SUNRPC_CACHE_H_ */
-- 
2.37.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-08  1:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 22:05 [PATCH] sunrpc: Fix incorrect parsing of expiry time Jerry Zhang
2023-03-07 22:30 ` NeilBrown
2023-03-07 22:52   ` Jerry Zhang
2023-03-07 23:20     ` NeilBrown
2023-03-07 23:56       ` Jerry Zhang
2023-03-08  0:27         ` NeilBrown
2023-03-08  1:53           ` Jerry Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®