Bug 782460: Fix hal enum serializers, make wake lock permission checking match the DOM's, and log a message when an app process fails a backstop permission check. r=gal
authorChris Jones <jones.chris.g@gmail.com>
Sat, 25 Aug 2012 15:38:04 -0700
changeset 103432 af3d980899704fa608576eb27c5a97088311a315
parent 103431 7ef5b8b2c2c72582d852887b1772268747fe0c56
child 103433 730c4f0ec3ae03637cd8d79135d10fa125677640
push id13987
push usercjones@mozilla.com
push dateSat, 25 Aug 2012 22:38:10 +0000
treeherdermozilla-inbound@af3d98089970 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs782460
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 782460: Fix hal enum serializers, make wake lock permission checking match the DOM's, and log a message when an app process fails a backstop permission check. r=gal
dom/ipc/AppProcessPermissions.cpp
hal/HalTypes.h
hal/sandbox/SandboxHal.cpp
--- a/dom/ipc/AppProcessPermissions.cpp
+++ b/dom/ipc/AppProcessPermissions.cpp
@@ -31,18 +31,21 @@ AppProcessHasPermission(PBrowserParent* 
   // isBrowser frames inherit their app descriptor to identify their
   // data storage, but they don't inherit the permissions associated
   // with that descriptor.
   if (!app || tab->IsBrowserElement()) {
     return false;
   }
 
   bool hasPermission = false;
-  return (NS_SUCCEEDED(app->HasPermission(aPermission, &hasPermission)) &&
-          hasPermission);
+  if (!NS_SUCCEEDED(app->HasPermission(aPermission, &hasPermission)) ||
+      !hasPermission) {
+    printf_stderr("Security problem: App process does not have `%s' permission.  It will be killed.", aPermission);
+  }
+  return hasPermission;
 }
 
 bool
 AppProcessHasPermission(PContentParent* aActor, const char* aPermission)
 {
   const InfallibleTArray<PBrowserParent*>& browsers =
     aActor->ManagedPBrowserParent();
   for (uint32_t i = 0; i < browsers.Length(); ++i) {
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -24,22 +24,24 @@ enum LightType {
     eHalLightID_Notifications = 4,
     eHalLightID_Attention = 5,
     eHalLightID_Bluetooth = 6,
     eHalLightID_Wifi = 7,
     eHalLightID_Count = 8         // This should stay at the end
 };
 enum LightMode {
     eHalLightMode_User = 0,       // brightness is managed by user setting
-    eHalLightMode_Sensor = 1      // brightness is managed by a light sensor
+    eHalLightMode_Sensor = 1,     // brightness is managed by a light sensor
+    eHalLightMode_Count
 };
 enum FlashMode {
     eHalLightFlash_None = 0,
     eHalLightFlash_Timed = 1,     // timed flashing.  Use flashOnMS and flashOffMS for timing
-    eHalLightFlash_Hardware = 2   // hardware assisted flashing
+    eHalLightFlash_Hardware = 2,  // hardware assisted flashing
+    eHalLightFlash_Count
 };
 
 class SwitchEvent;
 
 enum SwitchDevice {
   SWITCH_DEVICE_UNKNOWN = -1,
   SWITCH_HEADPHONES,
   SWITCH_USB,
@@ -64,16 +66,17 @@ enum ProcessPriority {
 
 /**
  * Used by ModifyWakeLock
  */
 enum WakeLockControl {
   WAKE_LOCK_REMOVE_ONE = -1,
   WAKE_LOCK_NO_CHANGE  = 0,
   WAKE_LOCK_ADD_ONE    = 1,
+  NUM_WAKE_LOCK
 };
 
 } // namespace hal
 } // namespace mozilla
 
 namespace IPC {
 
 /**
@@ -88,37 +91,37 @@ struct ParamTraits<mozilla::hal::LightTy
 
 /**
  * Light mode serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::LightMode>
   : public EnumSerializer<mozilla::hal::LightMode,
                           mozilla::hal::eHalLightMode_User,
-                          mozilla::hal::eHalLightMode_Sensor>
+                          mozilla::hal::eHalLightMode_Count>
 {};
 
 /**
  * Flash mode serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::FlashMode>
   : public EnumSerializer<mozilla::hal::FlashMode,
                           mozilla::hal::eHalLightFlash_None,
-                          mozilla::hal::eHalLightFlash_Hardware>
+                          mozilla::hal::eHalLightFlash_Count>
 {};
 
 /**
  * WakeLockControl serializer.
  */
 template <>
 struct ParamTraits<mozilla::hal::WakeLockControl>
   : public EnumSerializer<mozilla::hal::WakeLockControl,
                           mozilla::hal::WAKE_LOCK_REMOVE_ONE,
-                          mozilla::hal::WAKE_LOCK_ADD_ONE>
+                          mozilla::hal::NUM_WAKE_LOCK>
 {};
 
 /**
  * Serializer for SwitchState
  */
 template <>
 struct ParamTraits<mozilla::hal::SwitchState>:
   public EnumSerializer<mozilla::hal::SwitchState,
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -569,29 +569,25 @@ public:
     unused << SendNotifySensorChange(aSensorData);
   }
 
   virtual bool
   RecvModifyWakeLock(const nsString &aTopic,
                      const WakeLockControl &aLockAdjust,
                      const WakeLockControl &aHiddenAdjust) MOZ_OVERRIDE
   {
-    if (!AppProcessHasPermission(this, "power")) {
-      return false;
-    }
+    // We allow arbitrary content to use wake locks.
     hal::ModifyWakeLock(aTopic, aLockAdjust, aHiddenAdjust);
     return true;
   }
 
   virtual bool
   RecvEnableWakeLockNotifications() MOZ_OVERRIDE
   {
-    if (!AppProcessHasPermission(this, "power")) {
-      return false;
-    }
+    // We allow arbitrary content to use wake locks.
     hal::RegisterWakeLockObserver(this);
     return true;
   }
    
   virtual bool
   RecvDisableWakeLockNotifications() MOZ_OVERRIDE
   {
     hal::UnregisterWakeLockObserver(this);