From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4A9CC4708E for ; Wed, 4 Jan 2023 09:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234546AbjADJci (ORCPT ); Wed, 4 Jan 2023 04:32:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbjADJce (ORCPT ); Wed, 4 Jan 2023 04:32:34 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A3D81AC for ; Wed, 4 Jan 2023 01:32:32 -0800 (PST) Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Nn48z159LzRqpS; Wed, 4 Jan 2023 17:30:59 +0800 (CST) Received: from [10.174.178.120] (10.174.178.120) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 4 Jan 2023 17:32:30 +0800 Message-ID: Date: Wed, 4 Jan 2023 17:32:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 From: mawupeng Subject: Re: [PATCH 0/4] return EINVAL for illegal user memory range To: , CC: , , , , References: <20221205034108.3365182-1-mawupeng1@huawei.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.120] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/1/2 21:22, David Hildenbrand wrote: > On 05.12.22 04:41, Wupeng Ma wrote: >> From: Ma Wupeng >> >> While testing mlock, we have a problem if the len of mlock is ULONG_MAX. >> The return value of mlock is zero. But nothing will be locked since the >> len in do_mlock overflows to zero due to the following code in mlock: >> >>    len = PAGE_ALIGN(len + (offset_in_page(start))); >> >> However this problem appear in multiple syscalls. >> >> Since TASK_SIZE is the maximum user space address. The start or len of >> mlock shouldn't be bigger than this. Function access_ok can be used to >> check this issue, so return -EINVAL if bigger. > > I assume this makes sure that what we document holds: > > EINVAL (mlock(),  mlock2(),  and  munlock()) The result of the addition >     addr+len was less than addr (e.g., the addition may have >     resulted in an overflow). > > So instead of adding access_ok() checks, wouldn't be the right think to do checking for overflows? I agree with you. Do checking only for overflows do seems nice since we need to keep backward-compatibility. > >