Skip to contentSkip to conversation

powerpc: Add barrier_nospec to raw_copy_in_user()

PATCH Applied Suraj Jitindar Singh 4 participants 6 messages Mar 6, 2019 – Dec 16, 2019 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Add barrier_nospec to raw_copy_in_user()

Commit ddf35cf3764b ("powerpc: Use barrier_nospec in copy_from_user()") Added barrier_nospec before loading from user-controller pointers. The intention was to order the load from the potentially user-controlled pointer vs a previous branch based on an access_ok() check or similar.

In order to achieve the same result, add a barrier_nospec to the raw_copy_in_user() function before loading from such a user-controlled pointer.

---
 arch/powerpc/include/asm/uaccess.h | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/include/asm/uaccess.h +1 -0
index e3a731793ea2..bb615592d5bb 100644
@@ -306,6 +306,7 @@ extern unsigned long __copy_tofrom_user(void __user *to,
 static inline unsigned long
 raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
 {
+	barrier_nospec();
 	return __copy_tofrom_user(to, from, n);
 }
 #endif /* __powerpc64__ */
Signature · 1 line
2.13.6
#1 lore raw
Quoted 10 lines · Suraj Jitindar Singh

Commit ddf35cf3764b ("powerpc: Use barrier_nospec in copy_from_user()") Added barrier_nospec before loading from user-controller pointers. The intention was to order the load from the potentially user-controlled pointer vs a previous branch based on an access_ok() check or similar.

In order to achieve the same result, add a barrier_nospec to the raw_copy_in_user() function before loading from such a user-controlled pointer.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/6fbcdd59094ade30db63f32316e9502425d7b256

cheers

#2 lore raw
In reply to Suraj Jitindar Singh
Quoted 19 lines · On Wed, 6 Mar 2019 12:10:38 +1100 Suraj Jitindar Singh…

Commit ddf35cf3764b ("powerpc: Use barrier_nospec in copy_from_user()") Added barrier_nospec before loading from user-controller pointers. The intention was to order the load from the potentially user-controlled pointer vs a previous branch based on an access_ok() check or similar.

In order to achieve the same result, add a barrier_nospec to the raw_copy_in_user() function before loading from such a user-controlled pointer.

---
 arch/powerpc/include/asm/uaccess.h | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/include/asm/uaccess.h +0 -0
index e3a731793ea2..bb615592d5bb 100644

arch/powerpc/include/asm/uaccess.h extern unsigned long __copy_tofrom_user(void __user *to, · line 312

Quoted 7 lines
arch/powerpc/include/asm/uaccess.h +1 -0
@@ -306,6 +306,7 @@ extern unsigned long __copy_tofrom_user(void __user *to,
 static inline unsigned long
 raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
 {
+	barrier_nospec();
 	return __copy_tofrom_user(to, from, n);
 }
 #endif /* __powerpc64__ */

Hello,

AFAICT this is not needed. The data cannot be used in the kernel without subsequent copy_from_user which already has the nospec barrier.

Thanks

Michal

#3 lore raw

PATCH 1/1 Revert "powerpc: Add barrier_nospec to raw_copy_in_user()"

This reverts commit 6fbcdd59094ade30db63f32316e9502425d7b256.

Not needed. Data handled by raw_copy_in_user must be loaded through copy_from_user to be used in the kernel which already has the barrier.

---
 arch/powerpc/include/asm/uaccess.h | 1 -
 1 file changed, 1 deletion(-)
arch/powerpc/include/asm/uaccess.h +0 -1
index 8b03eb44e876..76f34346b642 100644
@@ -312,7 +312,6 @@ raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
 {
 	unsigned long ret;
 
-	barrier_nospec();
 	allow_user_access(to, from, n);
 	ret = __copy_tofrom_user(to, from, n);
 	prevent_user_access(to, from, n);
Signature · 1 line
2.22.0
#4 lore raw
In reply to Michal Suchánek
Quoted 32 lines · Michal Suchánek
Quoted 19 lines · On Wed, 6 Mar 2019 12:10:38 +1100 Suraj Jitindar Singh…

Commit ddf35cf3764b ("powerpc: Use barrier_nospec in copy_from_user()") Added barrier_nospec before loading from user-controller pointers. The intention was to order the load from the potentially user-controlled pointer vs a previous branch based on an access_ok() check or similar.

In order to achieve the same result, add a barrier_nospec to the raw_copy_in_user() function before loading from such a user-controlled pointer.

---
 arch/powerpc/include/asm/uaccess.h | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/include/asm/uaccess.h +0 -0
index e3a731793ea2..bb615592d5bb 100644

arch/powerpc/include/asm/uaccess.h extern unsigned long __copy_tofrom_user(void __user *to, · line 312

Quoted 7 lines
arch/powerpc/include/asm/uaccess.h +1 -0
@@ -306,6 +306,7 @@ extern unsigned long __copy_tofrom_user(void __user *to,
 static inline unsigned long
 raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
 {
+	barrier_nospec();
 	return __copy_tofrom_user(to, from, n);
 }
 #endif /* __powerpc64__ */

Hello,

Quoted 2 lines

AFAICT this is not needed. The data cannot be used in the kernel without subsequent copy_from_user which already has the nospec barrier.

Suraj did talk to me about this before sending the patch. My memory is that he came up with a scenario where it was at least theoretically useful, but he didn't mention that in the change log. He was working on nested KVM at the time.

I've now forgotten, and he's moved on to other things so probably won't remember either, if he's even checking his mail :/

cheers

#5 lore raw
Quoted 36 lines · Michael Ellerman
Quoted 32 lines · Michal Suchánek
Quoted 19 lines · On Wed, 6 Mar 2019 12:10:38 +1100 Suraj Jitindar Singh…

Commit ddf35cf3764b ("powerpc: Use barrier_nospec in copy_from_user()") Added barrier_nospec before loading from user-controller pointers. The intention was to order the load from the potentially user-controlled pointer vs a previous branch based on an access_ok() check or similar.

In order to achieve the same result, add a barrier_nospec to the raw_copy_in_user() function before loading from such a user-controlled pointer.

---
 arch/powerpc/include/asm/uaccess.h | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/include/asm/uaccess.h +0 -0
index e3a731793ea2..bb615592d5bb 100644

arch/powerpc/include/asm/uaccess.h extern unsigned long __copy_tofrom_user(void __user *to, · line 312

Quoted 7 lines
arch/powerpc/include/asm/uaccess.h +1 -0
@@ -306,6 +306,7 @@ extern unsigned long __copy_tofrom_user(void __user *to,
 static inline unsigned long
 raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
 {
+	barrier_nospec();
 	return __copy_tofrom_user(to, from, n);
 }
 #endif /* __powerpc64__ */

Hello,

Quoted 2 lines

AFAICT this is not needed. The data cannot be used in the kernel without subsequent copy_from_user which already has the nospec barrier.

Quoted 7 lines

Suraj did talk to me about this before sending the patch. My memory is that he came up with a scenario where it was at least theoretically useful, but he didn't mention that in the change log. He was working on nested KVM at the time.

I've now forgotten, and he's moved on to other things so probably won't remember either, if he's even checking his mail :/

In absence of any argument for the code and absence of the same code on other architectures I would say you were just confused when merging this. The code is confusing after all.

Thanks

Michal