Skip to contentSkip to conversation

io_uring: use timespec64_valid() to verify time value

PATCH In review Ye Bin 2 participants 4 messages Dec 2, 2021 – Dec 16, 2021

Subsystems (2)
lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH 1/1 io_uring: use timespec64_valid() to verify time value

It's better to use timespec64_valid() to verify time value.

Fixes 2087009c74d4("io_uring: validate timespec for timeout removals")
Fixes f6223ff79966("io_uring: Fix undefined-behaviour in io_issue_sqe")
---
 fs/io_uring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/io_uring.c +2 -2
index 568729677e25..929ff732d6dc 100644
@@ -6151,7 +6151,7 @@ static int io_timeout_remove_prep(struct io_kiocb *req,
 			return -EINVAL;
 		if (get_timespec64(&tr->ts, u64_to_user_ptr(sqe->addr2)))
 			return -EFAULT;
-		if (tr->ts.tv_sec < 0 || tr->ts.tv_nsec < 0)
+		if (!timespec64_valid(&tr->ts))
 			return -EINVAL;
 	} else if (tr->flags) {
 		/* timeout removal doesn't support flags */
@@ -6238,7 +6238,7 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 	if (get_timespec64(&data->ts, u64_to_user_ptr(sqe->addr)))
 		return -EFAULT;
 
-	if (data->ts.tv_sec < 0 || data->ts.tv_nsec < 0)
+	if (!timespec64_valid(&data->ts))
 		return -EINVAL;
 
 	data->mode = io_translate_timeout_mode(flags);
Signature · 1 line
2.31.1
author
#1 lore raw
Quoted 23 lines · Ye Bin

It's better to use timespec64_valid() to verify time value.

Fixes 2087009c74d4("io_uring: validate timespec for timeout removals")
Fixes f6223ff79966("io_uring: Fix undefined-behaviour in io_issue_sqe")
---
  fs/io_uring.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/io_uring.c +1 -1
index 568729677e25..929ff732d6dc 100644
@@ -6151,7 +6151,7 @@ static int io_timeout_remove_prep(struct io_kiocb *req,
  			return -EINVAL;
  		if (get_timespec64(&tr->ts, u64_to_user_ptr(sqe->addr2)))
  			return -EFAULT;
-		if (tr->ts.tv_sec < 0 || tr->ts.tv_nsec < 0)
+		if (!timespec64_valid(&tr->ts))
  			return -EINVAL;
  	} else if (tr->flags) {
  		/* timeout removal doesn't support flags */

fs/io_uring.c static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe, · line 6244

Quoted 8 lines
fs/io_uring.c +1 -1
@@ -6238,7 +6238,7 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
  	if (get_timespec64(&data->ts, u64_to_user_ptr(sqe->addr)))
  		return -EFAULT;
 
-	if (data->ts.tv_sec < 0 || data->ts.tv_nsec < 0)
+	if (!timespec64_valid(&data->ts))
  		return -EINVAL;
 
  	data->mode = io_translate_timeout_mode(flags);

ping...

author
#2 lore raw
In reply to Ye Bin

ping...

Quoted 31 lines · Ye Bin

It's better to use timespec64_valid() to verify time value.

Fixes 2087009c74d4("io_uring: validate timespec for timeout removals")
Fixes f6223ff79966("io_uring: Fix undefined-behaviour in io_issue_sqe")
---
  fs/io_uring.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/io_uring.c +2 -2
index 568729677e25..929ff732d6dc 100644
@@ -6151,7 +6151,7 @@ static int io_timeout_remove_prep(struct io_kiocb *req,
  			return -EINVAL;
  		if (get_timespec64(&tr->ts, u64_to_user_ptr(sqe->addr2)))
  			return -EFAULT;
-		if (tr->ts.tv_sec < 0 || tr->ts.tv_nsec < 0)
+		if (!timespec64_valid(&tr->ts))
  			return -EINVAL;
  	} else if (tr->flags) {
  		/* timeout removal doesn't support flags */
@@ -6238,7 +6238,7 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
  	if (get_timespec64(&data->ts, u64_to_user_ptr(sqe->addr)))
  		return -EFAULT;
 
-	if (data->ts.tv_sec < 0 || data->ts.tv_nsec < 0)
+	if (!timespec64_valid(&data->ts))
  		return -EINVAL;
 
  	data->mode = io_translate_timeout_mode(flags);