From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752848AbcAGPbe (ORCPT ); Thu, 7 Jan 2016 10:31:34 -0500 Received: from kanga.kvack.org ([205.233.56.17]:32770 "EHLO kanga.kvack.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750756AbcAGPbd (ORCPT ); Thu, 7 Jan 2016 10:31:33 -0500 Date: Thu, 7 Jan 2016 10:31:32 -0500 From: Benjamin LaHaise To: Dmitry Vyukov Cc: Jan Kara , Alexander Viro , linux-aio , "linux-fsdevel@vger.kernel.org" , LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin , Andrey Ryabinin Subject: Re: int overflow in io_getevents Message-ID: <20160107153132.GL4439@kvack.org> References: <20151216125618.GA16918@quack.suse.cz> <20160106180158.GE4439@kvack.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 07, 2016 at 10:12:02AM +0100, Dmitry Vyukov wrote: ... > Sorry, but the following program still prints -9223372036562067969. I > think timespec_valid check will do. Ah, right. Yes, using timespec_valid() instead of timespec_valid_strict() as initially proposed will address my concerns. Updated commit below. -ben -- "Thought is the essence of where you are now." commit 3a55c535cf3836257434518bd6bc11464c493492 Author: Benjamin LaHaise Date: Thu Jan 7 10:25:44 2016 -0500 aio: handle integer overflow in io_getevents() timespec usage Dmitry Vyukov reported an integer overflow in io_getevents() when running a fuzzer. Upon investigation, the triggers appears to be that an invalid value for the tv_sec or tv_nsec was passed in which is not handled by timespec_to_ktime(). This patch fixes that by making io_getevents() return -EINVAL when timespec_valid() checks fail. We use timespec_valid() instead of timespec_valid_strict() to avoid issues caused by userspace not knowing the cutoff for KTIME_SEC_MAX. Reported-by: Dmitry Vyukov Signed-off-by: Benjamin LaHaise diff --git a/fs/aio.c b/fs/aio.c index 155f842..d161a2f 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1269,6 +1269,8 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr, if (unlikely(copy_from_user(&ts, timeout, sizeof(ts)))) return -EFAULT; + if (!timespec_valid()) + return -EINVAL; until = timespec_to_ktime(ts); }