[compiler-rt] [rtsan] Add ioctl interceptor (PR #117569)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 14:35:00 PST 2024


================
@@ -190,6 +190,23 @@ INTERCEPTOR(int, fcntl, int filedes, int cmd, ...) {
   return REAL(fcntl)(filedes, cmd, arg);
 }
 
+INTERCEPTOR(int, ioctl, int filedes, unsigned long request, ...) {
+  __rtsan_notify_intercepted_call("ioctl");
+
+  // See fcntl for discussion on why we use intptr_t
+  // And why we read from va_args on all request types
+  using arg_type = intptr_t;
+  static_assert(sizeof(arg_type) >= sizeof(struct ifreq *));
+  static_assert(sizeof(arg_type) >= sizeof(int));
+
+  va_list args;
+  va_start(args, request);
+  arg_type arg = va_arg(args, arg_type);
+  va_end(args);
+
+  return REAL(ioctl)(filedes, request, arg);
----------------
vitalybuka wrote:

we do these ugly macro, but we know the size of va_list
https://github.com/llvm/llvm-project/blob/8ffe63fb556915c041e8e9bc2d1bf4325f12ba26/compiler-rt/lib/asan/asan_interceptors.cpp#L375-L381

https://github.com/llvm/llvm-project/pull/117569


More information about the llvm-commits mailing list