Skip to content

Commit 4db1df7

Browse files
chleroyKAGA-KOKO
authored andcommitted
iov_iter: Convert copy_from_user_iter() to masked user access
copy_from_user_iter() lacks a speculation barrier, which will degrade performance on some architecture like x86, which would be unfortunate as copy_from_user_iter() is a critical hotpath function. Convert copy_from_user_iter() to using masked user access on architecture that support it. This allows to add the speculation barrier without impacting performance. This is similar to what was done for copy_from_user() in commit 0fc810a ("x86/uaccess: Avoid barrier_nospec() in 64-bit copy_from_user()") [ tglx: Massage change log ] Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://patch.msgid.link/58e4b07d469ca68a2b9477fe2c1ccc8a44cef131.1763396724.git.christophe.leroy@csgroup.eu
1 parent 3ce17e6 commit 4db1df7

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lib/iov_iter.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ size_t copy_from_user_iter(void __user *iter_from, size_t progress,
4949

5050
if (should_fail_usercopy())
5151
return len;
52-
if (access_ok(iter_from, len)) {
53-
to += progress;
54-
instrument_copy_from_user_before(to, iter_from, len);
55-
res = raw_copy_from_user(to, iter_from, len);
56-
instrument_copy_from_user_after(to, iter_from, len, res);
57-
}
52+
if (can_do_masked_user_access())
53+
iter_from = mask_user_address(iter_from);
54+
else if (!access_ok(iter_from, len))
55+
return res;
56+
57+
to += progress;
58+
instrument_copy_from_user_before(to, iter_from, len);
59+
res = raw_copy_from_user(to, iter_from, len);
60+
instrument_copy_from_user_after(to, iter_from, len, res);
61+
5862
return res;
5963
}
6064

0 commit comments

Comments
 (0)