diff options
| author | Kamil Rytarowski <n54@gmx.com> | 2018-01-18 10:53:27 +0000 |
|---|---|---|
| committer | Kamil Rytarowski <n54@gmx.com> | 2018-01-18 10:53:27 +0000 |
| commit | c815ed57927615e18c0df0cdf8a662bdb1e6a3b7 (patch) | |
| tree | f98874b98c23894c4baca57223abb8b62073099d | |
| parent | 360974a559f8f87b8cb0f2303bd1f9ef03df403d (diff) | |
| download | bcm5719-llvm-c815ed57927615e18c0df0cdf8a662bdb1e6a3b7.tar.gz bcm5719-llvm-c815ed57927615e18c0df0cdf8a662bdb1e6a3b7.zip | |
Add new interceptors for pwcache(3)-style functions
Summary:
From <pwd.h>: user_from_uid, uid_from_user
From <grp.h>: group_from_gid, gid_from_group
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, vitalybuka
Reviewed By: vitalybuka
Subscribers: kubamracek, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D42068
llvm-svn: 322829
6 files changed, 138 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 684f6b4ba56..c0212dec2cc 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -6476,6 +6476,70 @@ INTERCEPTOR(int, acct, const char *file) { #define INIT_ACCT #endif +#if SANITIZER_INTERCEPT_USER_FROM_UID +INTERCEPTOR(const char *, user_from_uid, u32 uid, int nouser) { + void *ctx; + const char *user; + COMMON_INTERCEPTOR_ENTER(ctx, user_from_uid, uid, nouser); + user = REAL(user_from_uid)(uid, nouser); + if (user) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, user, REAL(strlen)(user) + 1); + return user; +} +#define INIT_USER_FROM_UID COMMON_INTERCEPT_FUNCTION(user_from_uid) +#else +#define INIT_USER_FROM_UID +#endif + +#if SANITIZER_INTERCEPT_UID_FROM_USER +INTERCEPTOR(int, uid_from_user, const char *name, u32 *uid) { + void *ctx; + int res; + COMMON_INTERCEPTOR_ENTER(ctx, uid_from_user, name, uid); + if (name) + COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1); + res = REAL(uid_from_user)(name, uid); + if (uid) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, uid, sizeof(*uid)); + return ret; +} +#define INIT_UID_FROM_USER COMMON_INTERCEPT_FUNCTION(uid_from_user) +#else +#define INIT_UID_FROM_USER +#endif + +#if SANITIZER_INTERCEPT_GROUP_FROM_GID +INTERCEPTOR(const char *, group_from_gid, u32 gid, int nogroup) { + void *ctx; + const char *group; + COMMON_INTERCEPTOR_ENTER(ctx, group_from_gid, gid, nogroup); + group = REAL(group_from_gid)(gid, nogroup); + if (group) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, group, REAL(strlen)(group) + 1); + return group; +} +#define INIT_GROUP_FROM_GID COMMON_INTERCEPT_FUNCTION(group_from_gid) +#else +#define INIT_GROUP_FROM_GID +#endif + +#if SANITIZER_INTERCEPT_GID_FROM_GROUP +INTERCEPTOR(int, gid_from_group, const char *group, u32 *gid) { + void *ctx; + int res; + COMMON_INTERCEPTOR_ENTER(ctx, gid_from_group, group, gid); + if (group) + COMMON_INTERCEPTOR_READ_RANGE(ctx, group, REAL(strlen)(group) + 1); + res = REAL(gid_from_group)(group, gid); + if (gid) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, gid, sizeof(*gid)); + return ret; +} +#define INIT_GID_FROM_GROUP COMMON_INTERCEPT_FUNCTION(gid_from_group) +#else +#define INIT_GID_FROM_GROUP +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap(); @@ -6688,6 +6752,10 @@ static void InitializeCommonInterceptors() { INIT_WCSLEN; INIT_WCSCAT; INIT_ACCT; + INIT_USER_FROM_UID; + INIT_UID_FROM_USER; + INIT_GROUP_FROM_GID; + INIT_GID_FROM_GROUP; #if SANITIZER_NETBSD COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index da56646f741..84f5c2d2ba6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -433,5 +433,9 @@ #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID #define SANITIZER_INTERCEPT_ACCT SI_NETBSD +#define SANITIZER_INTERCEPT_USER_FROM_UID SI_NETBSD +#define SANITIZER_INTERCEPT_UID_FROM_USER SI_NETBSD +#define SANITIZER_INTERCEPT_GROUP_FROM_GID SI_NETBSD +#define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc new file mode 100644 index 00000000000..c6a9bc97c1e --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc @@ -0,0 +1,16 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include <grp.h> +#include <stdlib.h> + +int main(void) { + gid_t nobody; + + if (gid_from_group("nobody", &nobody) == -1) + exit(1); + + if (nobody) + exit(0); + + return 0; +} diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc new file mode 100644 index 00000000000..eb39da7b2b5 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc @@ -0,0 +1,17 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include <grp.h> +#include <stdlib.h> +#include <string.h> + +int main(void) { + const char *nobody; + + if (!(nobody = group_from_gid(0, 0))) + exit(1); + + if (strlen(nobody)) + exit(0); + + return 0; +} diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc new file mode 100644 index 00000000000..4cc1366aad4 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc @@ -0,0 +1,16 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include <pwd.h> +#include <stdlib.h> + +int main(void) { + uid_t nobody; + + if (uid_from_user("nobody", &nobody) == -1) + exit(1); + + if (nobody) + exit(0); + + return 0; +} diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc new file mode 100644 index 00000000000..bb098525a47 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc @@ -0,0 +1,17 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include <pwd.h> +#include <stdlib.h> +#include <string.h> + +int main(void) { + const char *nobody; + + if (!(nobody = user_from_uid(0, 0))) + exit(1); + + if (strlen(nobody)) + exit(0); + + return 0; +} |

