From: Catalin Marinas <catalin.marinas@arm.com>
To: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: linux-arch@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
Will Deacon <will.deacon@arm.com>,
linux-arm-kernel@lists.infradead.org,
Jann Horn <jannh@google.com>
Subject: Re: [PATCH 5/5] arm64: compat: Reduce address limit
Date: Fri, 29 Mar 2019 15:59:37 +0000 [thread overview]
Message-ID: <20190329155937.GA48010@arrakis.emea.arm.com> (raw)
In-Reply-To: <20190319151542.19557-6-vincenzo.frascino@arm.com>
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 <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Jann Horn <jannh@google.com>
> Reported-by: Jann Horn <jannh@google.com>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> ---
> 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.
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).
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.
--
Catalin
WARNING: multiple messages have this Message-ID (diff)
From: Catalin Marinas <catalin.marinas@arm.com>
To: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Will Deacon <will.deacon@arm.com>, Jann Horn <jannh@google.com>,
Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH 5/5] arm64: compat: Reduce address limit
Date: Fri, 29 Mar 2019 15:59:37 +0000 [thread overview]
Message-ID: <20190329155937.GA48010@arrakis.emea.arm.com> (raw)
Message-ID: <20190329155937.lxfclHCFJLK6160Ds8UvGapzx6Mcs1oddpzZG_50hNI@z> (raw)
In-Reply-To: <20190319151542.19557-6-vincenzo.frascino@arm.com>
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 <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Jann Horn <jannh@google.com>
> Reported-by: Jann Horn <jannh@google.com>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> ---
> 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.
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).
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.
--
Catalin
next prev parent reply other threads:[~2019-03-29 15:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 15:15 [PATCH 0/5] arm64: compat: Reduce address limit Vincenzo Frascino
2019-03-19 15:15 ` Vincenzo Frascino
2019-03-19 15:15 ` [PATCH 1/5] arm64: compat: Alloc separate pages for vectors and sigpage Vincenzo Frascino
2019-03-19 15:15 ` Vincenzo Frascino
2019-03-29 12:12 ` Catalin Marinas
2019-03-29 12:12 ` Catalin Marinas
2019-04-01 9:00 ` Vincenzo Frascino
2019-04-01 9:00 ` Vincenzo Frascino
2019-03-19 15:15 ` [PATCH 2/5] arm64: compat: Split kuser32 Vincenzo Frascino
2019-03-19 15:15 ` Vincenzo Frascino
2019-03-19 15:15 ` [PATCH 3/5] arm64: compat: Refactor aarch32_alloc_vdso_pages() Vincenzo Frascino
2019-03-19 15:15 ` Vincenzo Frascino
2019-03-19 15:15 ` [PATCH 4/5] arm64: compat: Add KUSER_HELPERS config option Vincenzo Frascino
2019-03-19 15:15 ` Vincenzo Frascino
2019-03-29 12:22 ` Catalin Marinas
2019-03-29 12:22 ` Catalin Marinas
2019-03-19 15:15 ` [PATCH 5/5] arm64: compat: Reduce address limit Vincenzo Frascino
2019-03-19 15:15 ` Vincenzo Frascino
2019-03-29 15:59 ` Catalin Marinas [this message]
2019-03-29 15:59 ` Catalin Marinas
2019-04-01 9:13 ` Vincenzo Frascino
2019-04-01 9:13 ` Vincenzo Frascino
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=20190329155937.GA48010@arrakis.emea.arm.com \
--to=catalin.marinas@arm.com \
--cc=jannh@google.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=vincenzo.frascino@arm.com \
--cc=will.deacon@arm.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