[PATCH 7/7] lib/iov_iter: add missing should_fail_usercopy() in copy_to_user_iter_mc()

Josh Law posted 7 patches 3 weeks, 3 days ago
[PATCH 7/7] lib/iov_iter: add missing should_fail_usercopy() in copy_to_user_iter_mc()
Posted by Josh Law 3 weeks, 3 days ago
When running fault injection tests (CONFIG_FAULT_INJECTION_USERCOPY)
against DAX/pmem read paths, the machine-check variant
copy_to_user_iter_mc() is not covered because it skips the
should_fail_usercopy() check that the normal copy_to_user_iter() has.

This means the dax_copy_to_iter() code path used for pmem reads cannot
be exercised by the usercopy fault injector, leaving a gap in test
coverage for a path that has its own distinct error handling (it must
not retry on #MC).

Found by auditing all copy_to_user/copy_from_user helper variants in
the file for consistent use of the fault injection hook and noticing
copy_to_user_iter_mc() was the only one without it.

Add the same should_fail_usercopy() check that copy_to_user_iter() has.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/iov_iter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index a5bb4fbd9d38..89e04066f737 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -204,6 +204,8 @@ static __always_inline
 size_t copy_to_user_iter_mc(void __user *iter_to, size_t progress,
 			    size_t len, void *from, void *priv2)
 {
+	if (should_fail_usercopy())
+		return len;
 	if (access_ok(iter_to, len)) {
 		from += progress;
 		instrument_copy_to_user(iter_to, from, len);
-- 
2.34.1