[PATCH] [compiler-rt] Fix the prototype of ioctl interceptor

Kuba Brecka kuba.brecka at gmail.com
Wed Jan 21 11:39:02 PST 2015


Updating sanitizer_common_interceptors_ioctl.inc with `unsigned` -> `unsigned long` as well.

> I agree with "unsigned long request", but is there any benefit in the _unconditional_ va_arg stuff? We don't reliably know if there is an argument to a given ioctl or not, and then we pass this (possible garbage) value to REAL(ioctl) in any case.


I don't think we have a way to tell whether that argument is used or not.  The docs (e.g. http://man7.org/linux/man-pages/man2/ioctl.2.html) also suggest that it's always used:

> The third argument is an untyped pointer to memory.  It's traditionally char

>  *argp (from the days before void * was valid C), and will be so named

>  for this discussion.



http://reviews.llvm.org/D7038

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc

Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1025,8 +1025,12 @@
 
 #if SANITIZER_INTERCEPT_IOCTL
 #include "sanitizer_common_interceptors_ioctl.inc"
-INTERCEPTOR(int, ioctl, int d, unsigned request, void *arg) {
+INTERCEPTOR(int, ioctl, int d, unsigned long request, ...) {
   void *ctx;
+  va_list ap;
+  va_start(ap, request);
+  void *arg = va_arg(ap, void *);
+  va_end(ap);
   COMMON_INTERCEPTOR_ENTER(ctx, ioctl, d, request, arg);
 
   CHECK(ioctl_initialized);
Index: lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
@@ -13,7 +13,7 @@
 #include "sanitizer_flags.h"
 
 struct ioctl_desc {
-  unsigned req;
+  unsigned long req;
   // FIXME: support read+write arguments. Currently READWRITE and WRITE do the
   // same thing.
   // XXX: The declarations below may use WRITE instead of READWRITE, unless
@@ -491,10 +491,10 @@
 }
 
 // Handle the most evil ioctls that encode argument value as part of request id.
-static unsigned ioctl_request_fixup(unsigned req) {
+static unsigned long ioctl_request_fixup(unsigned long req) {
 #if SANITIZER_LINUX
   // Strip size and event number.
-  const unsigned kEviocgbitMask =
+  const unsigned long kEviocgbitMask =
       (IOC_SIZEMASK << IOC_SIZESHIFT) | EVIOC_EV_MAX;
   if ((req & ~kEviocgbitMask) == IOCTL_EVIOCGBIT)
     return IOCTL_EVIOCGBIT;
@@ -507,7 +507,7 @@
   return req;
 }
 
-static const ioctl_desc *ioctl_table_lookup(unsigned req) {
+static const ioctl_desc *ioctl_table_lookup(unsigned long req) {
   int left = 0;
   int right = ioctl_table_size;
   while (left < right) {
@@ -523,7 +523,7 @@
     return 0;
 }
 
-static bool ioctl_decode(unsigned req, ioctl_desc *desc) {
+static bool ioctl_decode(unsigned long req, ioctl_desc *desc) {
   CHECK(desc);
   desc->req = req;
   desc->name = "<DECODED_IOCTL>";
@@ -554,7 +554,7 @@
   return true;
 }
 
-static const ioctl_desc *ioctl_lookup(unsigned req) {
+static const ioctl_desc *ioctl_lookup(unsigned long req) {
   req = ioctl_request_fixup(req);
   const ioctl_desc *desc = ioctl_table_lookup(req);
   if (desc) return desc;
@@ -571,7 +571,7 @@
 }
 
 static void ioctl_common_pre(void *ctx, const ioctl_desc *desc, int d,
-                             unsigned request, void *arg) {
+                             unsigned long request, void *arg) {
   if (desc->type == ioctl_desc::READ || desc->type == ioctl_desc::READWRITE) {
     unsigned size = desc->size ? desc->size : IOC_SIZE(request);
     COMMON_INTERCEPTOR_READ_RANGE(ctx, arg, size);
@@ -589,7 +589,7 @@
 }
 
 static void ioctl_common_post(void *ctx, const ioctl_desc *desc, int res, int d,
-                              unsigned request, void *arg) {
+                              unsigned long request, void *arg) {
   if (desc->type == ioctl_desc::WRITE || desc->type == ioctl_desc::READWRITE) {
     // FIXME: add verbose output
     unsigned size = desc->size ? desc->size : IOC_SIZE(request);

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7038.18543.patch
Type: text/x-patch
Size: 3305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150121/d3374f1d/attachment.bin>


More information about the llvm-commits mailing list