[compiler-rt] r183529 - [sanitizer] Handle SIOCGIFCONF ioctl.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Jun 7 08:49:38 PDT 2013
Author: eugenis
Date: Fri Jun 7 10:49:38 2013
New Revision: 183529
URL: http://llvm.org/viewvc/llvm-project?rev=183529&view=rev
Log:
[sanitizer] Handle SIOCGIFCONF ioctl.
Added:
compiler-rt/trunk/lib/msan/lit_tests/ioctl_custom.cc (with props)
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
Added: compiler-rt/trunk/lib/msan/lit_tests/ioctl_custom.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/ioctl_custom.cc?rev=183529&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/ioctl_custom.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/ioctl_custom.cc Fri Jun 7 10:49:38 2013
@@ -0,0 +1,33 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O3 -g %s -o %t && %t
+
+// RUN: %clangxx_msan -DPOSITIVE -m64 -O0 -g %s -o %t && %t 2>&1 | FileCheck %s
+// RUN: %clangxx_msan -DPOSITIVE -m64 -O3 -g %s -o %t && %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
+
+ struct ifreq ifreqs[20];
+ struct ifconf ifc;
+ ifc.ifc_ifcu.ifcu_req = ifreqs;
+#ifndef POSITIVE
+ ifc.ifc_len = sizeof(ifreqs);
+#endif
+ int res = ioctl(fd, SIOCGIFCONF, (void *)&ifc);
+ // CHECK: UMR in ioctl{{.*}} at offset 0
+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: #{{.*}} in main {{.*}}ioctl_custom.cc:[[@LINE-3]]
+ assert(res == 0);
+ for (int i = 0; i < ifc.ifc_len / sizeof(*ifc.ifc_ifcu.ifcu_req); ++i)
+ printf("%d %zu %s\n", i, strlen(ifreqs[i].ifr_name), ifreqs[i].ifr_name);
+ return 0;
+}
Propchange: compiler-rt/trunk/lib/msan/lit_tests/ioctl_custom.cc
------------------------------------------------------------------------------
svn:eol-style = LF
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc?rev=183529&r1=183528&r2=183529&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc Fri Jun 7 10:49:38 2013
@@ -66,7 +66,7 @@ static void ioctl_table_fill() {
_(0x00008903, WRITE, sizeof(int)); // FIOGETOWN
_(0x00008904, WRITE, sizeof(int)); // SIOCGPGRP
_(0x00008905, WRITE, sizeof(int)); // SIOCATMAR
- _(0x00008912, WRITE, struct_ifconf_sz); // SIOCGIFCONF
+ _(0x00008912, CUSTOM, 0); // SIOCGIFCONF
_(0x00008913, WRITE, struct_ifreq_sz); // SIOCGIFFLAGS
_(0x00008914, READ, struct_ifreq_sz); // SIOCSIFFLAGS
_(0x00008915, WRITE, struct_ifreq_sz); // SIOCGIFADDR
@@ -502,7 +502,13 @@ static void ioctl_common_pre(void *ctx,
COMMON_INTERCEPTOR_READ_RANGE(ctx, arg, desc->size);
if (desc->type != ioctl_desc::CUSTOM)
return;
- // FIXME: add some ioctls of "CUSTOM" type and handle them here.
+ switch (request) {
+ case 0x00008912: { // SIOCGIFCONF
+ struct __sanitizer_ifconf *ifc = (__sanitizer_ifconf *)arg;
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &ifc->ifc_len, sizeof(ifc->ifc_len));
+ break;
+ }
+ }
return;
}
@@ -514,5 +520,12 @@ static void ioctl_common_post(void *ctx,
}
if (desc->type != ioctl_desc::CUSTOM)
return;
- return; // FIXME
+ switch (request) {
+ case 0x00008912: { // SIOCGIFCONF
+ struct __sanitizer_ifconf *ifc = (__sanitizer_ifconf *)arg;
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ifc->ifc_ifcu.ifcu_req, ifc->ifc_len);
+ break;
+ }
+ }
+ return;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=183529&r1=183528&r2=183529&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Fri Jun 7 10:49:38 2013
@@ -150,7 +150,6 @@ namespace __sanitizer {
// ioctl arguments
unsigned struct_arpreq_sz = sizeof(struct arpreq);
- unsigned struct_ifconf_sz = sizeof(struct ifconf);
unsigned struct_ifreq_sz = sizeof(struct ifreq);
unsigned struct_termios_sz = sizeof(struct termios);
unsigned struct_winsize_sz = sizeof(struct winsize);
@@ -280,4 +279,9 @@ CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len)
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
+CHECK_TYPE_SIZE(ifconf);
+CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
+CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
+
#endif // SANITIZER_LINUX || SANITIZER_MAC
+
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=183529&r1=183528&r2=183529&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 Fri Jun 7 10:49:38 2013
@@ -149,8 +149,14 @@ namespace __sanitizer {
};
// ioctl arguments
+ struct __sanitizer_ifconf {
+ int ifc_len;
+ union {
+ void *ifcu_req;
+ } ifc_ifcu;
+ };
+
extern unsigned struct_arpreq_sz;
- extern unsigned struct_ifconf_sz;
extern unsigned struct_ifreq_sz;
extern unsigned struct_termios_sz;
extern unsigned struct_winsize_sz;
More information about the llvm-commits
mailing list