Skip to content

Commit 5fbc09e

Browse files
chleroymaddy-kerneldev
authored andcommitted
powerpc/uaccess: Move barrier_nospec() out of allow_read_{from/write}_user()
Commit 74e19ef ("uaccess: Add speculation barrier to copy_from_user()") added a redundant barrier_nospec() in copy_from_user(), because powerpc is already calling barrier_nospec() in allow_read_from_user() and allow_read_write_user(). But on other architectures that call to barrier_nospec() was missing. So change powerpc instead of reverting the above commit and having to fix other architectures one by one. This is now possible because barrier_nospec() has also been added in copy_from_user_iter(). Move barrier_nospec() out of allow_read_from_user() and allow_read_write_user(). This will also allow reuse of those functions when implementing masked user access which doesn't require barrier_nospec(). Don't add it back in raw_copy_from_user() as it is already called by copy_from_user() and copy_from_user_iter(). Fixes: 74e19ef ("uaccess: Add speculation barrier to copy_from_user()") Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/f29612105c5fcbc8ceb7303808ddc1a781f0f6b5.1766574657.git.chleroy@kernel.org
1 parent 9ace475 commit 5fbc09e

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

arch/powerpc/include/asm/kup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ static __always_inline void kuap_assert_locked(void)
134134

135135
static __always_inline void allow_read_from_user(const void __user *from, unsigned long size)
136136
{
137-
barrier_nospec();
138137
allow_user_access(NULL, from, size, KUAP_READ);
139138
}
140139

@@ -146,7 +145,6 @@ static __always_inline void allow_write_to_user(void __user *to, unsigned long s
146145
static __always_inline void allow_read_write_user(void __user *to, const void __user *from,
147146
unsigned long size)
148147
{
149-
barrier_nospec();
150148
allow_user_access(to, from, size, KUAP_READ_WRITE);
151149
}
152150

arch/powerpc/include/asm/uaccess.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ do { \
301301
__typeof__(sizeof(*(ptr))) __gu_size = sizeof(*(ptr)); \
302302
\
303303
might_fault(); \
304+
barrier_nospec(); \
304305
allow_read_from_user(__gu_addr, __gu_size); \
305306
__get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err); \
306307
prevent_read_from_user(__gu_addr, __gu_size); \
@@ -329,6 +330,7 @@ raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
329330
{
330331
unsigned long ret;
331332

333+
barrier_nospec();
332334
allow_read_write_user(to, from, n);
333335
ret = __copy_tofrom_user(to, from, n);
334336
prevent_read_write_user(to, from, n);
@@ -415,6 +417,7 @@ static __must_check __always_inline bool user_access_begin(const void __user *pt
415417

416418
might_fault();
417419

420+
barrier_nospec();
418421
allow_read_write_user((void __user *)ptr, ptr, len);
419422
return true;
420423
}
@@ -431,6 +434,7 @@ user_read_access_begin(const void __user *ptr, size_t len)
431434

432435
might_fault();
433436

437+
barrier_nospec();
434438
allow_read_from_user(ptr, len);
435439
return true;
436440
}

0 commit comments

Comments
 (0)