vold: Remove autorun.inf at mount/unmount time if it exists

Change-Id: Ia57da8ee177453a601a23d965c2b4f16b6de46e5
Signed-off-by: San Mehat <san@google.com>
diff --git a/Volume.cpp b/Volume.cpp
index 80a8bf1..eae70d1 100644
--- a/Volume.cpp
+++ b/Volume.cpp
@@ -112,6 +112,25 @@
     free(mMountpoint);
 }
 
+void Volume::protectFromAutorunStupidity() {
+    char filename[255];
+
+    snprintf(filename, sizeof(filename), "%s/autorun.inf", SEC_STGDIR);
+    if (!access(filename, F_OK)) {
+        LOGW("Volume contains an autorun.inf! - removing");
+        /*
+         * Ensure the filename is all lower-case so
+         * the process killer can find the inode.
+         * Probably being paranoid here but meh.
+         */
+        rename(filename, filename);
+        Process::killProcessesWithOpenFiles(filename, 2);
+        if (unlink(filename)) {
+            LOGE("Failed to remove %s (%s)", filename, strerror(errno));
+        }
+    }
+}
+
 void Volume::setDebug(bool enable) {
     mDebug = enable;
 }
@@ -306,6 +325,8 @@
 
         LOGI("Device %s, target %s mounted @ /mnt/secure/staging", devicePath, getMountpoint());
 
+        protectFromAutorunStupidity();
+
         if (createBindMounts()) {
             LOGE("Failed to create bindmounts (%s)", strerror(errno));
             umount("/mnt/secure/staging");
@@ -487,6 +508,8 @@
         return -1;
     }
 
+    protectFromAutorunStupidity();
+
     /*
      * Unmount the tmpfs which was obscuring the asec image directory
      * from non root users