[compiler-rt] r373993 - [msan] Add interceptors: crypt, crypt_r.

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 13:48:35 PDT 2019


r374115

On Tue, Oct 8, 2019 at 12:29 PM Azhar Mohammed via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> This is failing on Darwin, can you please take a look.
> http://green.lab.llvm.org/green/job/clang-stage1-RA/2649/consoleFull
>
>
> ******************** TEST 'SanitizerCommon-asan-x86_64-Darwin ::
> Posix/crypt.cpp' FAILED ******************** Script: -- : 'RUN: at line
> 1';
> /Users/buildslave/jenkins/workspace/clang-stage1-RA/clang-build/./bin/clang
> --driver-mode=g++ -gline-tables-only -fsanitize=address -arch x86_64
> -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
> -O0 -g
> /Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp
> -o
> /Users/buildslave/jenkins/workspace/clang-stage1-RA/clang-build/tools/clang/runtime/compiler-rt-bins/test/sanitizer_common/asan-x86_64-Darwin/Posix/Output/crypt.cpp.tmp
> -lcrypt &&
> /Users/buildslave/jenkins/workspace/clang-stage1-RA/clang-build/tools/clang/runtime/compiler-rt-bins/test/sanitizer_common/asan-x86_64-Darwin/Posix/Output/crypt.cpp.tmp
> -- Exit Code: 1
>
> Command Output (stderr): -- ld: library not found for -lcrypt clang-10:
> error: linker command failed with exit code 1 (use -v to see invocation)
>
>
>
> On Oct 7, 2019, at 5:00 PM, Evgeniy Stepanov via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
> Author: eugenis
> Date: Mon Oct  7 17:00:30 2019
> New Revision: 373993
>
> URL: http://llvm.org/viewvc/llvm-project?rev=373993&view=rev
> Log:
> [msan] Add interceptors: crypt, crypt_r.
>
> Reviewers: vitalybuka
>
> Subscribers: srhines, #sanitizers, llvm-commits
>
> Tags: #sanitizers, #llvm
>
> Differential Revision: https://reviews.llvm.org/D68431
>
> Added:
>    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/crypt_r.cpp
>    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/crypt.cpp
> 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_posix.cpp
>    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.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=373993&r1=373992&r2=373993&view=diff
>
> ==============================================================================
> ---
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
> (original)
> +++
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
> Mon Oct  7 17:00:30 2019
> @@ -9573,6 +9573,41 @@ INTERCEPTOR(SSIZE_T, getrandom, void *bu
> #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;
> }
>
> 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=373993&r1=373992&r2=373993&view=diff
>
> ==============================================================================
> ---
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
> (original)
> +++
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
> Mon Oct  7 17:00:30 2019
> @@ -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
>
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp?rev=373993&r1=373992&r2=373993&view=diff
>
> ==============================================================================
> ---
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
> (original)
> +++
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
> Mon Oct  7 17:00:30 2019
> @@ -140,6 +140,7 @@ typedef struct user_fpregs elf_fpregset_
> #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
>
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=373993&r1=373992&r2=373993&view=diff
>
> ==============================================================================
> ---
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
> (original)
> +++
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
> Mon Oct  7 17:00:30 2019
> @@ -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 {
>
> Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/crypt_r.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/crypt_r.cpp?rev=373993&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/crypt_r.cpp
> (added)
> +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/crypt_r.cpp
> Mon Oct  7 17:00:30 2019
> @@ -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);
> +  }
> +}
>
> Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/crypt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/crypt.cpp?rev=373993&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/crypt.cpp
> (added)
> +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/crypt.cpp Mon
> Oct  7 17:00:30 2019
> @@ -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);
> +  }
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191008/114255ec/attachment.html>


More information about the llvm-commits mailing list