[compiler-rt] 76777b2 - [DFSan] Add wrapper for getentropy().
Andrew Browne via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 24 15:11:08 PDT 2021
Author: Andrew Browne
Date: 2021-08-24T15:10:13-07:00
New Revision: 76777b216b48a6c838a7864d953fa19fc50282ec
URL: https://github.com/llvm/llvm-project/commit/76777b216b48a6c838a7864d953fa19fc50282ec
DIFF: https://github.com/llvm/llvm-project/commit/76777b216b48a6c838a7864d953fa19fc50282ec.diff
LOG: [DFSan] Add wrapper for getentropy().
Reviewed By: morehouse
Differential Revision: https://reviews.llvm.org/D108604
Added:
Modified:
compiler-rt/lib/dfsan/dfsan_custom.cpp
compiler-rt/lib/dfsan/done_abilist.txt
compiler-rt/lib/dfsan/libc_ubuntu1404_abilist.txt
compiler-rt/test/dfsan/custom.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 175ae69816db4..97aa13525b7a6 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -1026,6 +1026,33 @@ char *__dfso_get_current_dir_name(dfsan_label *ret_label,
return __dfsw_get_current_dir_name(ret_label);
}
+// This function is only available for glibc 2.25 or newer. Mark it weak so
+// linking succeeds with older glibcs.
+SANITIZER_WEAK_ATTRIBUTE int getentropy(void *buffer, size_t length);
+
+SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_getentropy(void *buffer, size_t length,
+ dfsan_label buffer_label,
+ dfsan_label length_label,
+ dfsan_label *ret_label) {
+ int ret = getentropy(buffer, length);
+ if (ret == 0) {
+ dfsan_set_label(0, buffer, length);
+ }
+ *ret_label = 0;
+ return ret;
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE int __dfso_getentropy(void *buffer, size_t length,
+ dfsan_label buffer_label,
+ dfsan_label length_label,
+ dfsan_label *ret_label,
+ dfsan_origin buffer_origin,
+ dfsan_origin length_origin,
+ dfsan_origin *ret_origin) {
+ return __dfsw_getentropy(buffer, length, buffer_label, length_label,
+ ret_label);
+}
+
SANITIZER_INTERFACE_ATTRIBUTE
int __dfsw_gethostname(char *name, size_t len, dfsan_label name_label,
dfsan_label len_label, dfsan_label *ret_label) {
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index 3c2670e04c29c..4dd0a86d66a5f 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -218,6 +218,7 @@ fun:fgets=custom
fun:fstat=custom
fun:getcwd=custom
fun:get_current_dir_name=custom
+fun:getentropy=custom
fun:gethostname=custom
fun:getpeername=custom
fun:getrlimit=custom
diff --git a/compiler-rt/lib/dfsan/libc_ubuntu1404_abilist.txt b/compiler-rt/lib/dfsan/libc_ubuntu1404_abilist.txt
index a1ea0a06b5375..433092e2b27b8 100644
--- a/compiler-rt/lib/dfsan/libc_ubuntu1404_abilist.txt
+++ b/compiler-rt/lib/dfsan/libc_ubuntu1404_abilist.txt
@@ -1852,6 +1852,7 @@ fun:getdirentries64=uninstrumented
fun:getdomainname=uninstrumented
fun:getdtablesize=uninstrumented
fun:getegid=uninstrumented
+fun:getentropy=uninstrumented
fun:getenv=uninstrumented
fun:geteuid=uninstrumented
fun:getfsent=uninstrumented
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 99450a6c1e71a..e25e1de2c0f0e 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -161,6 +161,10 @@ dfsan_label i_j_label = 0;
#define ASSERT_SAVED_N_ORIGINS(val, n)
#endif
+#if !defined(__GLIBC_PREREQ)
+# define __GLIBC_PREREQ(a, b) 0
+#endif
+
void test_stat() {
int i = 1;
dfsan_set_label(i_label, &i, sizeof(i));
@@ -944,6 +948,21 @@ void test_get_current_dir_name() {
ASSERT_ZERO_LABEL(ret);
}
+void test_getentropy() {
+ char buf[64];
+ dfsan_set_label(i_label, buf + 2, 2);
+ DEFINE_AND_SAVE_ORIGINS(buf)
+#if __GLIBC_PREREQ(2, 25)
+ // glibc >= 2.25 has getentropy()
+ int ret = getentropy(buf, sizeof(buf));
+ ASSERT_ZERO_LABEL(ret);
+ if (ret == 0) {
+ ASSERT_READ_ZERO_LABEL(buf + 2, 2);
+ ASSERT_SAVED_ORIGINS(buf)
+ }
+#endif
+}
+
void test_gethostname() {
char buf[1024];
dfsan_set_label(i_label, buf + 2, 2);
@@ -1967,6 +1986,7 @@ int main(void) {
test_fstat();
test_get_current_dir_name();
test_getcwd();
+ test_getentropy();
test_gethostname();
test_getpeername();
test_getpwuid_r();
More information about the llvm-commits
mailing list