[compiler-rt] r322829 - Add new interceptors for pwcache(3)-style functions
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 18 02:53:28 PST 2018
Author: kamil
Date: Thu Jan 18 02:53:27 2018
New Revision: 322829
URL: http://llvm.org/viewvc/llvm-project?rev=322829&view=rev
Log:
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
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.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=322829&r1=322828&r2=322829&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Jan 18 02:53:27 2018
@@ -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);
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=322829&r1=322828&r2=322829&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Jan 18 02:53:27 2018
@@ -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
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc?rev=322829&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc Thu Jan 18 02:53:27 2018
@@ -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;
+}
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc?rev=322829&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc Thu Jan 18 02:53:27 2018
@@ -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;
+}
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc?rev=322829&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc Thu Jan 18 02:53:27 2018
@@ -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;
+}
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc?rev=322829&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc Thu Jan 18 02:53:27 2018
@@ -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;
+}
More information about the llvm-commits
mailing list