Skip to content
/ linux Public

Commit ee31055

Browse files
chleroySasha Levin
authored andcommitted
powerpc/uaccess: Move barrier_nospec() out of allow_read_{from/write}_user()
[ Upstream commit 5fbc09e ] 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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a862ce5 commit ee31055

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

arch/powerpc/include/asm/kup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ static __always_inline void restore_user_access(unsigned long flags)
163163

164164
static __always_inline void allow_read_from_user(const void __user *from, unsigned long size)
165165
{
166-
barrier_nospec();
167166
allow_user_access(NULL, from, size, KUAP_READ);
168167
}
169168

@@ -175,7 +174,6 @@ static __always_inline void allow_write_to_user(void __user *to, unsigned long s
175174
static __always_inline void allow_read_write_user(void __user *to, const void __user *from,
176175
unsigned long size)
177176
{
178-
barrier_nospec();
179177
allow_user_access(to, from, size, KUAP_READ_WRITE);
180178
}
181179

arch/powerpc/include/asm/uaccess.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ do { \
285285
__typeof__(sizeof(*(ptr))) __gu_size = sizeof(*(ptr)); \
286286
\
287287
might_fault(); \
288+
barrier_nospec(); \
288289
allow_read_from_user(__gu_addr, __gu_size); \
289290
__get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err); \
290291
prevent_read_from_user(__gu_addr, __gu_size); \
@@ -313,6 +314,7 @@ raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
313314
{
314315
unsigned long ret;
315316

317+
barrier_nospec();
316318
allow_read_write_user(to, from, n);
317319
ret = __copy_tofrom_user(to, from, n);
318320
prevent_read_write_user(to, from, n);
@@ -401,6 +403,7 @@ static __must_check inline bool user_access_begin(const void __user *ptr, size_t
401403

402404
might_fault();
403405

406+
barrier_nospec();
404407
allow_read_write_user((void __user *)ptr, ptr, len);
405408
return true;
406409
}
@@ -417,6 +420,7 @@ user_read_access_begin(const void __user *ptr, size_t len)
417420

418421
might_fault();
419422

423+
barrier_nospec();
420424
allow_read_from_user(ptr, len);
421425
return true;
422426
}

0 commit comments

Comments
 (0)