Skip to contentSkip to conversation

arm64: mm: don't write garbage into TTBR1_EL1 register

PATCH Applied Ard Biesheuvel 5 participants 13 messages Feb 23, 2018 – Feb 28, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/proc.S +1 -1
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
 .macro	__idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
 	adrp	\tmp1, empty_zero_page
-	msr	ttbr1_el1, \tmp2
+	msr	ttbr1_el1, \tmp1
 	isb
 	tlbi	vmalle1
 	dsb	nsh
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

hi Ard,

many thanks for your help and the debug session ;-)

Quoted 9 lines · Ard Biesheuvel

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

I have tested this patch on Qualcomm Dragonboard 410c where the issue was found initially.

This patch is also needed on 4.15-stable.

Quoted 20 lines
---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/proc.S +1 -2
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
 .macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
        adrp    \tmp1, empty_zero_page
-       msr     ttbr1_el1, \tmp2
+       msr     ttbr1_el1, \tmp1
        isb
        tlbi    vmalle1
        dsb     nsh
--

2.11.0

maintainer
#2 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

In reply to Ard Biesheuvel
Quoted 6 lines · Ard Biesheuvel

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

Quoted 6 lines
---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Any reason why you didn't cc: the stable list, as this is a patch that is not needed in mainline, right?

arch/arm64/mm/proc.S ENDPROC(cpu_do_switch_mm) · line 158

Quoted 10 lines
arch/arm64/mm/proc.S +1 -1
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
 .macro	__idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
 	adrp	\tmp1, empty_zero_page
-	msr	ttbr1_el1, \tmp2
+	msr	ttbr1_el1, \tmp1

I don't understand why this isn't also needed in Linus's tree. What commit there prevents this from being required?

thanks,

greg k-h

#3 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

Quoted 23 lines · Greg KH
Quoted 6 lines · Ard Biesheuvel

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

Quoted 6 lines
---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Any reason why you didn't cc: the stable list, as this is a patch that is not needed in mainline, right?

Quoted 6 lines
arch/arm64/mm/proc.S +0 -0
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
Quoted 7 lines

arch/arm64/mm/proc.S ENDPROC(cpu_do_switch_mm) · line 158

Quoted 4 lines
arch/arm64/mm/proc.S +1 -1
 .macro       __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
      adrp    \tmp1, empty_zero_page
-     msr     ttbr1_el1, \tmp2
+     msr     ttbr1_el1, \tmp1

I don't understand why this isn't also needed in Linus's tree. What commit there prevents this from being required?

in master this code is

.macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2

    adrp    \tmp1, empty_zero_page
    phys_to_ttbr \tmp2, \tmp1
    msr ttbr1_el1, \tmp2
    isb

which can also explain why the (non trivial) cherry-picked commit ended up wrong.

this change in master came from

529c4b05a3cb arm64: handle 52-bit addresses in TTBR

which afaik, is not needed on stable

Quoted 4 lines

thanks,

greg k-h

#4 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

In reply to Greg KH
Quoted 14 lines · Greg KH
Quoted 6 lines · Ard Biesheuvel

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

Quoted 6 lines
---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines

Any reason why you didn't cc: the stable list, as this is a patch that is not needed in mainline, right?

Indeed, apologies. I added the Cc: tag but it appears not to have been picked up by git send-email.

Also, i suppose it is unclear from the tag that this should be applied to both v4.15 and v4.14

Quoted 6 lines
Quoted 6 lines
arch/arm64/mm/proc.S +0 -0
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
Quoted 8 lines

arch/arm64/mm/proc.S ENDPROC(cpu_do_switch_mm) · line 158

Quoted 4 lines
arch/arm64/mm/proc.S +1 -1
 .macro       __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
      adrp    \tmp1, empty_zero_page
-     msr     ttbr1_el1, \tmp2
+     msr     ttbr1_el1, \tmp1

I don't understand why this isn't also needed in Linus's tree. What commit there prevents this from being required?

Linus's tree has

+.macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2

+     adrp \tmp1, empty_zero_page
+     phys_to_ttbr \tmp1, \tmp2
+     msr ttbr1_el1, \tmp2
+     isb
+     tlbi vmalle1
+     dsb nsh
+     isb

+.endm

but phys_to_ttbr does not exist in the v4.15 and earlier trees (it is related to 52-bit physical address support which landed in v4.16), so it was removed for the backport. However, that means tmp2 is never assigned, and whatever was there is poked into the translation table base register.

But let's wait for team-ARM to ack this in any case.

Thanks,
Ard.

#5 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

Quoted 29 lines · Ard Biesheuvel
Quoted 7 lines · Greg KH
Quoted 6 lines · Ard Biesheuvel
arch/arm64/mm/proc.S +0 -0
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
Quoted 8 lines

arch/arm64/mm/proc.S ENDPROC(cpu_do_switch_mm) · line 158

Quoted 4 lines
arch/arm64/mm/proc.S +1 -1
 .macro       __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
      adrp    \tmp1, empty_zero_page
-     msr     ttbr1_el1, \tmp2
+     msr     ttbr1_el1, \tmp1

I don't understand why this isn't also needed in Linus's tree. What commit there prevents this from being required?

Linus's tree has

+.macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2

(quoted diff) +8 -0
+     adrp \tmp1, empty_zero_page
+     phys_to_ttbr \tmp1, \tmp2
+     msr ttbr1_el1, \tmp2
+     isb
+     tlbi vmalle1
+     dsb nsh
+     isb
+.endm
Quoted 5 lines

but phys_to_ttbr does not exist in the v4.15 and earlier trees (it is related to 52-bit physical address support which landed in v4.16), so it was removed for the backport. However, that means tmp2 is never assigned, and whatever was there is poked into the translation table base register.

Damnit, sorry again. I changed the argument order of phys_to_ttbr along the way, so must've confused myself during the backporting exercise. It's also one of those things that will lead to potential TLB corruption in rare circumstances where the junk in TTBR1 ends up giving a valid translation, so it didn't crop up in my testing. How did Nicolas see this? The bug report I saw didn't look related.

Quoted 1 line

But let's wait for team-ARM to ack this in any case.

Greg -- please can you apply this to the 4.14 and 4.15 stable trees?

Will

#6 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

Quoted 36 lines · Will Deacon
Quoted 29 lines · Ard Biesheuvel
Quoted 7 lines · Greg KH
Quoted 6 lines · Ard Biesheuvel
arch/arm64/mm/proc.S +0 -0
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
Quoted 8 lines

arch/arm64/mm/proc.S ENDPROC(cpu_do_switch_mm) · line 158

Quoted 4 lines
arch/arm64/mm/proc.S +1 -1
 .macro       __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
      adrp    \tmp1, empty_zero_page
-     msr     ttbr1_el1, \tmp2
+     msr     ttbr1_el1, \tmp1

I don't understand why this isn't also needed in Linus's tree. What commit there prevents this from being required?

Linus's tree has

+.macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2

(quoted diff) +8 -0
+     adrp \tmp1, empty_zero_page
+     phys_to_ttbr \tmp1, \tmp2
+     msr ttbr1_el1, \tmp2
+     isb
+     tlbi vmalle1
+     dsb nsh
+     isb
+.endm
Quoted 5 lines

but phys_to_ttbr does not exist in the v4.15 and earlier trees (it is related to 52-bit physical address support which landed in v4.16), so it was removed for the backport. However, that means tmp2 is never assigned, and whatever was there is poked into the translation table base register.

Quoted 7 lines

Damnit, sorry again. I changed the argument order of phys_to_ttbr along the way, so must've confused myself during the backporting exercise. It's also one of those things that will lead to potential TLB corruption in rare circumstances where the junk in TTBR1 ends up giving a valid translation, so it didn't crop up in my testing. How did Nicolas see this? The bug report I saw didn't look related.

This broke the boot on the Dragonboard 410c, but the bisect identified another unrelated commit initially.

Quoted 7 lines
Quoted 1 line

But let's wait for team-ARM to ack this in any case.

Greg -- please can you apply this to the 4.14 and 4.15 stable trees?

Will

#7 lore raw

PATCH 1/1 arm64: mm: don't write garbage into TTBR1_EL1 register

In reply to Will Deacon
Quoted 6 lines · Will Deacon

Damnit, sorry again. I changed the argument order of phys_to_ttbr along the way, so must've confused myself during the backporting exercise. It's also one of those things that will lead to potential TLB corruption in rare circumstances where the junk in TTBR1 ends up giving a valid translation, so it didn't crop up in my testing. How did Nicolas see this? The bug report I saw didn't look related.

FWIW, we've been hitting this bug with a distribution backport on ThunderX2 on every boot. Due to bad luck there was a non-zero value in TTBR1 that crashed the kernel immediately and dropped us to firmware.

--Jan

maintainer Applied
#8 lore raw

Patch "arm64: mm: don't write garbage into TTBR1_EL1 register" has been added to the 4.14-stable tree

In reply to Ard Biesheuvel

This is a note to let you know that I've just added the patch titled

arm64: mm: don't write garbage into TTBR1_EL1 register

to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
arm64-mm-don-t-write-garbage-into-ttbr1_el1-register.patch
and it can be found in the queue-4.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Mon Feb 26 13:53:22 2018

From: Ard Biesheuvel <[email protected]>
Date: Fri, 23 Feb 2018 18:29:02 +0000
Subject: arm64: mm: don't write garbage into TTBR1_EL1 register
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], Ard Biesheuvel <[email protected]>
Message-ID: <[email protected]>

From: Ard Biesheuvel <[email protected]>

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

---
 arch/arm64/mm/proc.S |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/proc.S +1 -1
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
 .macro	__idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
 	adrp	\tmp1, empty_zero_page
-	msr	ttbr1_el1, \tmp2
+	msr	ttbr1_el1, \tmp1
 	isb
 	tlbi	vmalle1
 	dsb	nsh

Patches currently in stable-queue which might be from [email protected] are

queue-4.14/arm64-mm-don-t-write-garbage-into-ttbr1_el1-register.patch

maintainer Applied
#9 lore raw

Patch "arm64: mm: don't write garbage into TTBR1_EL1 register" has been added to the 4.15-stable tree

In reply to Ard Biesheuvel

This is a note to let you know that I've just added the patch titled

arm64: mm: don't write garbage into TTBR1_EL1 register

to the 4.15-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
arm64-mm-don-t-write-garbage-into-ttbr1_el1-register.patch
and it can be found in the queue-4.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Mon Feb 26 13:53:22 2018

From: Ard Biesheuvel <[email protected]>
Date: Fri, 23 Feb 2018 18:29:02 +0000
Subject: arm64: mm: don't write garbage into TTBR1_EL1 register
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], Ard Biesheuvel <[email protected]>
Message-ID: <[email protected]>

From: Ard Biesheuvel <[email protected]>

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

---
 arch/arm64/mm/proc.S |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/proc.S +1 -1
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
 .macro	__idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
 	adrp	\tmp1, empty_zero_page
-	msr	ttbr1_el1, \tmp2
+	msr	ttbr1_el1, \tmp1
 	isb
 	tlbi	vmalle1
 	dsb	nsh

Patches currently in stable-queue which might be from [email protected] are

queue-4.15/arm64-mm-don-t-write-garbage-into-ttbr1_el1-register.patch

maintainer Applied
#10 lore raw

Patch "arm64: mm: don't write garbage into TTBR1_EL1 register" has been added to the 4.4-stable tree

In reply to Ard Biesheuvel

This is a note to let you know that I've just added the patch titled

arm64: mm: don't write garbage into TTBR1_EL1 register

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
arm64-mm-don-t-write-garbage-into-ttbr1_el1-register.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Mon Feb 26 13:53:22 2018

From: Ard Biesheuvel <[email protected]>
Date: Fri, 23 Feb 2018 18:29:02 +0000
Subject: arm64: mm: don't write garbage into TTBR1_EL1 register
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], Ard Biesheuvel <[email protected]>
Message-ID: <[email protected]>

From: Ard Biesheuvel <[email protected]>

Stable backport commit 173358a49173 ("arm64: kpti: Add ->enable callback to remap swapper using nG mappings") of upstream commit f992b4dfd58b did not survive the backporting process unscathed, and ends up writing garbage into the TTBR1_EL1 register, rather than pointing it to the zero page to disable translations. Fix that.

---
 arch/arm64/mm/proc.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/proc.S +1 -1
index 08572f95bd8a..2b473ddeb7a3 100644
@@ -155,7 +155,7 @@ ENDPROC(cpu_do_switch_mm)
 
 .macro	__idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
 	adrp	\tmp1, empty_zero_page
-	msr	ttbr1_el1, \tmp2
+	msr	ttbr1_el1, \tmp1
 	isb
 	tlbi	vmalle1
 	dsb	nsh
Signature · 7 lines
2.11.0



Patches currently in stable-queue which might be from [email protected] are

queue-4.4/arm64-mm-don-t-write-garbage-into-ttbr1_el1-register.patch
#11 lore raw

Re: Patch "arm64: mm: don't write garbage into TTBR1_EL1 register" has been added to the 4.4-stable tree

Quoted 8 lines · On 26 February 2018 at 13:02, <[email protected]> wrote:

This is a note to let you know that I've just added the patch titled

arm64: mm: don't write garbage into TTBR1_EL1 register

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Please drop this. It only applies to v4.14 and v4.15

#12 lore raw

Re: Patch "arm64: mm: don't write garbage into TTBR1_EL1 register" has been added to the 4.4-stable tree

Quoted 11 lines · Ard Biesheuvel
Quoted 8 lines · On 26 February 2018 at 13:02, <[email protected]> wrote:

This is a note to let you know that I've just added the patch titled

arm64: mm: don't write garbage into TTBR1_EL1 register

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Please drop this. It only applies to v4.14 and v4.15

Ugh, my fault, it didn't even apply, but ended up in the wrong directory. Thanks for pointing it out, now dropped.

greg k-h