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 strcat/strchr/strrchr.
details: https://anonhg.NetBSD.org/src/rev/0fc7fd3c19d4
branches: trunk
changeset: 1008797:0fc7fd3c19d4
user: maxv <maxv%NetBSD.org@localhost>
date: Fri Apr 03 18:44:50 2020 +0000
description:
Add KASAN instrumentation on strcat/strchr/strrchr.
diffstat:
sys/kern/subr_asan.c | 35 +++++++++++++++++++++++++++++++++--
sys/lib/libkern/libkern.h | 11 +++++++++--
2 files changed, 42 insertions(+), 4 deletions(-)
diffs (81 lines):
diff -r 7331dd69bbe0 -r 0fc7fd3c19d4 sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c Fri Apr 03 18:39:15 2020 +0000
+++ b/sys/kern/subr_asan.c Fri Apr 03 18:44:50 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_asan.c,v 1.19 2020/04/03 18:12:39 maxv Exp $ */
+/* $NetBSD: subr_asan.c,v 1.20 2020/04/03 18:44:50 maxv Exp $ */
/*
* Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.19 2020/04/03 18:12:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.20 2020/04/03 18:44:50 maxv Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -507,6 +507,37 @@
return (s - str);
}
+char *
+kasan_strcat(char *dst, const char *src)
+{
+ size_t ldst, lsrc;
+
+ ldst = __builtin_strlen(dst);
+ lsrc = __builtin_strlen(src);
+ kasan_shadow_check((unsigned long)dst, ldst + lsrc + 1, true,
+ __RET_ADDR);
+ kasan_shadow_check((unsigned long)src, lsrc + 1, false,
+ __RET_ADDR);
+
+ return __builtin_strcat(dst, src);
+}
+
+char *
+kasan_strchr(const char *s, int c)
+{
+ kasan_shadow_check((unsigned long)s, __builtin_strlen(s) + 1, false,
+ __RET_ADDR);
+ return __builtin_strchr(s, c);
+}
+
+char *
+kasan_strrchr(const char *s, int c)
+{
+ kasan_shadow_check((unsigned long)s, __builtin_strlen(s) + 1, false,
+ __RET_ADDR);
+ return __builtin_strrchr(s, c);
+}
+
#undef kcopy
#undef copystr
#undef copyinstr
diff -r 7331dd69bbe0 -r 0fc7fd3c19d4 sys/lib/libkern/libkern.h
--- a/sys/lib/libkern/libkern.h Fri Apr 03 18:39:15 2020 +0000
+++ b/sys/lib/libkern/libkern.h Fri Apr 03 18:44:50 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: libkern.h,v 1.137 2019/12/14 17:23:47 riastradh Exp $ */
+/* $NetBSD: libkern.h,v 1.138 2020/04/03 18:44:50 maxv Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -430,7 +430,14 @@
#endif
/* These exist in GCC 3.x, but we don't bother. */
-#if defined(_KERNEL) && defined(KMSAN)
+#if defined(_KERNEL) && defined(KASAN)
+char *kasan_strcat(char *, const char *);
+char *kasan_strchr(const char *, int);
+char *kasan_strrchr(const char *, int);
+#define strcat(d, s) kasan_strcat(d, s)
+#define strchr(s, c) kasan_strchr(s, c)
+#define strrchr(s, c) kasan_strrchr(s, c)
+#elif defined(_KERNEL) && defined(KMSAN)
char *kmsan_strcat(char *, const char *);
char *kmsan_strchr(const char *, int);
char *kmsan_strrchr(const char *, int);
Home |
Main Index |
Thread Index |
Old Index