kasan-checks.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_KASAN_CHECKS_H
  3. #define _LINUX_KASAN_CHECKS_H
  4. #include <linux/types.h>
  5. /*
  6. * The annotations present in this file are only relevant for the software
  7. * KASAN modes that rely on compiler instrumentation, and will be optimized
  8. * away for the hardware tag-based KASAN mode. Use kasan_check_byte() instead.
  9. */
  10. /*
  11. * __kasan_check_*: Always available when KASAN is enabled. This may be used
  12. * even in compilation units that selectively disable KASAN, but must use KASAN
  13. * to validate access to an address. Never use these in header files!
  14. */
  15. #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
  16. bool __kasan_check_read(const volatile void *p, unsigned int size);
  17. bool __kasan_check_write(const volatile void *p, unsigned int size);
  18. #else
  19. static inline bool __kasan_check_read(const volatile void *p, unsigned int size)
  20. {
  21. return true;
  22. }
  23. static inline bool __kasan_check_write(const volatile void *p, unsigned int size)
  24. {
  25. return true;
  26. }
  27. #endif
  28. /*
  29. * kasan_check_*: Only available when the particular compilation unit has KASAN
  30. * instrumentation enabled. May be used in header files.
  31. */
  32. #ifdef __SANITIZE_ADDRESS__
  33. #define kasan_check_read __kasan_check_read
  34. #define kasan_check_write __kasan_check_write
  35. #else
  36. static inline bool kasan_check_read(const volatile void *p, unsigned int size)
  37. {
  38. return true;
  39. }
  40. static inline bool kasan_check_write(const volatile void *p, unsigned int size)
  41. {
  42. return true;
  43. }
  44. #endif
  45. #endif