Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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
0fc810ae3ae1 ("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

authored by

Christophe Leroy and committed by
Thomas Gleixner
4db1df7a 3ce17e69

+10 -6
+10 -6
lib/iov_iter.c
··· 49 49 50 50 if (should_fail_usercopy()) 51 51 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 + 58 62 return res; 59 63 } 60 64