~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/instrumented.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/instrumented.h (Version linux-6.12-rc7) and /include/linux/instrumented.h (Version linux-6.0.19)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2                                                     2 
  3 /*                                                  3 /*
  4  * This header provides generic wrappers for m      4  * This header provides generic wrappers for memory access instrumentation that
  5  * the compiler cannot emit for: KASAN, KCSAN, !!   5  * the compiler cannot emit for: KASAN, KCSAN.
  6  */                                                 6  */
  7 #ifndef _LINUX_INSTRUMENTED_H                       7 #ifndef _LINUX_INSTRUMENTED_H
  8 #define _LINUX_INSTRUMENTED_H                       8 #define _LINUX_INSTRUMENTED_H
  9                                                     9 
 10 #include <linux/compiler.h>                        10 #include <linux/compiler.h>
 11 #include <linux/kasan-checks.h>                    11 #include <linux/kasan-checks.h>
 12 #include <linux/kcsan-checks.h>                    12 #include <linux/kcsan-checks.h>
 13 #include <linux/kmsan-checks.h>                << 
 14 #include <linux/types.h>                           13 #include <linux/types.h>
 15                                                    14 
 16 /**                                                15 /**
 17  * instrument_read - instrument regular read a     16  * instrument_read - instrument regular read access
 18  * @v: address of access                       << 
 19  * @size: size of access                       << 
 20  *                                                 17  *
 21  * Instrument a regular read access. The instr     18  * Instrument a regular read access. The instrumentation should be inserted
 22  * before the actual read happens.                 19  * before the actual read happens.
                                                   >>  20  *
                                                   >>  21  * @ptr address of access
                                                   >>  22  * @size size of access
 23  */                                                23  */
 24 static __always_inline void instrument_read(co     24 static __always_inline void instrument_read(const volatile void *v, size_t size)
 25 {                                                  25 {
 26         kasan_check_read(v, size);                 26         kasan_check_read(v, size);
 27         kcsan_check_read(v, size);                 27         kcsan_check_read(v, size);
 28 }                                                  28 }
 29                                                    29 
 30 /**                                                30 /**
 31  * instrument_write - instrument regular write     31  * instrument_write - instrument regular write access
 32  * @v: address of access                       << 
 33  * @size: size of access                       << 
 34  *                                                 32  *
 35  * Instrument a regular write access. The inst     33  * Instrument a regular write access. The instrumentation should be inserted
 36  * before the actual write happens.                34  * before the actual write happens.
                                                   >>  35  *
                                                   >>  36  * @ptr address of access
                                                   >>  37  * @size size of access
 37  */                                                38  */
 38 static __always_inline void instrument_write(c     39 static __always_inline void instrument_write(const volatile void *v, size_t size)
 39 {                                                  40 {
 40         kasan_check_write(v, size);                41         kasan_check_write(v, size);
 41         kcsan_check_write(v, size);                42         kcsan_check_write(v, size);
 42 }                                                  43 }
 43                                                    44 
 44 /**                                                45 /**
 45  * instrument_read_write - instrument regular      46  * instrument_read_write - instrument regular read-write access
 46  * @v: address of access                       << 
 47  * @size: size of access                       << 
 48  *                                                 47  *
 49  * Instrument a regular write access. The inst     48  * Instrument a regular write access. The instrumentation should be inserted
 50  * before the actual write happens.                49  * before the actual write happens.
                                                   >>  50  *
                                                   >>  51  * @ptr address of access
                                                   >>  52  * @size size of access
 51  */                                                53  */
 52 static __always_inline void instrument_read_wr     54 static __always_inline void instrument_read_write(const volatile void *v, size_t size)
 53 {                                                  55 {
 54         kasan_check_write(v, size);                56         kasan_check_write(v, size);
 55         kcsan_check_read_write(v, size);           57         kcsan_check_read_write(v, size);
 56 }                                                  58 }
 57                                                    59 
 58 /**                                                60 /**
 59  * instrument_atomic_read - instrument atomic      61  * instrument_atomic_read - instrument atomic read access
 60  * @v: address of access                       << 
 61  * @size: size of access                       << 
 62  *                                                 62  *
 63  * Instrument an atomic read access. The instr     63  * Instrument an atomic read access. The instrumentation should be inserted
 64  * before the actual read happens.                 64  * before the actual read happens.
                                                   >>  65  *
                                                   >>  66  * @ptr address of access
                                                   >>  67  * @size size of access
 65  */                                                68  */
 66 static __always_inline void instrument_atomic_     69 static __always_inline void instrument_atomic_read(const volatile void *v, size_t size)
 67 {                                                  70 {
 68         kasan_check_read(v, size);                 71         kasan_check_read(v, size);
 69         kcsan_check_atomic_read(v, size);          72         kcsan_check_atomic_read(v, size);
 70 }                                                  73 }
 71                                                    74 
 72 /**                                                75 /**
 73  * instrument_atomic_write - instrument atomic     76  * instrument_atomic_write - instrument atomic write access
 74  * @v: address of access                       << 
 75  * @size: size of access                       << 
 76  *                                                 77  *
 77  * Instrument an atomic write access. The inst     78  * Instrument an atomic write access. The instrumentation should be inserted
 78  * before the actual write happens.                79  * before the actual write happens.
                                                   >>  80  *
                                                   >>  81  * @ptr address of access
                                                   >>  82  * @size size of access
 79  */                                                83  */
 80 static __always_inline void instrument_atomic_     84 static __always_inline void instrument_atomic_write(const volatile void *v, size_t size)
 81 {                                                  85 {
 82         kasan_check_write(v, size);                86         kasan_check_write(v, size);
 83         kcsan_check_atomic_write(v, size);         87         kcsan_check_atomic_write(v, size);
 84 }                                                  88 }
 85                                                    89 
 86 /**                                                90 /**
 87  * instrument_atomic_read_write - instrument a     91  * instrument_atomic_read_write - instrument atomic read-write access
 88  * @v: address of access                       << 
 89  * @size: size of access                       << 
 90  *                                                 92  *
 91  * Instrument an atomic read-write access. The     93  * Instrument an atomic read-write access. The instrumentation should be
 92  * inserted before the actual write happens.       94  * inserted before the actual write happens.
                                                   >>  95  *
                                                   >>  96  * @ptr address of access
                                                   >>  97  * @size size of access
 93  */                                                98  */
 94 static __always_inline void instrument_atomic_     99 static __always_inline void instrument_atomic_read_write(const volatile void *v, size_t size)
 95 {                                                 100 {
 96         kasan_check_write(v, size);               101         kasan_check_write(v, size);
 97         kcsan_check_atomic_read_write(v, size)    102         kcsan_check_atomic_read_write(v, size);
 98 }                                                 103 }
 99                                                   104 
100 /**                                               105 /**
101  * instrument_copy_to_user - instrument reads     106  * instrument_copy_to_user - instrument reads of copy_to_user
102  * @to: destination address                    << 
103  * @from: source address                       << 
104  * @n: number of bytes to copy                 << 
105  *                                                107  *
106  * Instrument reads from kernel memory, that a    108  * Instrument reads from kernel memory, that are due to copy_to_user (and
107  * variants). The instrumentation must be inse    109  * variants). The instrumentation must be inserted before the accesses.
                                                   >> 110  *
                                                   >> 111  * @to destination address
                                                   >> 112  * @from source address
                                                   >> 113  * @n number of bytes to copy
108  */                                               114  */
109 static __always_inline void                       115 static __always_inline void
110 instrument_copy_to_user(void __user *to, const    116 instrument_copy_to_user(void __user *to, const void *from, unsigned long n)
111 {                                                 117 {
112         kasan_check_read(from, n);                118         kasan_check_read(from, n);
113         kcsan_check_read(from, n);                119         kcsan_check_read(from, n);
114         kmsan_copy_to_user(to, from, n, 0);    << 
115 }                                                 120 }
116                                                   121 
117 /**                                               122 /**
118  * instrument_copy_from_user_before - add inst !! 123  * instrument_copy_from_user - instrument writes of copy_from_user
119  * @to: destination address                    << 
120  * @from: source address                       << 
121  * @n: number of bytes to copy                 << 
122  *                                                124  *
123  * Instrument writes to kernel memory, that ar    125  * Instrument writes to kernel memory, that are due to copy_from_user (and
124  * variants). The instrumentation should be in    126  * variants). The instrumentation should be inserted before the accesses.
125  */                                            << 
126 static __always_inline void                    << 
127 instrument_copy_from_user_before(const void *t << 
128 {                                              << 
129         kasan_check_write(to, n);              << 
130         kcsan_check_write(to, n);              << 
131 }                                              << 
132                                                << 
133 /**                                            << 
134  * instrument_copy_from_user_after - add instr << 
135  * @to: destination address                    << 
136  * @from: source address                       << 
137  * @n: number of bytes to copy                 << 
138  * @left: number of bytes not copied (as retur << 
139  *                                                127  *
140  * Instrument writes to kernel memory, that ar !! 128  * @to destination address
141  * variants). The instrumentation should be in !! 129  * @from source address
                                                   >> 130  * @n number of bytes to copy
142  */                                               131  */
143 static __always_inline void                       132 static __always_inline void
144 instrument_copy_from_user_after(const void *to !! 133 instrument_copy_from_user(const void *to, const void __user *from, unsigned long n)
145                                 unsigned long  << 
146 {                                              << 
147         kmsan_unpoison_memory(to, n - left);   << 
148 }                                              << 
149                                                << 
150 /**                                            << 
151  * instrument_memcpy_before - add instrumentat << 
152  * @to: destination address                    << 
153  * @from: source address                       << 
154  * @n: number of bytes to copy                 << 
155  *                                             << 
156  * Instrument memory accesses that happen in c << 
157  * instrumentation should be inserted before t << 
158  */                                            << 
159 static __always_inline void instrument_memcpy_ << 
160                                                << 
161 {                                                 134 {
162         kasan_check_write(to, n);                 135         kasan_check_write(to, n);
163         kasan_check_read(from, n);             << 
164         kcsan_check_write(to, n);                 136         kcsan_check_write(to, n);
165         kcsan_check_read(from, n);             << 
166 }                                              << 
167                                                << 
168 /**                                            << 
169  * instrument_memcpy_after - add instrumentati << 
170  * @to: destination address                    << 
171  * @from: source address                       << 
172  * @n: number of bytes to copy                 << 
173  * @left: number of bytes not copied (if known << 
174  *                                             << 
175  * Instrument memory accesses that happen in c << 
176  * instrumentation should be inserted after th << 
177  */                                            << 
178 static __always_inline void instrument_memcpy_ << 
179                                                << 
180                                                << 
181 {                                              << 
182         kmsan_memmove(to, from, n - left);     << 
183 }                                                 137 }
184                                                << 
185 /**                                            << 
186  * instrument_get_user() - add instrumentation << 
187  * @to: destination variable, may not be addre << 
188  *                                             << 
189  * get_user() and friends are fragile, so it m << 
190  * whether the instrumentation happens before  << 
191  * the userspace.                              << 
192  */                                            << 
193 #define instrument_get_user(to)                << 
194 ({                                             << 
195         u64 __tmp = (u64)(to);                 << 
196         kmsan_unpoison_memory(&__tmp, sizeof(_ << 
197         to = __tmp;                            << 
198 })                                             << 
199                                                << 
200                                                << 
201 /**                                            << 
202  * instrument_put_user() - add instrumentation << 
203  * @from: source address                       << 
204  * @ptr: userspace pointer to copy to          << 
205  * @size: number of bytes to copy              << 
206  *                                             << 
207  * put_user() and friends are fragile, so it m << 
208  * whether the instrumentation happens before  << 
209  * the userspace.                              << 
210  */                                            << 
211 #define instrument_put_user(from, ptr, size)   << 
212 ({                                             << 
213         kmsan_copy_to_user(ptr, &from, sizeof( << 
214 })                                             << 
215                                                   138 
216 #endif /* _LINUX_INSTRUMENTED_H */                139 #endif /* _LINUX_INSTRUMENTED_H */
217                                                   140 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php