2018-08-30 06:23:34 +08:00
|
|
|
//===-- hwasan_interface_internal.h -----------------------------*- C++ -*-===//
|
2017-12-09 09:31:51 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-12-09 09:31:51 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of HWAddressSanitizer.
|
|
|
|
//
|
|
|
|
// Private Hwasan interface header.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef HWASAN_INTERFACE_INTERNAL_H
|
|
|
|
#define HWASAN_INTERFACE_INTERNAL_H
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_internal_defs.h"
|
2018-09-07 06:53:08 +08:00
|
|
|
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
|
2019-08-07 06:07:29 +08:00
|
|
|
#include <link.h>
|
2017-12-09 09:31:51 +08:00
|
|
|
|
|
|
|
extern "C" {
|
2018-04-24 02:19:23 +08:00
|
|
|
|
2018-08-14 03:57:11 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2019-02-01 07:37:12 +08:00
|
|
|
void __hwasan_init_static();
|
2018-08-14 03:57:11 +08:00
|
|
|
|
2017-12-09 09:31:51 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_init();
|
|
|
|
|
2019-08-07 06:07:29 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_library_loaded(ElfW(Addr) base, const ElfW(Phdr) * phdr,
|
|
|
|
ElfW(Half) phnum);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_library_unloaded(ElfW(Addr) base, const ElfW(Phdr) * phdr,
|
|
|
|
ElfW(Half) phnum);
|
|
|
|
|
2017-12-09 09:31:51 +08:00
|
|
|
using __sanitizer::uptr;
|
|
|
|
using __sanitizer::sptr;
|
|
|
|
using __sanitizer::uu64;
|
|
|
|
using __sanitizer::uu32;
|
|
|
|
using __sanitizer::uu16;
|
|
|
|
using __sanitizer::u64;
|
|
|
|
using __sanitizer::u32;
|
|
|
|
using __sanitizer::u16;
|
|
|
|
using __sanitizer::u8;
|
|
|
|
|
2018-10-23 08:50:40 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_init_frames(uptr, uptr);
|
|
|
|
|
2018-04-24 02:19:23 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
extern uptr __hwasan_shadow_memory_dynamic_address;
|
|
|
|
|
2017-12-09 09:31:51 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2018-04-19 06:05:18 +08:00
|
|
|
void __hwasan_loadN(uptr, uptr);
|
2017-12-09 09:31:51 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load1(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load2(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load4(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load8(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load16(uptr);
|
|
|
|
|
2017-12-21 03:05:44 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2018-04-19 06:05:18 +08:00
|
|
|
void __hwasan_loadN_noabort(uptr, uptr);
|
2017-12-21 03:05:44 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load1_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load2_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load4_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load8_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_load16_noabort(uptr);
|
|
|
|
|
2017-12-09 09:31:51 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2018-04-19 06:05:18 +08:00
|
|
|
void __hwasan_storeN(uptr, uptr);
|
2017-12-09 09:31:51 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store1(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store2(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store4(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store8(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store16(uptr);
|
|
|
|
|
2017-12-21 03:05:44 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2018-04-19 06:05:18 +08:00
|
|
|
void __hwasan_storeN_noabort(uptr, uptr);
|
2017-12-21 03:05:44 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store1_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store2_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store4_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store8_noabort(uptr);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_store16_noabort(uptr);
|
|
|
|
|
2018-01-12 06:53:30 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_tag_memory(uptr p, u8 tag, uptr sz);
|
|
|
|
|
2018-08-15 08:39:35 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
uptr __hwasan_tag_pointer(uptr p, u8 tag);
|
|
|
|
|
[HWASan] Save + print registers when tag mismatch occurs in AArch64.
Summary:
This change change the instrumentation to allow users to view the registers at the point at which tag mismatch occured. Most of the heavy lifting is done in the runtime library, where we save the registers to the stack and emit unwind information. This allows us to reduce the overhead, as very little additional work needs to be done in each __hwasan_check instance.
In this implementation, the fast path of __hwasan_check is unmodified. There are an additional 4 instructions (16B) emitted in the slow path in every __hwasan_check instance. This may increase binary size somewhat, but as most of the work is done in the runtime library, it's manageable.
The failure trace now contains a list of registers at the point of which the failure occured, in a format similar to that of Android's tombstones. It currently has the following format:
Registers where the failure occurred (pc 0x0055555561b4):
x0 0000000000000014 x1 0000007ffffff6c0 x2 1100007ffffff6d0 x3 12000056ffffe025
x4 0000007fff800000 x5 0000000000000014 x6 0000007fff800000 x7 0000000000000001
x8 12000056ffffe020 x9 0200007700000000 x10 0200007700000000 x11 0000000000000000
x12 0000007fffffdde0 x13 0000000000000000 x14 02b65b01f7a97490 x15 0000000000000000
x16 0000007fb77376b8 x17 0000000000000012 x18 0000007fb7ed6000 x19 0000005555556078
x20 0000007ffffff768 x21 0000007ffffff778 x22 0000000000000001 x23 0000000000000000
x24 0000000000000000 x25 0000000000000000 x26 0000000000000000 x27 0000000000000000
x28 0000000000000000 x29 0000007ffffff6f0 x30 00000055555561b4
... and prints after the dump of memory tags around the buggy address.
Every register is saved exactly as it was at the point where the tag mismatch occurs, with the exception of x16/x17. These registers are used in the tag mismatch calculation as scratch registers during __hwasan_check, and cannot be saved without affecting the fast path. As these registers are designated as scratch registers for linking, there should be no important information in them that could aid in debugging.
Reviewers: pcc, eugenis
Reviewed By: pcc, eugenis
Subscribers: srhines, kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, hiraditya, jdoerfert, llvm-commits, #sanitizers
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D58857
llvm-svn: 355738
2019-03-09 05:22:35 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_tag_mismatch(uptr addr, u8 ts);
|
|
|
|
|
2019-10-24 18:16:06 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame,
|
|
|
|
size_t outsize);
|
|
|
|
|
2018-01-13 09:32:15 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
u8 __hwasan_generate_tag();
|
|
|
|
|
2017-12-09 09:31:51 +08:00
|
|
|
// Returns the offset of the first tag mismatch or -1 if the whole range is
|
|
|
|
// good.
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
sptr __hwasan_test_shadow(const void *x, uptr size);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
/* OPTIONAL */ const char* __hwasan_default_options();
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_print_shadow(const void *x, uptr size);
|
|
|
|
|
2018-08-17 07:17:14 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_handle_longjmp(const void *sp_dst);
|
|
|
|
|
[hwasan, asan] Intercept vfork.
Summary:
Intercept vfork on arm, aarch64, i386 and x86_64.
Reviewers: pcc, vitalybuka
Subscribers: kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D58533
llvm-svn: 355030
2019-02-28 05:11:50 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_handle_vfork(const void *sp_dst);
|
|
|
|
|
2017-12-09 09:31:51 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
u16 __sanitizer_unaligned_load16(const uu16 *p);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
u32 __sanitizer_unaligned_load32(const uu32 *p);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
u64 __sanitizer_unaligned_load64(const uu64 *p);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __sanitizer_unaligned_store16(uu16 *p, u16 x);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __sanitizer_unaligned_store32(uu32 *p, u32 x);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __sanitizer_unaligned_store64(uu64 *p, u64 x);
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_enable_allocator_tagging();
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_disable_allocator_tagging();
|
|
|
|
|
[hwasan] Add a (almost) no-interceptor mode.
Summary:
The idea behind this change is to allow sanitization of libc. We are prototyping on Bionic,
but the tool interface will be general enough (or at least generalizable) to support any other libc.
When libc depends on libclang_rt.hwasan, the latter can not interpose libc functions.
In fact, majority of interceptors become unnecessary when libc code is instrumented.
This change gets rid of most hwasan interceptors and provides interface for libc to notify
hwasan about thread creation and destruction events. Some interceptors (pthread_create)
are kept under #ifdef to enable testing with uninstrumented libc. They are expressed in
terms of the new libc interface.
The new cmake switch, COMPILER_RT_HWASAN_WITH_INTERCEPTORS, ON by default, builds testing
version of the library with the aforementioned pthread_create interceptor.
With the OFF setting, the library becomes more of a libc plugin.
Reviewers: vitalybuka, kcc, jfb
Subscribers: srhines, kubamracek, mgorny, jfb, llvm-commits
Differential Revision: https://reviews.llvm.org/D50922
llvm-svn: 340216
2018-08-21 05:49:15 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_thread_enter();
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_thread_exit();
|
|
|
|
|
2018-09-07 06:08:41 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_print_memory_usage();
|
|
|
|
|
2018-12-20 17:10:03 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void *__hwasan_memcpy(void *dst, const void *src, uptr size);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void *__hwasan_memset(void *s, int c, uptr n);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void *__hwasan_memmove(void *dest, const void *src, uptr n);
|
2020-11-20 06:34:56 +08:00
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __hwasan_set_error_report_callback(void (*callback)(const char *));
|
2017-12-09 09:31:51 +08:00
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
#endif // HWASAN_INTERFACE_INTERNAL_H
|