@@ -7,12 +7,15 @@ The tracking issue for this feature is: [#39699](https://github.com/rust-lang/ru
77This feature allows for use of one of following sanitizers:
88
99* [ AddressSanitizer] [ clang-asan ] a fast memory error detector.
10+ * [ HWAddressSanitizer] [ clang-hwasan ] a memory error detector similar to
11+ AddressSanitizer, but based on partial hardware assistance.
1012* [ LeakSanitizer] [ clang-lsan ] a run-time memory leak detector.
1113* [ MemorySanitizer] [ clang-msan ] a detector of uninitialized reads.
1214* [ ThreadSanitizer] [ clang-tsan ] a fast data race detector.
1315
14- To enable a sanitizer compile with ` -Zsanitizer=address ` , ` -Zsanitizer=leak ` ,
15- ` -Zsanitizer=memory ` or ` -Zsanitizer=thread ` .
16+ To enable a sanitizer compile with ` -Zsanitizer=address ` ,
17+ ` -Zsanitizer=hwaddress ` , ` -Zsanitizer=leak ` , ` -Zsanitizer=memory ` or
18+ ` -Zsanitizer=thread ` .
1619
1720# AddressSanitizer
1821
@@ -174,6 +177,86 @@ Shadow byte legend (one shadow byte represents 8 application bytes):
174177==39249==ABORTING
175178` ` `
176179
180+ # HWAddressSanitizer
181+
182+ HWAddressSanitizer is a newer variant of AddressSanitizer that consumes much
183+ less memory.
184+
185+ HWAddressSanitizer is supported on the following targets:
186+
187+ * ` aarch64-linux-android`
188+ * ` aarch64-unknown-linux-gnu`
189+
190+ HWAddressSanitizer requires ` tagged-globals` target feature to instrument
191+ globals. To enable this target feature compile with ` -C
192+ target-feature=+tagged-globals`
193+
194+ # # Example
195+
196+ Heap buffer overflow:
197+
198+ ` ` ` rust
199+ fn main () {
200+ let xs = vec! [0, 1, 2, 3];
201+ let _y = unsafe { *xs.as_ptr ().offset(4) };
202+ }
203+ ` ` `
204+
205+ ` ` ` shell
206+ $ rustc main.rs -Zsanitizer=hwaddress -C target-feature=+tagged-globals -C
207+ linker=aarch64-linux-gnu-gcc -C link-arg=-fuse-ld=lld --target
208+ aarch64-unknown-linux-gnu
209+ ` ` `
210+
211+ ` ` ` shell
212+ $ ./main
213+ ==241==ERROR: HWAddressSanitizer: tag-mismatch on address 0xefdeffff0050 at pc 0xaaaae0ae4a98
214+ READ of size 4 at 0xefdeffff0050 tags: 2c/00 (ptr/mem) in thread T0
215+ # 0 0xaaaae0ae4a94 (/.../main+0x54a94)
216+ ...
217+
218+ [0xefdeffff0040,0xefdeffff0060) is a small allocated heap chunk; size: 32 offset: 16
219+ 0xefdeffff0050 is located 0 bytes to the right of 16-byte region [0xefdeffff0040,0xefdeffff0050)
220+ allocated here:
221+ # 0 0xaaaae0acb80c (/.../main+0x3b80c)
222+ ...
223+
224+ Thread: T0 0xeffe00002000 stack: [0xffffc28ad000,0xffffc30ad000) sz: 8388608 tls: [0xffffaa10a020,0xffffaa10a7d0)
225+ Memory tags around the buggy address (one tag corresponds to 16 bytes):
226+ 0xfefcefffef80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
227+ 0xfefcefffef90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
228+ 0xfefcefffefa0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
229+ 0xfefcefffefb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
230+ 0xfefcefffefc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
231+ 0xfefcefffefd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
232+ 0xfefcefffefe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
233+ 0xfefcefffeff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
234+ => 0xfefceffff000: d7 d7 05 00 2c [00] 00 00 00 00 00 00 00 00 00 00
235+ 0xfefceffff010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
236+ 0xfefceffff020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
237+ 0xfefceffff030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
238+ 0xfefceffff040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
239+ 0xfefceffff050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
240+ 0xfefceffff060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
241+ 0xfefceffff070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
242+ 0xfefceffff080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
243+ Tags for short granules around the buggy address (one tag corresponds to 16 bytes):
244+ 0xfefcefffeff0: .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
245+ => 0xfefceffff000: .. .. 8c .. .. [..] .. .. .. .. .. .. .. .. .. ..
246+ 0xfefceffff010: .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
247+ See https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#short-granules for a description of short granule tags
248+ Registers where the failure occurred (pc 0xaaaae0ae4a98):
249+ x0 2c00efdeffff0050 x1 0000000000000004 x2 0000000000000004 x3 0000000000000000
250+ x4 0000fffefc30ac37 x5 000000000000005d x6 00000ffffc30ac37 x7 0000efff00000000
251+ x8 2c00efdeffff0050 x9 0200efff00000000 x10 0000000000000000 x11 0200efff00000000
252+ x12 0200effe00000310 x13 0200effe00000310 x14 0000000000000008 x15 5d00ffffc30ac360
253+ x16 0000aaaae0ad062c x17 0000000000000003 x18 0000000000000001 x19 0000ffffc30ac658
254+ x20 4e00ffffc30ac6e0 x21 0000aaaae0ac5e10 x22 0000000000000000 x23 0000000000000000
255+ x24 0000000000000000 x25 0000000000000000 x26 0000000000000000 x27 0000000000000000
256+ x28 0000000000000000 x29 0000ffffc30ac5a0 x30 0000aaaae0ae4a98
257+ SUMMARY: HWAddressSanitizer: tag-mismatch (/.../main+0x54a94)
258+ ` ` `
259+
177260# LeakSanitizer
178261
179262LeakSanitizer is run-time memory leak detector.
@@ -321,11 +404,13 @@ Sanitizers produce symbolized stacktraces when llvm-symbolizer binary is in `PAT
321404
322405* [Sanitizers project page](https://github.com/google/sanitizers/wiki/)
323406* [AddressSanitizer in Clang][clang-asan]
407+ * [HWAddressSanitizer in Clang][clang-hwasan]
324408* [LeakSanitizer in Clang][clang-lsan]
325409* [MemorySanitizer in Clang][clang-msan]
326410* [ThreadSanitizer in Clang][clang-tsan]
327411
328412[clang-asan]: https://clang.llvm.org/docs/AddressSanitizer.html
413+ [clang-hwasan]: https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
329414[clang-lsan]: https://clang.llvm.org/docs/LeakSanitizer.html
330415[clang-msan]: https://clang.llvm.org/docs/MemorySanitizer.html
331416[clang-tsan]: https://clang.llvm.org/docs/ThreadSanitizer.html
0 commit comments