Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1703297 > unrolled thread
| Started by | Nick Desaulniers <ndesaulniers@google.com> |
|---|---|
| First post | 2017-08-03 19:20 +0200 |
| Last post | 2017-08-03 20:10 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET Nick Desaulniers <ndesaulniers@google.com> - 2017-08-03 19:20 +0200
Re: [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-08-03 19:30 +0200
Re: [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET Nick Desaulniers <ndesaulniers@google.com> - 2017-08-03 20:00 +0200
[PATCH v2] arm64: avoid overflow in VA_START and PAGE_OFFSET Nick Desaulniers <ndesaulniers@google.com> - 2017-08-03 20:10 +0200
| From | Nick Desaulniers <ndesaulniers@google.com> |
|---|---|
| Date | 2017-08-03 19:20 +0200 |
| Subject | [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET |
| Message-ID | <uarWX-37e-41@gated-at.bofh.it> |
The bitmask used to define these values produces overflow, as seen by
this compiler warning:
arch/arm64/kernel/head.S:47:8: warning:
integer overflow in preprocessor expression
#elif (PAGE_OFFSET & 0x1fffff) != 0
^~~~~~~~~~~
arch/arm64/include/asm/memory.h:52:46: note:
expanded from macro 'PAGE_OFFSET'
#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS -
1))
~~~~~~~~~~~~~~~~~~ ^
It would be preferrable to use GENMASK_ULL() instead, but it's not set
up to be used from assembly (the UL() macro token pastes UL suffixes
when not included in assembly sources).
Suggested-by: Yury Norov <ynorov@caviumnetworks.com>
Suggested-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
arch/arm64/include/asm/memory.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 32f82723338a..dde717a31dee 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -64,8 +64,9 @@
* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
*/
#define VA_BITS (CONFIG_ARM64_VA_BITS)
-#define VA_START (UL(0xffffffffffffffff) << VA_BITS)
-#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - 1))
+#define VA_START ((UL(0xffffffffffffffff) >> VA_BITS) << VA_BITS)
+#define PAGE_OFFSET ((UL(0xffffffffffffffff) >> (VA_BITS - 1)) \
+ << (VA_BITS - 1))
#define KIMAGE_VADDR (MODULES_END)
#define MODULES_END (MODULES_VADDR + MODULES_VSIZE)
#define MODULES_VADDR (VA_START + KASAN_SHADOW_SIZE)
--
2.14.0.rc1.383.gd1ce394fe2-goog
[toc] | [next] | [standalone]
| From | Ard Biesheuvel <ard.biesheuvel@linaro.org> |
|---|---|
| Date | 2017-08-03 19:30 +0200 |
| Message-ID | <uas6C-3bf-35@gated-at.bofh.it> |
| In reply to | #1703297 |
On 3 August 2017 at 18:11, Nick Desaulniers <ndesaulniers@google.com> wrote: > The bitmask used to define these values produces overflow, as seen by > this compiler warning: > > arch/arm64/kernel/head.S:47:8: warning: > integer overflow in preprocessor expression > #elif (PAGE_OFFSET & 0x1fffff) != 0 > ^~~~~~~~~~~ > arch/arm64/include/asm/memory.h:52:46: note: > expanded from macro 'PAGE_OFFSET' > #define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - > 1)) > ~~~~~~~~~~~~~~~~~~ ^ > > It would be preferrable to use GENMASK_ULL() instead, but it's not set > up to be used from assembly (the UL() macro token pastes UL suffixes > when not included in assembly sources). > > Suggested-by: Yury Norov <ynorov@caviumnetworks.com> > Suggested-by: Matthias Kaehlcke <mka@chromium.org> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> > --- > arch/arm64/include/asm/memory.h | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 32f82723338a..dde717a31dee 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -64,8 +64,9 @@ > * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. > */ > #define VA_BITS (CONFIG_ARM64_VA_BITS) > -#define VA_START (UL(0xffffffffffffffff) << VA_BITS) > -#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - 1)) > +#define VA_START ((UL(0xffffffffffffffff) >> VA_BITS) << VA_BITS) > +#define PAGE_OFFSET ((UL(0xffffffffffffffff) >> (VA_BITS - 1)) \ > + << (VA_BITS - 1)) > #define KIMAGE_VADDR (MODULES_END) > #define MODULES_END (MODULES_VADDR + MODULES_VSIZE) > #define MODULES_VADDR (VA_START + KASAN_SHADOW_SIZE) > -- > 2.14.0.rc1.383.gd1ce394fe2-goog > Would #define VA_START (UL(0xffffffffffffffff) - (1 << VA_BITS) + 1) also work?
[toc] | [prev] | [next] | [standalone]
| From | Nick Desaulniers <ndesaulniers@google.com> |
|---|---|
| Date | 2017-08-03 20:00 +0200 |
| Message-ID | <uaszE-3m4-19@gated-at.bofh.it> |
| In reply to | #1703303 |
> Would > > #define VA_START (UL(0xffffffffffffffff) - (1 << VA_BITS) + 1) > > also work? I think you'd have to wrap the 1 in a UL(), ex: #define VA_START (UL(0xffffffffffffffff) - (UL(1) << VA_BITS) + 1) Otherwise IIUC a integral literal (`1`) is treated as an int, which on arm64 is LP64 making it 32b, where most configs set VA_BITS to larger than 32b. Shifting by more than the width is undefined behavior. And without it, I get compile errors. I'll send v2 with your suggestion, thanks. -- Thanks, ~Nick Desaulniers
[toc] | [prev] | [next] | [standalone]
| From | Nick Desaulniers <ndesaulniers@google.com> |
|---|---|
| Date | 2017-08-03 20:10 +0200 |
| Subject | [PATCH v2] arm64: avoid overflow in VA_START and PAGE_OFFSET |
| Message-ID | <uasJj-3EH-7@gated-at.bofh.it> |
| In reply to | #1703316 |
The bitmask used to define these values produces overflow, as seen by
this compiler warning:
arch/arm64/kernel/head.S:47:8: warning:
integer overflow in preprocessor expression
#elif (PAGE_OFFSET & 0x1fffff) != 0
^~~~~~~~~~~
arch/arm64/include/asm/memory.h:52:46: note:
expanded from macro 'PAGE_OFFSET'
#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS -
1))
~~~~~~~~~~~~~~~~~~ ^
It would be preferrable to use GENMASK_ULL() instead, but it's not set
up to be used from assembly (the UL() macro token pastes UL suffixes
when not included in assembly sources).
Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Suggested-by: Yury Norov <ynorov@caviumnetworks.com>
Suggested-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
arch/arm64/include/asm/memory.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 32f82723338a..ef39dcb9ca6a 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -64,8 +64,10 @@
* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
*/
#define VA_BITS (CONFIG_ARM64_VA_BITS)
-#define VA_START (UL(0xffffffffffffffff) << VA_BITS)
-#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - 1))
+#define VA_START (UL(0xffffffffffffffff) - \
+ (UL(1) << VA_BITS) + 1)
+#define PAGE_OFFSET (UL(0xffffffffffffffff) - \
+ (UL(1) << (VA_BITS - 1)) + 1)
#define KIMAGE_VADDR (MODULES_END)
#define MODULES_END (MODULES_VADDR + MODULES_VSIZE)
#define MODULES_VADDR (VA_START + KASAN_SHADOW_SIZE)
--
2.14.0.rc1.383.gd1ce394fe2-goog
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web