diff options
author | Josselin Poiret <dev@jpoiret.xyz> | 2024-03-08 13:02:49 +0100 |
---|---|---|
committer | Josselin Poiret <dev@jpoiret.xyz> | 2024-03-09 17:37:08 +0100 |
commit | b2a79566af11ec8b13e790a57d977a6588e827dc (patch) | |
tree | 56dbc8efc0e4878ce5940e74d6d8ff83d0443687 | |
parent | 5d7d01e8daddd6ebb7fccca85aa81f8b2cf1a049 (diff) |
gnu: clang: Fix build with libcrypt-less glibc.
* gnu/packages/patches/clang-13-remove-crypt-interceptors.patch
* gnu/packages/patches/clang-14-remove-crypt-interceptors.patch
* gnu/packages/patches/clang-16-remove-crypt-interceptors.patch: New patches.
* gnu/local.mk (dist_patch_DATA): Register them.
* gnu/packages/llvm.scm (%llvm-patches, clang-runtime-13): Use them.
Change-Id: Idcc82313f1a39710aa91fb577144321372a3af47
-rw-r--r-- | gnu/local.mk | 3 | ||||
-rw-r--r-- | gnu/packages/llvm.scm | 12 | ||||
-rw-r--r-- | gnu/packages/patches/clang-13-remove-crypt-interceptors.patch | 214 | ||||
-rw-r--r-- | gnu/packages/patches/clang-14-remove-crypt-interceptors.patch | 214 | ||||
-rw-r--r-- | gnu/packages/patches/clang-16-remove-crypt-interceptors.patch | 222 |
5 files changed, 661 insertions, 4 deletions
diff --git a/gnu/local.mk b/gnu/local.mk index dd96b58ecb..b3d0422215 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1036,9 +1036,12 @@ dist_patch_DATA = \ %D%/packages/patches/clang-11.0-libc-search-path.patch \ %D%/packages/patches/clang-12.0-libc-search-path.patch \ %D%/packages/patches/clang-13.0-libc-search-path.patch \ + %D%/packages/patches/clang-13-remove-crypt-interceptors.patch \ %D%/packages/patches/clang-14.0-libc-search-path.patch \ + %D%/packages/patches/clang-14-remove-crypt-interceptors.patch \ %D%/packages/patches/clang-15.0-libc-search-path.patch \ %D%/packages/patches/clang-16.0-libc-search-path.patch \ + %D%/packages/patches/clang-16-remove-crypt-interceptors.patch \ %D%/packages/patches/clang-17.0-libc-search-path.patch \ %D%/packages/patches/clang-runtime-asan-build-fixes.patch \ %D%/packages/patches/clang-runtime-esan-build-fixes.patch \ diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm index a085aa5677..59d096cb1a 100644 --- a/gnu/packages/llvm.scm +++ b/gnu/packages/llvm.scm @@ -598,9 +598,12 @@ output), and Binutils.") (define %llvm-patches '(("14.0.6" . ("clang-14.0-libc-search-path.patch" - "clang-runtime-14-glibc-2.36-compat.patch")) - ("15.0.7" . ("clang-15.0-libc-search-path.patch")) - ("16.0.6" . ("clang-16.0-libc-search-path.patch")) + "clang-runtime-14-glibc-2.36-compat.patch" + "clang-14-remove-crypt-interceptors.patch")) + ("15.0.7" . ("clang-15.0-libc-search-path.patch" + "clang-16-remove-crypt-interceptors.patch")) + ("16.0.6" . ("clang-16.0-libc-search-path.patch" + "clang-16-remove-crypt-interceptors.patch")) ("17.0.6" . ("clang-17.0-libc-search-path.patch")))) (define (llvm-monorepo version) @@ -848,7 +851,8 @@ Library.") (clang-runtime-from-llvm llvm-13 "1z2xr9nn4mgc3hn9ark2k5y4wznpk47xppkp63bcbagr6589acvv" - '("clang-runtime-13-glibc-2.36-compat.patch"))) + '("clang-runtime-13-glibc-2.36-compat.patch" + "clang-13-remove-crypt-interceptors.patch"))) (define-public clang-13 (clang-from-llvm llvm-13 clang-runtime-13 diff --git a/gnu/packages/patches/clang-13-remove-crypt-interceptors.patch b/gnu/packages/patches/clang-13-remove-crypt-interceptors.patch new file mode 100644 index 0000000000..578f246c39 --- /dev/null +++ b/gnu/packages/patches/clang-13-remove-crypt-interceptors.patch @@ -0,0 +1,214 @@ +From d7bead833631486e337e541e692d9b4a1ca14edd Mon Sep 17 00:00:00 2001 +From: Fangrui Song <i@maskray.me> +Date: Fri, 28 Apr 2023 09:59:17 -0700 +Subject: [PATCH] [sanitizer] Remove crypt and crypt_r interceptors + +From Florian Weimer's D144073 + +> On GNU/Linux (glibc), the crypt and crypt_r functions are not part of the main shared object (libc.so.6), but libcrypt (with multiple possible sonames). The sanitizer libraries do not depend on libcrypt, so it can happen that during sanitizer library initialization, no real implementation will be found because the crypt, crypt_r functions are not present in the process image (yet). If its interceptors are called nevertheless, this results in a call through a null pointer when the sanitizer library attempts to forward the call to the real implementation. +> +> Many distributions have already switched to libxcrypt, a library that is separate from glibc and that can be build with sanitizers directly (avoiding the need for interceptors). This patch disables building the interceptor for glibc targets. + +Let's remove crypt and crypt_r interceptors (D68431) to fix issues with +newer glibc. + +For older glibc, msan will not know that an uninstrumented crypt_r call +initializes `data`, so there is a risk for false positives. However, with some +codebase survey, I think crypt_r uses are very few and the call sites typically +have a `memset(&data, 0, sizeof(data));` anyway. + +Fix https://github.com/google/sanitizers/issues/1365 +Related: https://bugzilla.redhat.com/show_bug.cgi?id=2169432 + +Reviewed By: #sanitizers, fweimer, thesamesam, vitalybuka + +Differential Revision: https://reviews.llvm.org/D149403 +--- + .../sanitizer_common_interceptors.inc | 37 ------------------- + .../sanitizer_platform_interceptors.h | 2 - + .../sanitizer_platform_limits_posix.cpp | 8 ---- + .../sanitizer_platform_limits_posix.h | 1 - + .../TestCases/Linux/crypt_r.cpp | 36 ------------------ + .../TestCases/Posix/crypt.cpp | 32 ---------------- + 6 files changed, 116 deletions(-) + delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp + delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp + +diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc +index b30c91f06cfeb0..490a8b12d8b17d 100644 +--- a/lib/sanitizer_common/sanitizer_common_interceptors.inc ++++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc +@@ -10086,41 +10086,6 @@ 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 +- + #if SANITIZER_INTERCEPT_GETENTROPY + INTERCEPTOR(int, getentropy, void *buf, SIZE_T buflen) { + void *ctx; +@@ -10698,8 +10663,6 @@ static void InitializeCommonInterceptors() { + INIT_GETUSERSHELL; + INIT_SL_INIT; + INIT_GETRANDOM; +- INIT_CRYPT; +- INIT_CRYPT_R; + INIT_GETENTROPY; + INIT_QSORT; + INIT_QSORT_R; +diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h +index eb39fabfd59839..c82ab5c2105621 100644 +--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h ++++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h +@@ -569,8 +569,6 @@ + #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)) || SI_FREEBSD) +diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +index a04eed7aa5a6e..6d61d276d77e3 100644 +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +@@ -142,5 +142,4 @@ + #include <linux/serial.h> + #include <sys/msg.h> + #include <sys/ipc.h> +-#include <crypt.h> + #endif // SANITIZER_ANDROID +@@ -243,7 +244,6 @@ + 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 e6f298c26e1fb6..58244c9944a03a 100644 +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h +@@ -309,7 +309,6 @@ 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 +deleted file mode 100644 +index 69bfb46aa5f171..00000000000000 +--- a/test/sanitizer_common/TestCases/Linux/crypt_r.cpp ++++ /dev/null +@@ -1,36 +0,0 @@ +-// RUN: %clangxx -O0 -g %s -lcrypt -o %t && %run %t +- +-// crypt.h is missing from Android. +-// UNSUPPORTED: android +- +-#include <assert.h> +-#include <unistd.h> +-#include <cstring> +-#include <crypt.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 +deleted file mode 100644 +index 3a8faaa1ae7682..00000000000000 +--- a/test/sanitizer_common/TestCases/Posix/crypt.cpp ++++ /dev/null +@@ -1,32 +0,0 @@ +-// RUN: %clangxx -O0 -g %s -o %t -lcrypt && %run %t +- +-// crypt() is missing from Android and -lcrypt from darwin. +-// UNSUPPORTED: android, darwin +- +-#include <assert.h> +-#include <unistd.h> +-#include <cstring> +-#if __has_include(<crypt.h>) +-#include <crypt.h> +-#endif +- +-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); +- } +-} diff --git a/gnu/packages/patches/clang-14-remove-crypt-interceptors.patch b/gnu/packages/patches/clang-14-remove-crypt-interceptors.patch new file mode 100644 index 0000000000..1043240fe2 --- /dev/null +++ b/gnu/packages/patches/clang-14-remove-crypt-interceptors.patch @@ -0,0 +1,214 @@ +From d7bead833631486e337e541e692d9b4a1ca14edd Mon Sep 17 00:00:00 2001 +From: Fangrui Song <i@maskray.me> +Date: Fri, 28 Apr 2023 09:59:17 -0700 +Subject: [PATCH] [sanitizer] Remove crypt and crypt_r interceptors + +From Florian Weimer's D144073 + +> On GNU/Linux (glibc), the crypt and crypt_r functions are not part of the main shared object (libc.so.6), but libcrypt (with multiple possible sonames). The sanitizer libraries do not depend on libcrypt, so it can happen that during sanitizer library initialization, no real implementation will be found because the crypt, crypt_r functions are not present in the process image (yet). If its interceptors are called nevertheless, this results in a call through a null pointer when the sanitizer library attempts to forward the call to the real implementation. +> +> Many distributions have already switched to libxcrypt, a library that is separate from glibc and that can be build with sanitizers directly (avoiding the need for interceptors). This patch disables building the interceptor for glibc targets. + +Let's remove crypt and crypt_r interceptors (D68431) to fix issues with +newer glibc. + +For older glibc, msan will not know that an uninstrumented crypt_r call +initializes `data`, so there is a risk for false positives. However, with some +codebase survey, I think crypt_r uses are very few and the call sites typically +have a `memset(&data, 0, sizeof(data));` anyway. + +Fix https://github.com/google/sanitizers/issues/1365 +Related: https://bugzilla.redhat.com/show_bug.cgi?id=2169432 + +Reviewed By: #sanitizers, fweimer, thesamesam, vitalybuka + +Differential Revision: https://reviews.llvm.org/D149403 +--- + .../sanitizer_common_interceptors.inc | 37 ------------------- + .../sanitizer_platform_interceptors.h | 2 - + .../sanitizer_platform_limits_posix.cpp | 8 ---- + .../sanitizer_platform_limits_posix.h | 1 - + .../TestCases/Linux/crypt_r.cpp | 36 ------------------ + .../TestCases/Posix/crypt.cpp | 32 ---------------- + 6 files changed, 116 deletions(-) + delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp + delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp + +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +index b30c91f06cfeb0..490a8b12d8b17d 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +@@ -10086,41 +10086,6 @@ 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 +- + #if SANITIZER_INTERCEPT_GETENTROPY + INTERCEPTOR(int, getentropy, void *buf, SIZE_T buflen) { + void *ctx; +@@ -10698,8 +10663,6 @@ static void InitializeCommonInterceptors() { + INIT_GETUSERSHELL; + INIT_SL_INIT; + INIT_GETRANDOM; +- INIT_CRYPT; +- INIT_CRYPT_R; + INIT_GETENTROPY; + INIT_QSORT; + INIT_QSORT_R; +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +index eb39fabfd59839..c82ab5c2105621 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +@@ -569,8 +569,6 @@ + #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)) || SI_FREEBSD) +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +index a04eed7aa5a6e..6d61d276d77e3 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +@@ -142,5 +142,4 @@ + #include <linux/serial.h> + #include <sys/msg.h> + #include <sys/ipc.h> +-#include <crypt.h> + #endif // SANITIZER_ANDROID +@@ -243,7 +244,6 @@ + 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/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +index e6f298c26e1fb6..58244c9944a03a 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +@@ -309,7 +309,6 @@ 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/compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp +deleted file mode 100644 +index 69bfb46aa5f171..00000000000000 +--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp ++++ /dev/null +@@ -1,36 +0,0 @@ +-// RUN: %clangxx -O0 -g %s -lcrypt -o %t && %run %t +- +-// crypt.h is missing from Android. +-// UNSUPPORTED: android +- +-#include <assert.h> +-#include <unistd.h> +-#include <cstring> +-#include <crypt.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/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp +deleted file mode 100644 +index 3a8faaa1ae7682..00000000000000 +--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp ++++ /dev/null +@@ -1,32 +0,0 @@ +-// RUN: %clangxx -O0 -g %s -o %t -lcrypt && %run %t +- +-// crypt() is missing from Android and -lcrypt from darwin. +-// UNSUPPORTED: android, darwin +- +-#include <assert.h> +-#include <unistd.h> +-#include <cstring> +-#if __has_include(<crypt.h>) +-#include <crypt.h> +-#endif +- +-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); +- } +-} diff --git a/gnu/packages/patches/clang-16-remove-crypt-interceptors.patch b/gnu/packages/patches/clang-16-remove-crypt-interceptors.patch new file mode 100644 index 0000000000..bd0717b5fb --- /dev/null +++ b/gnu/packages/patches/clang-16-remove-crypt-interceptors.patch @@ -0,0 +1,222 @@ +From d7bead833631486e337e541e692d9b4a1ca14edd Mon Sep 17 00:00:00 2001 +From: Fangrui Song <i@maskray.me> +Date: Fri, 28 Apr 2023 09:59:17 -0700 +Subject: [PATCH] [sanitizer] Remove crypt and crypt_r interceptors + +From Florian Weimer's D144073 + +> On GNU/Linux (glibc), the crypt and crypt_r functions are not part of the main shared object (libc.so.6), but libcrypt (with multiple possible sonames). The sanitizer libraries do not depend on libcrypt, so it can happen that during sanitizer library initialization, no real implementation will be found because the crypt, crypt_r functions are not present in the process image (yet). If its interceptors are called nevertheless, this results in a call through a null pointer when the sanitizer library attempts to forward the call to the real implementation. +> +> Many distributions have already switched to libxcrypt, a library that is separate from glibc and that can be build with sanitizers directly (avoiding the need for interceptors). This patch disables building the interceptor for glibc targets. + +Let's remove crypt and crypt_r interceptors (D68431) to fix issues with +newer glibc. + +For older glibc, msan will not know that an uninstrumented crypt_r call +initializes `data`, so there is a risk for false positives. However, with some +codebase survey, I think crypt_r uses are very few and the call sites typically +have a `memset(&data, 0, sizeof(data));` anyway. + +Fix https://github.com/google/sanitizers/issues/1365 +Related: https://bugzilla.redhat.com/show_bug.cgi?id=2169432 + +Reviewed By: #sanitizers, fweimer, thesamesam, vitalybuka + +Differential Revision: https://reviews.llvm.org/D149403 +--- + .../sanitizer_common_interceptors.inc | 37 ------------------- + .../sanitizer_platform_interceptors.h | 2 - + .../sanitizer_platform_limits_posix.cpp | 8 ---- + .../sanitizer_platform_limits_posix.h | 1 - + .../TestCases/Linux/crypt_r.cpp | 36 ------------------ + .../TestCases/Posix/crypt.cpp | 32 ---------------- + 6 files changed, 116 deletions(-) + delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp + delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp + +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +index b30c91f06cfeb0..490a8b12d8b17d 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +@@ -10086,41 +10086,6 @@ 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 +- + #if SANITIZER_INTERCEPT_GETENTROPY + INTERCEPTOR(int, getentropy, void *buf, SIZE_T buflen) { + void *ctx; +@@ -10698,8 +10663,6 @@ static void InitializeCommonInterceptors() { + INIT_GETUSERSHELL; + INIT_SL_INIT; + INIT_GETRANDOM; +- INIT_CRYPT; +- INIT_CRYPT_R; + INIT_GETENTROPY; + INIT_QSORT; + INIT_QSORT_R; +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +index eb39fabfd59839..c82ab5c2105621 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +@@ -569,8 +569,6 @@ + #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)) || SI_FREEBSD) +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +index a04eed7aa5a6e3..6d61d276d77e35 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +@@ -177,10 +177,6 @@ typedef struct user_fpregs elf_fpregset_t; + # include "sanitizer_platform_interceptors.h" + # include "sanitizer_platform_limits_posix.h" + +-#if SANITIZER_INTERCEPT_CRYPT_R +-#include <crypt.h> +-#endif +- + namespace __sanitizer { + unsigned struct_utsname_sz = sizeof(struct utsname); + unsigned struct_stat_sz = sizeof(struct stat); +@@ -300,10 +296,6 @@ namespace __sanitizer { + unsigned struct_statvfs64_sz = sizeof(struct statvfs64); + #endif // SANITIZER_GLIBC + +-#if SANITIZER_INTERCEPT_CRYPT_R +- unsigned struct_crypt_data_sz = sizeof(struct crypt_data); +-#endif +- + #if SANITIZER_LINUX && !SANITIZER_ANDROID + unsigned struct_timex_sz = sizeof(struct timex); + unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds); +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +index e6f298c26e1fb6..58244c9944a03a 100644 +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +@@ -309,7 +309,6 @@ 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/compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp +deleted file mode 100644 +index 69bfb46aa5f171..00000000000000 +--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/crypt_r.cpp ++++ /dev/null +@@ -1,36 +0,0 @@ +-// RUN: %clangxx -O0 -g %s -lcrypt -o %t && %run %t +- +-// crypt.h is missing from Android. +-// UNSUPPORTED: android +- +-#include <assert.h> +-#include <unistd.h> +-#include <cstring> +-#include <crypt.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/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp +deleted file mode 100644 +index 3a8faaa1ae7682..00000000000000 +--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/crypt.cpp ++++ /dev/null +@@ -1,32 +0,0 @@ +-// RUN: %clangxx -O0 -g %s -o %t -lcrypt && %run %t +- +-// crypt() is missing from Android and -lcrypt from darwin. +-// UNSUPPORTED: android, darwin +- +-#include <assert.h> +-#include <unistd.h> +-#include <cstring> +-#if __has_include(<crypt.h>) +-#include <crypt.h> +-#endif +- +-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); +- } +-} |