summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2019-10-08 00:00:30 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2019-10-08 00:00:30 +0000
commit12a9be541d8e64026106c6f453702c779c7f1e97 (patch)
tree15f6abc26b55cb037f3c3036a65e76af16a180cb
parent8ea8db5364fa341ce6dc7538be9311a725321848 (diff)
downloadcompiler-rt-12a9be541d8e64026106c6f453702c779c7f1e97.tar.gz
[msan] Add interceptors: crypt, crypt_r.
Reviewers: vitalybuka Subscribers: srhines, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D68431 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@373993 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/sanitizer_common/sanitizer_common_interceptors.inc37
-rw-r--r--lib/sanitizer_common/sanitizer_platform_interceptors.h2
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_posix.cpp2
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_posix.h1
-rw-r--r--test/sanitizer_common/TestCases/Linux/crypt_r.cpp37
-rw-r--r--test/sanitizer_common/TestCases/Posix/crypt.cpp26
6 files changed, 105 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 587b1ea22..7cae94559 100644
--- a/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9573,6 +9573,41 @@ INTERCEPTOR(SSIZE_T, getrandom, void *buf, SIZE_T buflen, unsigned int flags) {
#define INIT_GETRANDOM
#endif
+#if SANITIZER_INTERCEPT_CRYPT
+INTERCEPTOR(char *, crypt, char *key, char *salt) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, crypt, key, salt);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, key, internal_strlen(key) + 1);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, salt, internal_strlen(salt) + 1);
+ char *res = REAL(crypt)(key, salt);
+ if (res != nullptr)
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, internal_strlen(res) + 1);
+ return res;
+}
+#define INIT_CRYPT COMMON_INTERCEPT_FUNCTION(crypt);
+#else
+#define INIT_CRYPT
+#endif
+
+#if SANITIZER_INTERCEPT_CRYPT_R
+INTERCEPTOR(char *, crypt_r, char *key, char *salt, void *data) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, crypt_r, key, salt, data);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, key, internal_strlen(key) + 1);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, salt, internal_strlen(salt) + 1);
+ char *res = REAL(crypt_r)(key, salt, data);
+ if (res != nullptr) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, data,
+ __sanitizer::struct_crypt_data_sz);
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, internal_strlen(res) + 1);
+ }
+ return res;
+}
+#define INIT_CRYPT_R COMMON_INTERCEPT_FUNCTION(crypt_r);
+#else
+#define INIT_CRYPT_R
+#endif
+
static void InitializeCommonInterceptors() {
#if SI_POSIX
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
@@ -9871,6 +9906,8 @@ static void InitializeCommonInterceptors() {
INIT_GETUSERSHELL;
INIT_SL_INIT;
INIT_GETRANDOM;
+ INIT_CRYPT;
+ INIT_CRYPT_R;
INIT___PRINTF_CHK;
}
diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 36885da98..54a1699f5 100644
--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -566,6 +566,8 @@
#define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD
#define SANITIZER_INTERCEPT_GETUSERSHELL (SI_POSIX && !SI_ANDROID)
#define SANITIZER_INTERCEPT_SL_INIT (SI_FREEBSD || SI_NETBSD)
+#define SANITIZER_INTERCEPT_CRYPT (SI_POSIX && !SI_ANDROID)
+#define SANITIZER_INTERCEPT_CRYPT_R (SI_LINUX && !SI_ANDROID)
#define SANITIZER_INTERCEPT_GETRANDOM (SI_LINUX && __GLIBC_PREREQ(2, 25))
#define SANITIZER_INTERCEPT___CXA_ATEXIT SI_NETBSD
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index f50f31dcd..84058c708 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -140,6 +140,7 @@ typedef struct user_fpregs elf_fpregset_t;
#include <linux/serial.h>
#include <sys/msg.h>
#include <sys/ipc.h>
+#include <crypt.h>
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
#if SANITIZER_ANDROID
@@ -240,6 +241,7 @@ namespace __sanitizer {
unsigned struct_ustat_sz = SIZEOF_STRUCT_USTAT;
unsigned struct_rlimit64_sz = sizeof(struct rlimit64);
unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
+ unsigned struct_crypt_data_sz = sizeof(struct crypt_data);
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
#if SANITIZER_LINUX && !SANITIZER_ANDROID
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index b92fef395..db2c4f07b 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -304,6 +304,7 @@ extern unsigned struct_msqid_ds_sz;
extern unsigned struct_mq_attr_sz;
extern unsigned struct_timex_sz;
extern unsigned struct_statvfs_sz;
+extern unsigned struct_crypt_data_sz;
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
struct __sanitizer_iovec {
diff --git a/test/sanitizer_common/TestCases/Linux/crypt_r.cpp b/test/sanitizer_common/TestCases/Linux/crypt_r.cpp
new file mode 100644
index 000000000..b90b13b45
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Linux/crypt_r.cpp
@@ -0,0 +1,37 @@
+// RUN: %clangxx -O0 -g %s -lcrypt -o %t && %run %t
+
+#include <assert.h>
+#include <unistd.h>
+#include <cstring>
+#include <crypt.h>
+
+#include <sanitizer/msan_interface.h>
+
+int
+main (int argc, char** argv)
+{
+ {
+ crypt_data cd;
+ cd.initialized = 0;
+ char *p = crypt_r("abcdef", "xz", &cd);
+ volatile size_t z = strlen(p);
+ }
+ {
+ crypt_data cd;
+ cd.initialized = 0;
+ char *p = crypt_r("abcdef", "$1$", &cd);
+ volatile size_t z = strlen(p);
+ }
+ {
+ crypt_data cd;
+ cd.initialized = 0;
+ char *p = crypt_r("abcdef", "$5$", &cd);
+ volatile size_t z = strlen(p);
+ }
+ {
+ crypt_data cd;
+ cd.initialized = 0;
+ char *p = crypt_r("abcdef", "$6$", &cd);
+ volatile size_t z = strlen(p);
+ }
+}
diff --git a/test/sanitizer_common/TestCases/Posix/crypt.cpp b/test/sanitizer_common/TestCases/Posix/crypt.cpp
new file mode 100644
index 000000000..7b36741b6
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/crypt.cpp
@@ -0,0 +1,26 @@
+// RUN: %clangxx -O0 -g %s -o %t -lcrypt && %run %t
+
+#include <assert.h>
+#include <unistd.h>
+#include <cstring>
+
+int
+main (int argc, char** argv)
+{
+ {
+ char *p = crypt("abcdef", "xz");
+ volatile size_t z = strlen(p);
+ }
+ {
+ char *p = crypt("abcdef", "$1$");
+ volatile size_t z = strlen(p);
+ }
+ {
+ char *p = crypt("abcdef", "$5$");
+ volatile size_t z = strlen(p);
+ }
+ {
+ char *p = crypt("abcdef", "$6$");
+ volatile size_t z = strlen(p);
+ }
+}