From: Jeff Moyer <jmoyer@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Benjamin LaHaise <bcrl@kvack.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
linux-aio <linux-aio@kvack.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Tianhong Ding <dingtianhong@huawei.com>,
Hanjun Guo <guohanjun@huawei.com>,
Libin <huawei.libin@huawei.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Deepa Dinamani <deepa.kernel@gmail.com>
Subject: Re: [PATCH 1/1] aio: make sure the input "timeout" value is valid
Date: Wed, 13 Dec 2017 11:27:00 -0500 [thread overview]
Message-ID: <x49y3m6a90r.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <20171213141112.GA11217@bombadil.infradead.org> (Matthew Wilcox's message of "Wed, 13 Dec 2017 06:11:12 -0800")
Matthew Wilcox <willy@infradead.org> writes:
> On Wed, Dec 13, 2017 at 09:42:52PM +0800, Zhen Lei wrote:
>> Below information is reported by a lower kernel version, and I saw the
>> problem still exist in current version.
>
> I think you're right, but what an awful interface we have here!
> The user must not only fetch it, they must validate it separately?
> And if they forget, then userspace is provoking undefined behaviour? Ugh.
> Why not this:
Why not go a step further and have get_timespec64 check for validity?
I wonder what caller doesn't want that to happen...
-Jeff
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 4adbdcbe753a..fdd16cf897c8 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -1788,8 +1788,9 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
> struct timespec64 ts;
>
> if (timeout) {
> - if (unlikely(get_timespec64(&ts, timeout)))
> - return -EFAULT;
> + int error = get_valid_timespec64(&ts, timeout);
> + if (error)
> + return error;
> }
>
> return do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
> @@ -1805,9 +1806,9 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,
> struct timespec64 t;
>
> if (timeout) {
> - if (compat_get_timespec64(&t, timeout))
> - return -EFAULT;
> -
> + int error = compat_get_valid_timespec64(&t, timeout);
> + if (error)
> + return error;
> }
>
> return do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
> diff --git a/include/linux/compat.h b/include/linux/compat.h
> index 0fc36406f32c..578fc0f208d9 100644
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -172,6 +172,26 @@ extern int get_compat_itimerspec64(struct itimerspec64 *its,
> extern int put_compat_itimerspec64(const struct itimerspec64 *its,
> struct compat_itimerspec __user *uits);
>
> +static inline __must_check
> +int compat_get_valid_timespec64(struct timespec64 *ts, const void __user *uts)
> +{
> + if (unlikely(compat_get_timespec64(ts, uts)))
> + return -EFAULT;
> + if (unlikely(!timespec64_valid(ts)))
> + return -EINVAL;
> + return 0;
> +}
> +
> +static inline __must_check
> +int compat_get_strict_timespec64(struct timespec64 *ts, const void __user *uts)
> +{
> + if (unlikely(compat_get_timespec64(ts, uts)))
> + return -EFAULT;
> + if (unlikely(!timespec64_valid_strict(ts)))
> + return -EINVAL;
> + return 0;
> +}
> +
> struct compat_iovec {
> compat_uptr_t iov_base;
> compat_size_t iov_len;
> diff --git a/include/linux/time.h b/include/linux/time.h
> index 4b62a2c0a661..506d87483d04 100644
> --- a/include/linux/time.h
> +++ b/include/linux/time.h
> @@ -18,6 +18,26 @@ int get_itimerspec64(struct itimerspec64 *it,
> int put_itimerspec64(const struct itimerspec64 *it,
> struct itimerspec __user *uit);
>
> +static inline __must_check int get_valid_timespec64(struct timespec64 *ts,
> + const struct timespec __user *uts)
> +{
> + if (unlikely(get_timespec64(ts, uts)))
> + return -EFAULT;
> + if (unlikely(!timespec64_valid(ts)))
> + return -EINVAL;
> + return 0;
> +}
> +
> +static inline __must_check int get_strict_timespec64(struct timespec64 *ts,
> + const struct timespec __user *uts)
> +{
> + if (unlikely(get_timespec64(ts, uts)))
> + return -EFAULT;
> + if (unlikely(!timespec64_valid_strict(ts)))
> + return -EINVAL;
> + return 0;
> +}
> +
> extern time64_t mktime64(const unsigned int year, const unsigned int mon,
> const unsigned int day, const unsigned int hour,
> const unsigned int min, const unsigned int sec);
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-aio' in
> the body to majordomo@kvack.org. For more info on Linux AIO,
> see: http://www.kvack.org/aio/
> Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>
next prev parent reply other threads:[~2017-12-13 16:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-13 13:42 [PATCH 1/1] aio: make sure the input "timeout" value is valid Zhen Lei
2017-12-13 14:11 ` Matthew Wilcox
2017-12-13 15:58 ` Benjamin LaHaise
2017-12-13 16:27 ` Jeff Moyer [this message]
2017-12-13 19:31 ` Matthew Wilcox
2017-12-14 3:18 ` Leizhen (ThunderTown)
2018-01-02 14:51 ` Matthew Wilcox
2018-01-12 19:49 ` Jeff Moyer
2018-03-26 20:01 ` Arnd Bergmann
2018-03-26 21:55 ` Matthew Wilcox
2018-03-27 4:43 ` Deepa Dinamani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=x49y3m6a90r.fsf@segfault.boston.devel.redhat.com \
--to=jmoyer@redhat.com \
--cc=bcrl@kvack.org \
--cc=deepa.kernel@gmail.com \
--cc=dingtianhong@huawei.com \
--cc=guohanjun@huawei.com \
--cc=huawei.libin@huawei.com \
--cc=linux-aio@kvack.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thunder.leizhen@huawei.com \
--cc=viro@zeniv.linux.org.uk \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).