提交 bce69857 编写于 作者: Y Yu Liao 提交者: Yang Yingliang

time: Normalize timespec64 before timespec64_compare()

hulk inclusion
category: bugfix
bugzilla: 185831, https://gitee.com/openeuler/kernel/issues/I4MO2G
CVE: NA

-------------------------------------------------

Passing unnormalized timespec64 to timespec64_compare() may cause
incorrect results.

For example:
  wall_to_monotonic = {tv_sec = -10, tv_nsec = 900000000}
  ts_delta = {tv_sec = -9, tv_nsec = -900000000}

timespec64_compare() returns -1, but actually wall_to_monotonic > ts_delta.
This will cause wall_to_monotonic to become a positive number.

Use timespec64_sub() instead of direct subtraction to avoid this.
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NXiongfeng Wang <wangxiongfeng2@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 c12e68b4
...@@ -62,6 +62,8 @@ static inline int timespec64_equal(const struct timespec64 *a, ...@@ -62,6 +62,8 @@ static inline int timespec64_equal(const struct timespec64 *a,
* lhs < rhs: return <0 * lhs < rhs: return <0
* lhs == rhs: return 0 * lhs == rhs: return 0
* lhs > rhs: return >0 * lhs > rhs: return >0
*
* Note: Both lhs and rhs must be normalized.
*/ */
static inline int timespec64_compare(const struct timespec64 *lhs, const struct timespec64 *rhs) static inline int timespec64_compare(const struct timespec64 *lhs, const struct timespec64 *rhs)
{ {
......
...@@ -1236,8 +1236,7 @@ int do_settimeofday64(const struct timespec64 *ts) ...@@ -1236,8 +1236,7 @@ int do_settimeofday64(const struct timespec64 *ts)
timekeeping_forward_now(tk); timekeeping_forward_now(tk);
xt = tk_xtime(tk); xt = tk_xtime(tk);
ts_delta.tv_sec = ts->tv_sec - xt.tv_sec; ts_delta = timespec64_sub(*ts, xt);
ts_delta.tv_nsec = ts->tv_nsec - xt.tv_nsec;
if (timespec64_compare(&tk->wall_to_monotonic, &ts_delta) > 0) { if (timespec64_compare(&tk->wall_to_monotonic, &ts_delta) > 0) {
ret = -EINVAL; ret = -EINVAL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册