mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Leizhen (ThunderTown)" <thunder.leizhen@huawei.com>
Cc: Jeff Moyer <jmoyer@redhat.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: Tue, 2 Jan 2018 06:51:55 -0800	[thread overview]
Message-ID: <20180102145155.GD8222@bombadil.infradead.org> (raw)
In-Reply-To: <5A31ED86.5000800@huawei.com>

On Thu, Dec 14, 2017 at 11:18:30AM +0800, Leizhen (ThunderTown) wrote:
> On 2017/12/14 3:31, Matthew Wilcox wrote:
> > On Wed, Dec 13, 2017 at 11:27:00AM -0500, Jeff Moyer wrote:
> >> 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...
> I tried this before. But I found some places call get_timespec64 in the following function.
> If we do the check in get_timespec64, the check will be duplicated.
> 
> For example:
> static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
> ....
> 	if (get_timespec64(&ts, tsp))
> 		return -EFAULT;
> 
> 	to = &end_time;
> 	if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
> 
> int poll_select_set_timeout(struct timespec64 *to, time64_t sec, long nsec)
> {
> 	struct timespec64 ts = {.tv_sec = sec, .tv_nsec = nsec};
> 
> 	if (!timespec64_valid(&ts))
> 		return -EINVAL;

The check is only two comparisons!  Why do we have an interface that can
cause bugs for the sake of saving *two comparisons*?!  Can we talk about
the cost of a cache miss versus the cost of executing these comparisons?

  reply	other threads:[~2018-01-02 14:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 13:42 Zhen Lei
2017-12-13 14:11 ` Matthew Wilcox
2017-12-13 15:58   ` Benjamin LaHaise
2017-12-13 16:27   ` Jeff Moyer
2017-12-13 19:31     ` Matthew Wilcox
2017-12-14  3:18       ` Leizhen (ThunderTown)
2018-01-02 14:51         ` Matthew Wilcox [this message]
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=20180102145155.GD8222@bombadil.infradead.org \
    --to=willy@infradead.org \
    --cc=bcrl@kvack.org \
    --cc=deepa.kernel@gmail.com \
    --cc=dingtianhong@huawei.com \
    --cc=guohanjun@huawei.com \
    --cc=huawei.libin@huawei.com \
    --cc=jmoyer@redhat.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 \
    /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

all inboxes | Powered by JetHome®