Skip to contentSkip to conversation

aio: add timeout validity check for io_[p]getevents

PATCH In review zhangyi (F) 2 participants 3 messages Jul 30, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 aio: add timeout validity check for io_[p]getevents

io_[p]getevents syscall should return -EINVAL if timeout is out of range, add this validity check.

Cc Jeff Moyer <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Deepa Dinamani <[email protected]>

---
Changes since v1:
- add Reviewed-by and Cc tags.

 fs/aio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/aio.c +9 -2
index 01e0fb9..dd967a0 100644
@@ -2031,10 +2031,17 @@ static long do_io_getevents(aio_context_t ctx_id,
 		struct io_event __user *events,
 		struct timespec64 *ts)
 {
-	ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
-	struct kioctx *ioctx = lookup_ioctx(ctx_id);
+	ktime_t until = KTIME_MAX;
+	struct kioctx *ioctx = NULL;
 	long ret = -EINVAL;
 
+	if (ts) {
+		if (!timespec64_valid(ts))
+			return ret;
+		until = timespec64_to_ktime(*ts);
+	}
+
+	ioctx = lookup_ioctx(ctx_id);
 	if (likely(ioctx)) {
 		if (likely(min_nr <= nr && min_nr >= 0))
 			ret = read_events(ioctx, min_nr, nr, events, until);
Signature · 1 line
2.7.4
#1 lore raw

fs/aio.c static long do_io_getevents(aio_context_t ctx_id, · line 2042

Quoted 12 lines · zhangyi (F)

{

fs/aio.c +7 -2
-       ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
-       struct kioctx *ioctx = lookup_ioctx(ctx_id);
+       ktime_t until = KTIME_MAX;
+       struct kioctx *ioctx = NULL;
        long ret = -EINVAL;
 
+       if (ts) {
+               if (!timespec64_valid(ts))
+                       return ret;
+               until = timespec64_to_ktime(*ts);
+       }

The man page should probably get updated as well to reflect that this will now return -EINVAL for a negative timeout or malformed nanoseconds.

Arnd

#2 lore raw

On 2019/7/30 15:11, Arnd Bergmann Wrote:

Quoted 15 lines · zhangyi (F)

fs/aio.c static long do_io_getevents(aio_context_t ctx_id, · line 2042

Quoted 13 lines

{

fs/aio.c +7 -2
-       ktime_t until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX;
-       struct kioctx *ioctx = lookup_ioctx(ctx_id);
+       ktime_t until = KTIME_MAX;
+       struct kioctx *ioctx = NULL;
        long ret = -EINVAL;
 
+       if (ts) {
+               if (!timespec64_valid(ts))
+                       return ret;
+               until = timespec64_to_ktime(*ts);
+       }
Quoted 4 lines

The man page should probably get updated as well to reflect that this will now return -EINVAL for a negative timeout or malformed nanoseconds.

Thanks for your suggestion, I will add a patch to update the man page.

Thanks,
Yi.