From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincenzo Frascino Subject: Re: [PATCH 5/5] arm64: compat: Reduce address limit Date: Mon, 1 Apr 2019 10:13:48 +0100 Message-ID: <682cdfd5-200c-4e1e-2863-605e44f3e5e8@arm.com> References: <20190319151542.19557-1-vincenzo.frascino@arm.com> <20190319151542.19557-6-vincenzo.frascino@arm.com> <20190329155937.GA48010@arrakis.emea.arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20190329155937.GA48010@arrakis.emea.arm.com> Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Catalin Marinas Cc: linux-arch@vger.kernel.org, Mark Rutland , Will Deacon , linux-arm-kernel@lists.infradead.org, Jann Horn List-Id: linux-arch.vger.kernel.org On 29/03/2019 15:59, Catalin Marinas wrote: > On Tue, Mar 19, 2019 at 03:15:42PM +0000, Vincenzo Frascino wrote: >> Currently, compat tasks running on arm64 can allocate memory up to >> TASK_SIZE_32 (UL(0x100000000)). >> >> This means that mmap() allocations, if we treat them as returning an >> array, are not compliant with the sections 6.5.8 of the C standard >> (C99) which states that: "If the expression P points to an element of >> an array object and the expression Q points to the last element of the >> same array object, the pointer expression Q+1 compares greater than P". >> >> Redefine TASK_SIZE_32 to address the issue. >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: Jann Horn >> Reported-by: Jann Horn >> Signed-off-by: Vincenzo Frascino >> --- >> arch/arm64/include/asm/processor.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h >> index 07c873fce961..4c689740940d 100644 >> --- a/arch/arm64/include/asm/processor.h >> +++ b/arch/arm64/include/asm/processor.h >> @@ -57,7 +57,7 @@ >> #define TASK_SIZE_64 (UL(1) << vabits_user) >> >> #ifdef CONFIG_COMPAT >> -#define TASK_SIZE_32 UL(0x100000000) >> +#define TASK_SIZE_32 (UL(0x100000000) - PAGE_SIZE) >> #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ >> TASK_SIZE_32 : TASK_SIZE_64) >> #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ > > So what I meant with the previous comment, can we have this: > > #ifndef CONFIG_ARM64_64K_PAGES > #define TASK_SIZE_32 (UK(0x100000000) - PAGE_SIZE) > #endif > > and still have a vectors page with 64K configuration? Assuming that it > is not unmapped, an mmap() wouldn't return the 0xffff0000 page to break > the C99 requirements. There is the case of user unmapping the vectors > page (which seems to be allowed based on my reading of the code) and > then getting an mmap() at the end for the 32-bit address range but I > really don't think we should cover for this case. > The current set is designed to cover all the cases, but I am fine either way. > Another option which I think would cover the unmap case as well in all > configurations is to handle the limit in arch_get_mmap_end(). We already > define this to handle mmap limitation on 52-bit user VA but you can make > it handle compat tasks (and probably turn it into a static inline > function). > I like this approach more than what I proposed in the current series, but I think this is not easily back-portable to stable. > The other patches for splitting the vectors page in two are still valid > (to be on par with arm32) but they would not be required for this fix. > Ok, to summarize, this is what I am going to do next: - Send a patch that includes your comments about CONFIG_ARM64_64K_PAGES. - Send a separate series for kuser helpers leaving them enabled by default in all the cases. - Create a new series based on arch_get_mmap_end(). -- Regards, Vincenzo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:58930 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbfDAJNv (ORCPT ); Mon, 1 Apr 2019 05:13:51 -0400 Subject: Re: [PATCH 5/5] arm64: compat: Reduce address limit References: <20190319151542.19557-1-vincenzo.frascino@arm.com> <20190319151542.19557-6-vincenzo.frascino@arm.com> <20190329155937.GA48010@arrakis.emea.arm.com> From: Vincenzo Frascino Message-ID: <682cdfd5-200c-4e1e-2863-605e44f3e5e8@arm.com> Date: Mon, 1 Apr 2019 10:13:48 +0100 MIME-Version: 1.0 In-Reply-To: <20190329155937.GA48010@arrakis.emea.arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Catalin Marinas Cc: linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Will Deacon , Jann Horn , Mark Rutland Message-ID: <20190401091348.oh1MHK2sP09veJEcFTY4Af69oE1IRV0HD5FgrlF3dQE@z> On 29/03/2019 15:59, Catalin Marinas wrote: > On Tue, Mar 19, 2019 at 03:15:42PM +0000, Vincenzo Frascino wrote: >> Currently, compat tasks running on arm64 can allocate memory up to >> TASK_SIZE_32 (UL(0x100000000)). >> >> This means that mmap() allocations, if we treat them as returning an >> array, are not compliant with the sections 6.5.8 of the C standard >> (C99) which states that: "If the expression P points to an element of >> an array object and the expression Q points to the last element of the >> same array object, the pointer expression Q+1 compares greater than P". >> >> Redefine TASK_SIZE_32 to address the issue. >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: Jann Horn >> Reported-by: Jann Horn >> Signed-off-by: Vincenzo Frascino >> --- >> arch/arm64/include/asm/processor.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h >> index 07c873fce961..4c689740940d 100644 >> --- a/arch/arm64/include/asm/processor.h >> +++ b/arch/arm64/include/asm/processor.h >> @@ -57,7 +57,7 @@ >> #define TASK_SIZE_64 (UL(1) << vabits_user) >> >> #ifdef CONFIG_COMPAT >> -#define TASK_SIZE_32 UL(0x100000000) >> +#define TASK_SIZE_32 (UL(0x100000000) - PAGE_SIZE) >> #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ >> TASK_SIZE_32 : TASK_SIZE_64) >> #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ > > So what I meant with the previous comment, can we have this: > > #ifndef CONFIG_ARM64_64K_PAGES > #define TASK_SIZE_32 (UK(0x100000000) - PAGE_SIZE) > #endif > > and still have a vectors page with 64K configuration? Assuming that it > is not unmapped, an mmap() wouldn't return the 0xffff0000 page to break > the C99 requirements. There is the case of user unmapping the vectors > page (which seems to be allowed based on my reading of the code) and > then getting an mmap() at the end for the 32-bit address range but I > really don't think we should cover for this case. > The current set is designed to cover all the cases, but I am fine either way. > Another option which I think would cover the unmap case as well in all > configurations is to handle the limit in arch_get_mmap_end(). We already > define this to handle mmap limitation on 52-bit user VA but you can make > it handle compat tasks (and probably turn it into a static inline > function). > I like this approach more than what I proposed in the current series, but I think this is not easily back-portable to stable. > The other patches for splitting the vectors page in two are still valid > (to be on par with arm32) but they would not be required for this fix. > Ok, to summarize, this is what I am going to do next: - Send a patch that includes your comments about CONFIG_ARM64_64K_PAGES. - Send a separate series for kuser helpers leaving them enabled by default in all the cases. - Create a new series based on arch_get_mmap_end(). -- Regards, Vincenzo