Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4008666imb; Wed, 6 Mar 2019 03:04:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzJMdQsHfWeOMUBJL+ASrF51WKmLQb3HL0qxyJFlc/uHP150/XhBpjDOQ+QrGelhx443Y0f X-Received: by 2002:a17:902:9a4a:: with SMTP id x10mr6125966plv.93.1551870266358; Wed, 06 Mar 2019 03:04:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551870266; cv=none; d=google.com; s=arc-20160816; b=bo3XJn+R8CAj2AJoEWttQ2xB6pyWyXKAAILIH4/i+26WgX1NDF2Eaqech+HGbC75MP AAD8yQaaUhB2ELUxKC6Gq0B0KZnE5GYcq1lk9lEHVCdM7lojJuyjXRSIlhwERl0i7R3Q YMRetf0sd7PVqhOD+NxpIQnT2CrbGr+oqkw32ZHR0VZNGsthvZrmQkd3ofZle0WT9GpZ nkJ4FduSbjuXLv3wwUqHhLS16frSIGOINOdAiKFxm+VRTa1477ZdDnmxR1A/RQjozexB KwixTP2yJrw1hrwblyEA/hLskSJH7+FXdsMmv43OuK+0XkG6bJIeuXwE2Hsi7qUNBNHt dYIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=pUrCDRD/9PIzAevEBpK3JuQ3TP9oFQTeCXXUVuOSoDU=; b=M4TXBU2XxZ0c5fxn0j+tJtQORCG84peQUtYxumEG8qxPDhsjWVqqM7hbX2Qw+/pXGK r4zhIKRTfvcBLKG+PMNiWfm+j8Q6CIYnUM473eploa6VkTo4EojM89HAWdCTc0U6mAa/ tOalD/ywMWuZYuoyKK0dsKBI93PkbH0cw0ovkfHhuOx+MnUF0e3R9sQLAkwBwUfnvAxL bPbZo7qIieFxnvw4xg7DmQgObGhQ2iijDQpntiUMejuXWiNpo9CzMP4KY0IU12jaGHIt DXBfqc33Gd9F0m9hcDRwWjaFo7ciRF2GZ8cy6vaG5wWtbcM5szHS7Jwsnvs2shuR6iM+ 19ZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h62si1164440pge.410.2019.03.06.03.04.08; Wed, 06 Mar 2019 03:04:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729740AbfCFJ2q (ORCPT + 99 others); Wed, 6 Mar 2019 04:28:46 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:4775 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729078AbfCFJ2q (ORCPT ); Wed, 6 Mar 2019 04:28:46 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 12A411A769AA38A3EF59; Wed, 6 Mar 2019 17:28:44 +0800 (CST) Received: from [127.0.0.1] (10.177.21.79) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Wed, 6 Mar 2019 17:28:36 +0800 Subject: Re: [PATCH v2] aio: add check for timeout to aviod invalid value To: , References: <1551089387-27557-1-git-send-email-tanxiaojun@huawei.com> CC: , , , , From: Tan Xiaojun Message-ID: <5C7F92C3.1030307@huawei.com> Date: Wed, 6 Mar 2019 17:28:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1551089387-27557-1-git-send-email-tanxiaojun@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.21.79] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Any comments? Anything is fine to me. Thanks. Xiaojun. On 2019/2/25 18:09, Tan Xiaojun wrote: > Syzkaller reported a UBSAN bug below, which was mainly caused by a large > negative number passed to the timeout of the io_getevents system call. > > ====================================================================== > UBSAN: Undefined behaviour in ./include/linux/ktime.h:42:14 > signed integer overflow: > -8427032702788048137 * 1000000000 cannot be represented in type 'long long int' > CPU: 3 PID: 11668 Comm: syz-executor0 Not tainted 4.19.18-514.55.6.9.x86_64+ #1 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 > Call Trace: > __dump_stack lib/dump_stack.c:77 [inline] > dump_stack+0xca/0x13e lib/dump_stack.c:113 > ubsan_epilogue+0xe/0x81 lib/ubsan.c:159 > handle_overflow+0x193/0x1e2 lib/ubsan.c:190 > ktime_set include/linux/ktime.h:42 [inline] > timespec64_to_ktime include/linux/ktime.h:78 [inline] > do_io_getevents+0x307/0x390 fs/aio.c:2043 > __do_sys_io_getevents fs/aio.c:2080 [inline] > __se_sys_io_getevents fs/aio.c:2068 [inline] > __x64_sys_io_getevents+0x163/0x250 fs/aio.c:2068 > do_syscall_64+0xc8/0x580 arch/x86/entry/common.c:290 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > RIP: 0033:0x462589 > Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48 > RSP: 002b:00007fde9b04ec58 EFLAGS: 00000246 ORIG_RAX: 00000000000000d0 > RAX: ffffffffffffffda RBX: 000000000072bf00 RCX: 0000000000462589 > RDX: 0000000000000006 RSI: 0000000000000000 RDI: 0000000000000000 > RBP: 0000000000000005 R08: 0000000020000100 R09: 0000000000000000 > R10: 0000000020000040 R11: 0000000000000246 R12: 00007fde9b04f6bc > R13: 00000000004bd1f0 R14: 00000000006f6b60 R15: 00000000ffffffff > ====================================================================== > bond0 (unregistering): Released all slaves > > The timeout described in "man io_getevents" does not say whether it > can be negative or not, but as a waiting time, a negative number has > no meaning. So I add check to avoid this case. > > This issue was previously discussed at: > https://lore.kernel.org/lkml/CACT4Y+bBxVYLQ6LtOKrKtnLthqLHcw-BMp3aqP3mjdAvr9FULQ@mail.gmail.com/ > > Signed-off-by: Tan Xiaojun > Reviewed-by: Jeff Moyer > --- > fs/aio.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/fs/aio.c b/fs/aio.c > index aaaaf4d..3a39673 100644 > --- a/fs/aio.c > +++ b/fs/aio.c > @@ -2078,10 +2078,16 @@ 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; > + struct kioctx *ioctx; > long ret = -EINVAL; > > + if (ts && !timespec64_valid(ts)) > + return -EINVAL; > + > + until = ts ? timespec64_to_ktime(*ts) : KTIME_MAX; > + 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);