Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add KASAN instrumentation on the bus_space functions tha...
details: https://anonhg.NetBSD.org/src/rev/5142f06bfa0d
branches: trunk
changeset: 454155:5142f06bfa0d
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Sep 07 10:24:01 2019 +0000
description:
Add KASAN instrumentation on the bus_space functions that handle buffers.
diffstat:
sys/kern/subr_asan.c | 151 ++++++++++++++++++++++++++++++++++++++++++++-
sys/sys/bus_proto.h | 172 +++++++++++++++++++++++++-------------------------
2 files changed, 236 insertions(+), 87 deletions(-)
diffs (truncated from 374 to 300 lines):
diff -r b2313659e968 -r 5142f06bfa0d sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c Sat Sep 07 09:57:37 2019 +0000
+++ b/sys/kern/subr_asan.c Sat Sep 07 10:24:01 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_asan.c,v 1.12 2019/09/07 09:46:07 maxv Exp $ */
+/* $NetBSD: subr_asan.c,v 1.13 2019/09/07 10:24:01 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.12 2019/09/07 09:46:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.13 2019/09/07 10:24:01 maxv Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -781,6 +781,153 @@
/* -------------------------------------------------------------------------- */
+#include <sys/bus.h>
+
+#undef bus_space_read_multi_1
+#undef bus_space_read_multi_2
+#undef bus_space_read_multi_4
+#undef bus_space_read_multi_8
+#undef bus_space_read_multi_stream_1
+#undef bus_space_read_multi_stream_2
+#undef bus_space_read_multi_stream_4
+#undef bus_space_read_multi_stream_8
+#undef bus_space_read_region_1
+#undef bus_space_read_region_2
+#undef bus_space_read_region_4
+#undef bus_space_read_region_8
+#undef bus_space_read_region_stream_1
+#undef bus_space_read_region_stream_2
+#undef bus_space_read_region_stream_4
+#undef bus_space_read_region_stream_8
+#undef bus_space_write_multi_1
+#undef bus_space_write_multi_2
+#undef bus_space_write_multi_4
+#undef bus_space_write_multi_8
+#undef bus_space_write_multi_stream_1
+#undef bus_space_write_multi_stream_2
+#undef bus_space_write_multi_stream_4
+#undef bus_space_write_multi_stream_8
+#undef bus_space_write_region_1
+#undef bus_space_write_region_2
+#undef bus_space_write_region_4
+#undef bus_space_write_region_8
+#undef bus_space_write_region_stream_1
+#undef bus_space_write_region_stream_2
+#undef bus_space_write_region_stream_4
+#undef bus_space_write_region_stream_8
+
+#define ASAN_BUS_READ_FUNC(bytes, bits) \
+ void bus_space_read_multi_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_multi_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_multi_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, false, __RET_ADDR); \
+ bus_space_read_multi_##bytes(tag, hnd, size, buf, count); \
+ } \
+ void bus_space_read_multi_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_multi_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_multi_stream_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, false, __RET_ADDR); \
+ bus_space_read_multi_stream_##bytes(tag, hnd, size, buf, count);\
+ } \
+ void bus_space_read_region_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_region_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_region_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, false, __RET_ADDR); \
+ bus_space_read_region_##bytes(tag, hnd, size, buf, count); \
+ } \
+ void bus_space_read_region_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_region_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_read_region_stream_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, false, __RET_ADDR); \
+ bus_space_read_region_stream_##bytes(tag, hnd, size, buf, count);\
+ }
+
+#define ASAN_BUS_WRITE_FUNC(bytes, bits) \
+ void bus_space_write_multi_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, const uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_write_multi_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, const uint##bits##_t *, bus_size_t);\
+ void kasan_bus_space_write_multi_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, const uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, true, __RET_ADDR); \
+ bus_space_write_multi_##bytes(tag, hnd, size, buf, count); \
+ } \
+ void bus_space_write_multi_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, const uint##bits##_t *, bus_size_t);\
+ void kasan_bus_space_write_multi_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, const uint##bits##_t *, bus_size_t);\
+ void kasan_bus_space_write_multi_stream_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, const uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, true, __RET_ADDR); \
+ bus_space_write_multi_stream_##bytes(tag, hnd, size, buf, count);\
+ } \
+ void bus_space_write_region_##bytes(bus_space_tag_t, bus_space_handle_t,\
+ bus_size_t, const uint##bits##_t *, bus_size_t); \
+ void kasan_bus_space_write_region_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, const uint##bits##_t *, bus_size_t);\
+ void kasan_bus_space_write_region_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, const uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, true, __RET_ADDR); \
+ bus_space_write_region_##bytes(tag, hnd, size, buf, count); \
+ } \
+ void bus_space_write_region_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, const uint##bits##_t *, bus_size_t);\
+ void kasan_bus_space_write_region_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, const uint##bits##_t *, bus_size_t);\
+ void kasan_bus_space_write_region_stream_##bytes(bus_space_tag_t tag, \
+ bus_space_handle_t hnd, bus_size_t size, const uint##bits##_t *buf, \
+ bus_size_t count) \
+ { \
+ kasan_shadow_check((uintptr_t)buf, \
+ sizeof(uint##bits##_t) * count, true, __RET_ADDR); \
+ bus_space_write_region_stream_##bytes(tag, hnd, size, buf, count);\
+ }
+
+ASAN_BUS_READ_FUNC(1, 8)
+ASAN_BUS_READ_FUNC(2, 16)
+ASAN_BUS_READ_FUNC(4, 32)
+ASAN_BUS_READ_FUNC(8, 64)
+
+ASAN_BUS_WRITE_FUNC(1, 8)
+ASAN_BUS_WRITE_FUNC(2, 16)
+ASAN_BUS_WRITE_FUNC(4, 32)
+ASAN_BUS_WRITE_FUNC(8, 64)
+
+/* -------------------------------------------------------------------------- */
+
void __asan_register_globals(struct __asan_global *, size_t);
void __asan_unregister_globals(struct __asan_global *, size_t);
diff -r b2313659e968 -r 5142f06bfa0d sys/sys/bus_proto.h
--- a/sys/sys/bus_proto.h Sat Sep 07 09:57:37 2019 +0000
+++ b/sys/sys/bus_proto.h Sat Sep 07 10:24:01 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_proto.h,v 1.7 2013/02/04 13:18:35 macallan Exp $ */
+/* $NetBSD: bus_proto.h,v 1.8 2019/09/07 10:24:01 maxv Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2001, 2007 The NetBSD Foundation, Inc.
@@ -64,6 +64,10 @@
#ifndef _SYS_BUS_PROTO_H_
#define _SYS_BUS_PROTO_H_
+#ifdef _KERNEL_OPT
+#include "opt_kasan.h"
+#endif
+
/*
* Forwards needed by prototypes below.
*/
@@ -128,41 +132,48 @@
uint64_t bus_space_read_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
-void bus_space_read_multi_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint8_t *, bus_size_t);
-void bus_space_read_multi_stream_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint8_t *, bus_size_t);
-void bus_space_read_region_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint8_t *, bus_size_t);
-void bus_space_read_region_stream_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint8_t *, bus_size_t);
-
-void bus_space_read_multi_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint16_t *, bus_size_t);
-void bus_space_read_multi_stream_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint16_t *, bus_size_t);
-void bus_space_read_region_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint16_t *, bus_size_t);
-void bus_space_read_region_stream_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint16_t *, bus_size_t);
+#ifdef KASAN
+#define BUS_SPACE_READ_MEM_PROTOS(bytes, bits) \
+void kasan_bus_space_read_multi_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, uint##bits##_t *, bus_size_t); \
+void kasan_bus_space_read_multi_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+void kasan_bus_space_read_region_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, uint##bits##_t *, bus_size_t); \
+void kasan_bus_space_read_region_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t);
+#define bus_space_read_multi_1 kasan_bus_space_read_multi_1
+#define bus_space_read_multi_2 kasan_bus_space_read_multi_2
+#define bus_space_read_multi_4 kasan_bus_space_read_multi_4
+#define bus_space_read_multi_8 kasan_bus_space_read_multi_8
+#define bus_space_read_multi_stream_1 kasan_bus_space_read_multi_stream_1
+#define bus_space_read_multi_stream_2 kasan_bus_space_read_multi_stream_2
+#define bus_space_read_multi_stream_4 kasan_bus_space_read_multi_stream_4
+#define bus_space_read_multi_stream_8 kasan_bus_space_read_multi_stream_8
+#define bus_space_read_region_1 kasan_bus_space_read_region_1
+#define bus_space_read_region_2 kasan_bus_space_read_region_2
+#define bus_space_read_region_4 kasan_bus_space_read_region_4
+#define bus_space_read_region_8 kasan_bus_space_read_region_8
+#define bus_space_read_region_stream_1 kasan_bus_space_read_region_stream_1
+#define bus_space_read_region_stream_2 kasan_bus_space_read_region_stream_2
+#define bus_space_read_region_stream_4 kasan_bus_space_read_region_stream_4
+#define bus_space_read_region_stream_8 kasan_bus_space_read_region_stream_8
+#else
+#define BUS_SPACE_READ_MEM_PROTOS(bytes, bits) \
+void bus_space_read_multi_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, uint##bits##_t *, bus_size_t); \
+void bus_space_read_multi_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t); \
+void bus_space_read_region_##bytes(bus_space_tag_t, bus_space_handle_t, \
+ bus_size_t, uint##bits##_t *, bus_size_t); \
+void bus_space_read_region_stream_##bytes(bus_space_tag_t, \
+ bus_space_handle_t, bus_size_t, uint##bits##_t *, bus_size_t);
+#endif
-void bus_space_read_multi_4(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint32_t *, bus_size_t);
-void bus_space_read_multi_stream_4(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint32_t *, bus_size_t);
-void bus_space_read_region_4(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint32_t *, bus_size_t);
-void bus_space_read_region_stream_4(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint32_t *, bus_size_t);
-
-void bus_space_read_multi_8(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint64_t *, bus_size_t);
-void bus_space_read_multi_stream_8(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint64_t *, bus_size_t);
-void bus_space_read_region_8(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint64_t *, bus_size_t);
-void bus_space_read_region_stream_8(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, uint64_t *, bus_size_t);
+BUS_SPACE_READ_MEM_PROTOS(1, 8)
+BUS_SPACE_READ_MEM_PROTOS(2, 16)
+BUS_SPACE_READ_MEM_PROTOS(4, 32)
+BUS_SPACE_READ_MEM_PROTOS(8, 64)
void bus_space_write_1(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint8_t);
@@ -184,57 +195,48 @@
void bus_space_write_stream_8(bus_space_tag_t, bus_space_handle_t,
bus_size_t, uint64_t);
-void bus_space_write_multi_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint8_t *,
- bus_size_t);
-void bus_space_write_multi_stream_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint8_t *,
- bus_size_t);
-void bus_space_write_region_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint8_t *,
- bus_size_t);
-void bus_space_write_region_stream_1(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint8_t *,
- bus_size_t);
-
-void bus_space_write_multi_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint16_t *,
- bus_size_t);
-void bus_space_write_multi_stream_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint16_t *,
- bus_size_t);
-void bus_space_write_region_2(bus_space_tag_t, bus_space_handle_t,
- bus_size_t, const uint16_t *,
Home |
Main Index |
Thread Index |
Old Index