instrumentedh-allow-instrumenting-both-sides-of-copy_from_user.patch removed from -mm tree
The quilt patch titled
Subject: instrumented.h: allow instrumenting both sides of copy_from_user()
has been removed from the -mm tree. Its filename was
instrumentedh-allow-instrumenting-both-sides-of-copy_from_user.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Alexander Potapenko <[email protected]>
Subject: instrumented.h: allow instrumenting both sides of copy_from_user()
Date: Thu, 15 Sep 2022 17:03:37 +0200
Introduce instrument_copy_from_user_before() and instrument_copy_from_user_after() hooks to be invoked before and after the call to copy_from_user().
KASAN and KCSAN will be only using instrument_copy_from_user_before(), but for KMSAN we'll need to insert code after copy_from_user().
---
arch/s390/lib/uaccess.c | 3 ++- include/linux/instrumented.h | 21 +++++++++++++++++++-- include/linux/uaccess.h | 19 ++++++++++++++----- lib/iov_iter.c | 9 ++++++--- lib/usercopy.c | 3 ++- 5 files changed, 43 insertions(+), 12 deletions(-)
arch/s390/lib/uaccess.c renamed from arch/s390/lib/uaccess.c~instrumentedh-allow-instrumenting-both-sides-of-copy_from_user +2 -1
@@ -81,8 +81,9 @@ unsigned long _copy_from_user_key(void *might_fault ();if (!should_fail_usercopy ()) { -instrument_copy_from_user (to, from, n); +instrument_copy_from_user_before (to, from, n); res =raw_copy_from_user_key (to, from, n, key); +instrument_copy_from_user_after (to, from, n, res); }if (unlikely (res))memset (to + (n - res),0 , res);
include/linux/instrumented.h renamed from include/linux/instrumented.h~instrumentedh-allow-instrumenting-both-sides-of-copy_from_user +19 -2
@@ -120,7 +120,7 @@ instrument_copy_to_user(void __user *to, }/** -* instrument_copy_from_user - instrument writes of copy_from_user +* instrument_copy_from_user_before - add instrumentation before copy_from_user * * Instrument writes to kernel memory, that are due to copy_from_user (and * variants). The instrumentation should be inserted before the accesses.
@@ -130,10 +130,27 @@ instrument_copy_to_user(void __user *to,* @n number of bytes to copy */ static __always_inline void -instrument_copy_from_user (const void *to,const void __user *from,unsigned long n) +instrument_copy_from_user_before (const void *to,const void __user *from,unsigned long n) {kasan_check_write (to, n);kcsan_check_write (to, n); } +/** +* instrument_copy_from_user_after - add instrumentation after copy_from_user +* +* Instrument writes to kernel memory, that are due to copy_from_user (and +* variants). The instrumentation should be inserted after the accesses. +* +* @to destination address +* @from source address +* @n number of bytes to copy +* @left number of bytes not copied (as returned by copy_from_user) +*/ +static __always_inline void +instrument_copy_from_user_after (const void *to,const void __user *from, +unsigned long n,unsigned long left) +{ +} +#endif /* _LINUX_INSTRUMENTED_H */
include/linux/uaccess.h renamed from include/linux/uaccess.h~instrumentedh-allow-instrumenting-both-sides-of-copy_from_user +14 -5
@@ -58,20 +58,28 @@static __always_inline __must_check unsigned long __copy_from_user_inatomic (void *to,const void __user *from,unsigned long n) { -instrument_copy_from_user (to, from, n); +unsigned long res; + +instrument_copy_from_user_before (to, from, n);check_object_size (to, n, false); -return raw_copy_from_user (to, from, n); + res =raw_copy_from_user (to, from, n); +instrument_copy_from_user_after (to, from, n, res); +return res; }static __always_inline __must_check unsigned long __copy_from_user (void *to,const void __user *from,unsigned long n) { +unsigned long res; +might_fault (); +instrument_copy_from_user_before (to, from, n);if (should_fail_usercopy ())return n; -instrument_copy_from_user (to, from, n);check_object_size (to, n, false); -return raw_copy_from_user (to, from, n); + res =raw_copy_from_user (to, from, n); +instrument_copy_from_user_after (to, from, n, res); +return res; }/**
@@ -115,8 +123,9 @@ _copy_from_user(void *to, const void __uunsigned long res = n;might_fault ();if (!should_fail_usercopy () &&likely (access_ok (from, n))) { -instrument_copy_from_user (to, from, n); +instrument_copy_from_user_before (to, from, n); res =raw_copy_from_user (to, from, n); +instrument_copy_from_user_after (to, from, n, res); }if (unlikely (res))memset (to + (n - res),0 , res);
lib/iov_iter.c renamed from lib/iov_iter.c~instrumentedh-allow-instrumenting-both-sides-of-copy_from_user +6 -3
@@ -174,13 +174,16 @@ static int copyout(void __user *to, consstatic int copyin (void *to,const void __user *from,size_t n) { +size_t res = n; +if (should_fail_usercopy ())return n;if (access_ok (from, n)) { -instrument_copy_from_user (to, from, n); - n =raw_copy_from_user (to, from, n); +instrument_copy_from_user_before (to, from, n); + res =raw_copy_from_user (to, from, n); +instrument_copy_from_user_after (to, from, n, res); } -return n; +return res; } static inline struct pipe_buffer *pipe_buf(const struct pipe_inode_info *pipe,
lib/usercopy.c renamed from lib/usercopy.c~instrumentedh-allow-instrumenting-both-sides-of-copy_from_user +2 -1
@@ -12,8 +12,9 @@ unsigned long _copy_from_user(void *to,unsigned long res = n;might_fault ();if (!should_fail_usercopy () &&likely (access_ok (from, n))) { -instrument_copy_from_user (to, from, n); +instrument_copy_from_user_before (to, from, n); res =raw_copy_from_user (to, from, n); +instrument_copy_from_user_after (to, from, n, res); }if (unlikely (res))memset (to + (n - res),0 , res);
_
Patches currently in -mm which might be from [email protected] are