[compiler-rt] r348370 - Add a new interceptor for modctl(2) from NetBSD
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 5 07:13:21 PST 2018
Author: kamil
Date: Wed Dec 5 07:13:20 2018
New Revision: 348370
URL: http://llvm.org/viewvc/llvm-project?rev=348370&view=rev
Log:
Add a new interceptor for modctl(2) from NetBSD
Summary:
modctl - controls loadable kernel modules.
Skip tests as this call uses privileged operations.
Reviewers: vitalybuka, joerg
Reviewed By: vitalybuka
Subscribers: kubamracek, llvm-commits, mgorny, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D55025
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=348370&r1=348369&r2=348370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Dec 5 07:13:20 2018
@@ -7678,6 +7678,52 @@ INTERCEPTOR(char *, nl_langinfo, long it
#define INIT_NL_LANGINFO
#endif
+#if SANITIZER_INTERCEPT_MODCTL
+INTERCEPTOR(int, modctl, int operation, void *argp) {
+ void *ctx;
+ int ret;
+ COMMON_INTERCEPTOR_ENTER(ctx, modctl, operation, argp);
+
+ if (operation == modctl_load) {
+ if (argp) {
+ __sanitizer_modctl_load_t *ml = (__sanitizer_modctl_load_t *)argp;
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, ml, sizeof(*ml));
+ if (ml->ml_filename)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, ml->ml_filename,
+ REAL(strlen)(ml->ml_filename) + 1);
+ if (ml->ml_props)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, ml->ml_props, ml->ml_propslen);
+ }
+ ret = REAL(modctl)(operation, argp);
+ } else if (operation == modctl_unload) {
+ if (argp) {
+ const char *name = (const char *)argp;
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1);
+ }
+ ret = REAL(modctl)(operation, argp);
+ } else if (operation == modctl_stat) {
+ uptr iov_len;
+ struct __sanitizer_iovec *iov = (struct __sanitizer_iovec *)argp;
+ if (iov) {
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, iov, sizeof(*iov));
+ iov_len = iov->iov_len;
+ }
+ ret = REAL(modctl)(operation, argp);
+ if (iov)
+ COMMON_INTERCEPTOR_WRITE_RANGE(
+ ctx, iov->iov_base, Min(iov_len, iov->iov_len));
+ } else if (operation == modctl_exists)
+ ret = REAL(modctl)(operation, argp);
+ else
+ ret = REAL(modctl)(operation, argp);
+
+ return ret;
+}
+#define INIT_MODCTL COMMON_INTERCEPT_FUNCTION(modctl)
+#else
+#define INIT_MODCTL
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7941,6 +7987,7 @@ static void InitializeCommonInterceptors
INIT_ASYSCTL;
INIT_SYSCTLGETMIBINFO;
INIT_NL_LANGINFO;
+ INIT_MODCTL;
INIT___PRINTF_CHK;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=348370&r1=348369&r2=348370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Dec 5 07:13:20 2018
@@ -520,12 +520,13 @@
SI_LINUX || SI_MAC)
#define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD
#define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
-#define SANITIZER_INTERCEPT_NL_LANGINFO SI_NETBSD
#define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
#define SANITIZER_INTERCEPT_REGEX SI_NETBSD
#define SANITIZER_INTERCEPT_FTS SI_NETBSD
#define SANITIZER_INTERCEPT_SYSCTL (SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_ASYSCTL SI_NETBSD
#define SANITIZER_INTERCEPT_SYSCTLGETMIBINFO SI_NETBSD
+#define SANITIZER_INTERCEPT_NL_LANGINFO SI_NETBSD
+#define SANITIZER_INTERCEPT_MODCTL SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc?rev=348370&r1=348369&r2=348370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc Wed Dec 5 07:13:20 2018
@@ -2096,6 +2096,11 @@ unsigned IOCTL_SNDCTL_DSP_SILENCE = SNDC
const int si_SEGV_MAPERR = SEGV_MAPERR;
const int si_SEGV_ACCERR = SEGV_ACCERR;
+
+const int modctl_load = MODCTL_LOAD;
+const int modctl_unload = MODCTL_UNLOAD;
+const int modctl_stat = MODCTL_STAT;
+const int modctl_exists = MODCTL_EXISTS;
} // namespace __sanitizer
using namespace __sanitizer;
@@ -2257,4 +2262,10 @@ CHECK_SIZE_AND_OFFSET(group, gr_passwd);
CHECK_SIZE_AND_OFFSET(group, gr_gid);
CHECK_SIZE_AND_OFFSET(group, gr_mem);
+CHECK_TYPE_SIZE(modctl_load_t);
+CHECK_SIZE_AND_OFFSET(modctl_load_t, ml_filename);
+CHECK_SIZE_AND_OFFSET(modctl_load_t, ml_flags);
+CHECK_SIZE_AND_OFFSET(modctl_load_t, ml_props);
+CHECK_SIZE_AND_OFFSET(modctl_load_t, ml_propslen);
+
#endif // SANITIZER_NETBSD
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h?rev=348370&r1=348369&r2=348370&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h Wed Dec 5 07:13:20 2018
@@ -71,6 +71,17 @@ struct __sanitizer_regmatch {
OFF_T rm_eo;
};
+typedef struct __sanitizer_modctl_load {
+ const char *ml_filename;
+ int ml_flags;
+ const char *ml_props;
+ uptr ml_propslen;
+} __sanitizer_modctl_load_t;
+extern const int modctl_load;
+extern const int modctl_unload;
+extern const int modctl_stat;
+extern const int modctl_exists;
+
union __sanitizer_sigval {
int sival_int;
uptr sival_ptr;
More information about the llvm-commits
mailing list