From patchwork Sat Aug 5 04:12:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9882891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77AA26020A for ; Sat, 5 Aug 2017 04:15:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65ED7288D9 for ; Sat, 5 Aug 2017 04:15:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59848288DB; Sat, 5 Aug 2017 04:15:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE79C288DD for ; Sat, 5 Aug 2017 04:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751381AbdHEENk (ORCPT ); Sat, 5 Aug 2017 00:13:40 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34932 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751072AbdHEENi (ORCPT ); Sat, 5 Aug 2017 00:13:38 -0400 Received: by mail-pf0-f194.google.com with SMTP id j68so3522498pfc.2; Fri, 04 Aug 2017 21:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VfoKU3T/JAB4UWKw4c8z8p9ul7FNB+StKqwtX90tuO0=; b=cQSfH3TQzkMocfRgxIok+Cot+CxrIAqJIt+O/N4GsUfYs6w8B1jA4pvBuCCjALDyik LlyqYXbg0BrkVoJiLI+XGZTmQNXZI/mcrhcwNyzT1j2U030zQfGl3RLRaJfAiwqJfWkC BDnD6a3NCYxO1JoKwjD6yhfz4UTlZkzjOrT2J8hnHwbjGVnH/Y42riug3Cqj1mT9qJKe fB8fAG6vEuzoFy7+p0STgVancn6TsVkI6m1LBnoNWaOTowLxw7+ZGCyixOiDZcQNAPKY b3IXL928uFUWpm5kc7CGKROmwCQdsoKJrliLwFzvwjPrATK/hGJiYv+4veSESqsDcE5q apmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VfoKU3T/JAB4UWKw4c8z8p9ul7FNB+StKqwtX90tuO0=; b=OWY17EsG4N2d/0QDDzESOGlvRHGaKdf/N1P77D0ritfOuuETVe78hi9O/U1byWbJhi hgygCgYt/fOriKbaCgVrS+SMElufpuX4dtnCq4FFS7yiEqP3hxI5MA8iOdwZn6c28Txj 689GFL+0cu1lYWa/B1IZZTAYO7Xk+xDIV3YaSkuAA6SeHARaDJFzWUAiO7kBiR/OpYJ7 wRoc9tolr9ollHHuj/m9d16m40UDYl0+G2kMzcySM9UcttH08BI6QY7/LeQWOI+tjLcL bABHRRRAmhNNUmk78bbIBTkVyF8JFAATFzqTLxD/fpVz9MlNIN5AVdYOJce3yf7/rDD/ jWeA== X-Gm-Message-State: AIVw111uAvkfeIYrH1Y8ekzy5iVO8IY/H9S4HHp0AOlSh6tIQw+pDGzO /6uxx7ToaOfPhw== X-Received: by 10.98.73.217 with SMTP id r86mr4698654pfi.265.1501906417698; Fri, 04 Aug 2017 21:13:37 -0700 (PDT) Received: from localhost.localdomain ([2601:647:5000:6620:9f3:1737:a046:9b69]) by smtp.gmail.com with ESMTPSA id z6sm4908495pge.20.2017.08.04.21.13.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Aug 2017 21:13:37 -0700 (PDT) From: Deepa Dinamani To: viro@zeniv.linux.org.uk Cc: tglx@linutronix.de, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org, linux-aio@kvack.org Subject: [PATCH 2/2] io_getevents: Use timespec64 to represent timeouts Date: Fri, 4 Aug 2017 21:12:32 -0700 Message-Id: <20170805041232.20875-3-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170805041232.20875-1-deepa.kernel@gmail.com> References: <20170805041232.20875-1-deepa.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP struct timespec is not y2038 safe. Use y2038 safe struct timespec64 to represent timeouts. The system call interface itself will be changed as part of different series. Timeouts will not really need more than 32 bits. But, replacing these with timespec64 helps verification of a y2038 safe kernel by getting rid of timespec internally. Signed-off-by: Deepa Dinamani Cc: linux-aio@kvack.org Reviewed-by: Arnd Bergmann --- fs/aio.c | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 8f0127526299..7ca6b7a00368 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1289,20 +1289,10 @@ static bool aio_read_events(struct kioctx *ctx, long min_nr, long nr, static long read_events(struct kioctx *ctx, long min_nr, long nr, struct io_event __user *event, - struct timespec __user *timeout) + ktime_t until) { - ktime_t until = KTIME_MAX; long ret = 0; - if (timeout) { - struct timespec ts; - - if (unlikely(copy_from_user(&ts, timeout, sizeof(ts)))) - return -EFAULT; - - until = timespec_to_ktime(ts); - } - /* * Note that aio_read_events() is being called as the conditional - i.e. * we're calling it after prepare_to_wait() has set task state to @@ -1824,6 +1814,25 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb, return ret; } +static long do_io_getevents(aio_context_t ctx_id, + long min_nr, + long nr, + 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); + long ret = -EINVAL; + + if (likely(ioctx)) { + if (likely(min_nr <= nr && min_nr >= 0)) + ret = read_events(ioctx, min_nr, nr, events, until); + percpu_ref_put(&ioctx->users); + } + + return ret; +} + /* io_getevents: * Attempts to read at least min_nr events and up to nr events from * the completion queue for the aio_context specified by ctx_id. If @@ -1842,15 +1851,14 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id, struct io_event __user *, events, struct timespec __user *, timeout) { - struct kioctx *ioctx = lookup_ioctx(ctx_id); - long ret = -EINVAL; + struct timespec64 ts; - if (likely(ioctx)) { - if (likely(min_nr <= nr && min_nr >= 0)) - ret = read_events(ioctx, min_nr, nr, events, timeout); - percpu_ref_put(&ioctx->users); + if (timeout) { + if (unlikely(get_timespec64(&ts, timeout))) + return -EFAULT; } - return ret; + + return do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL); } #ifdef CONFIG_COMPAT @@ -1860,17 +1868,14 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id, struct io_event __user *, events, struct compat_timespec __user *, timeout) { - struct timespec t; - struct timespec __user *ut = NULL; + struct timespec64 t; if (timeout) { - if (compat_get_timespec(&t, timeout)) + if (compat_get_timespec64(&t, timeout)) return -EFAULT; - ut = compat_alloc_user_space(sizeof(*ut)); - if (copy_to_user(ut, &t, sizeof(t))) - return -EFAULT; } - return sys_io_getevents(ctx_id, min_nr, nr, events, ut); + + return do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL); } #endif