Skip to content

Commit 803abed

Browse files
chleroyKAGA-KOKO
authored andcommitted
iov_iter: Add missing speculation barrier to copy_from_user_iter()
The results of "access_ok()" can be mis-speculated. The result is that the CPU can end speculatively: if (access_ok(from, size)) // Right here For the same reason as done in copy_from_user() in commit 74e19ef ("uaccess: Add speculation barrier to copy_from_user()"), add a speculation barrier to copy_from_user_iter(). Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://patch.msgid.link/6b73e69cc7168c89df4eab0a216e3ed4cca36b0a.1763396724.git.christophe.leroy@csgroup.eu
1 parent 4db1df7 commit 803abed

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/iov_iter.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ size_t copy_from_user_iter(void __user *iter_from, size_t progress,
4949

5050
if (should_fail_usercopy())
5151
return len;
52-
if (can_do_masked_user_access())
52+
if (can_do_masked_user_access()) {
5353
iter_from = mask_user_address(iter_from);
54-
else if (!access_ok(iter_from, len))
55-
return res;
54+
} else {
55+
if (!access_ok(iter_from, len))
56+
return res;
5657

58+
/*
59+
* Ensure that bad access_ok() speculation will not
60+
* lead to nasty side effects *after* the copy is
61+
* finished:
62+
*/
63+
barrier_nospec();
64+
}
5765
to += progress;
5866
instrument_copy_from_user_before(to, iter_from, len);
5967
res = raw_copy_from_user(to, iter_from, len);

0 commit comments

Comments
 (0)