Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752375AbdLNDSz (ORCPT ); Wed, 13 Dec 2017 22:18:55 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2284 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752016AbdLNDSv (ORCPT ); Wed, 13 Dec 2017 22:18:51 -0500 Subject: Re: [PATCH 1/1] aio: make sure the input "timeout" value is valid To: Matthew Wilcox , Jeff Moyer References: <1513172572-16724-1-git-send-email-thunder.leizhen@huawei.com> <20171213141112.GA11217@bombadil.infradead.org> <20171213193100.GA19700@bombadil.infradead.org> CC: Alexander Viro , Benjamin LaHaise , linux-fsdevel , linux-aio , linux-kernel , "Tianhong Ding" , Hanjun Guo , Libin , Kefeng Wang , "Deepa Dinamani" From: "Leizhen (ThunderTown)" Message-ID: <5A31ED86.5000800@huawei.com> Date: Thu, 14 Dec 2017 11:18:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20171213193100.GA19700@bombadil.infradead.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1663 Lines: 50 On 2017/12/14 3:31, Matthew Wilcox wrote: > On Wed, Dec 13, 2017 at 11:27:00AM -0500, Jeff Moyer wrote: >> Matthew Wilcox 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; > > There are some which don't today. I'm hoping Deepa takes this and goes > off and fixes them all up. As my search results, just the case I mentioned above, which may cause duplicate check. So if we don't care the slightly performance drop, maybe we should do timespec64_valid check in get_timespec64. I can try this in v2. Otherwise, use your method. > > . > -- Thanks! BestRegards