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 A1A39C3DA7A for ; Wed, 28 Dec 2022 22:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231936AbiL1WRK (ORCPT ); Wed, 28 Dec 2022 17:17:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232799AbiL1WRF (ORCPT ); Wed, 28 Dec 2022 17:17:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E3013D16 for ; Wed, 28 Dec 2022 14:17:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1CCD061640 for ; Wed, 28 Dec 2022 22:17:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB142C433EF; Wed, 28 Dec 2022 22:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1672265823; bh=TIUBssIqTL0wXOJJ79ujlgOXLd564sfw9ogVxe9yqhE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uJHEgKDZT6Vvn8sswHYsfVvULQSaTlrCcGRC7Wd+0Ov3vn7PIGC5+LjgUuJTZu1m+ UhtG0l6Q/qSYwueLsAtvIZdUPEEYNfZWed51W9Rqp+b5Vtb9kuG6sB8jPkBCAsDQo6 Q7NrsMvuR3FfT1yoQecwdmN5j8PBrSW1NJRctXaM= Date: Wed, 28 Dec 2022 14:17:01 -0800 From: Andrew Morton To: Wupeng Ma Cc: , , , , Subject: Re: [PATCH 1/4] mm/mlock: return EINVAL for illegal user memory range in mlock Message-Id: <20221228141701.c64add46c4b09aa17f605baf@linux-foundation.org> In-Reply-To: <20221205034108.3365182-2-mawupeng1@huawei.com> References: <20221205034108.3365182-1-mawupeng1@huawei.com> <20221205034108.3365182-2-mawupeng1@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 5 Dec 2022 11:41:05 +0800 Wupeng Ma wrote: > 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))); > > The same problem happens in munlock. > > 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. What happens if userspace uses a value somewhat smaller than ULONG_MAX? mlock(addr, ULONG_MAX - 1000000); ? Because if the above works successfully and if it no longer works successfully with this patchset then that could be a backward-compatibility problem.