diff mbox

[1/1] aio: make sure the input "timeout" value is valid

Message ID 1513172572-16724-1-git-send-email-thunder.leizhen@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Leizhen (ThunderTown) Dec. 13, 2017, 1:42 p.m. UTC
Below information is reported by a lower kernel version, and I saw the
problem still exist in current version.

UBSAN: Undefined behaviour in include/linux/ktime.h:55:34
signed integer overflow:
-4971973988617027584 * 1000000000 cannot be represented in type 'long int'
......
[<ffff80000072ca28>] timespec_to_ktime include/linux/ktime.h:55 [inline]
[<ffff80000072ca28>] read_events+0x4c8/0x5d0 fs/aio.c:1269
[<ffff8000007305bc>] SYSC_io_getevents fs/aio.c:1733 [inline]
[<ffff8000007305bc>] SyS_io_getevents+0xd4/0x218 fs/aio.c:1722

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 fs/aio.c | 5 +++++
 1 file changed, 5 insertions(+)

--
1.8.3
diff mbox

Patch

diff --git a/fs/aio.c b/fs/aio.c
index a062d75..19f7661 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1858,6 +1858,9 @@  static long do_io_getevents(aio_context_t ctx_id,
 	if (timeout) {
 		if (unlikely(get_timespec64(&ts, timeout)))
 			return -EFAULT;
+
+		if (!timespec64_valid(&ts))
+			return -EINVAL;
 	}

 	return do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
@@ -1876,6 +1879,8 @@  static long do_io_getevents(aio_context_t ctx_id,
 		if (compat_get_timespec64(&t, timeout))
 			return -EFAULT;

+		if (!timespec64_valid(&t))
+			return -EINVAL;
 	}

 	return do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);