]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
prevent random people from encoding the OSDMap
authorSage Weil <sage@redhat.com>
Fri, 22 Aug 2014 18:52:26 +0000 (11:52 -0700)
committerSage Weil <sage@redhat.com>
Mon, 10 Nov 2014 22:20:24 +0000 (14:20 -0800)
This is a safety check: nobody should be encoding OSDMaps except:

 - the mons
 - MOSDMap, when encoding old OSDMaps with legacy encodings
 - ceph-dencoder
 - the OSD

More importantly, nobody should be encoding OSDMap::Incremental except

 - the leader mon

We use a reserved feature bit to indicate that the encoder is enlightened.
Note that we skip this check for legacy encodings, so we don't touch
MOSDMap in this patch.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/OSDMonitor.cc
src/osd/OSD.cc
src/osd/OSDMap.cc
src/test/encoding/ceph_dencoder.cc

index 112dd06ee7ddc2c45ba1404a3711674004197bf9..ea73a3f13c82ceab4c7d58bdc2270d569a2ca595 100644 (file)
@@ -109,7 +109,7 @@ void OSDMonitor::create_initial()
   newmap.created = newmap.modified = ceph_clock_now(g_ceph_context);
 
   // encode into pending incremental
-  newmap.encode(pending_inc.fullmap, mon->quorum_features);
+  newmap.encode(pending_inc.fullmap, mon->quorum_features | CEPH_FEATURE_RESERVED);
 }
 
 void OSDMonitor::update_from_paxos(bool *need_bootstrap)
@@ -217,7 +217,7 @@ void OSDMonitor::update_from_paxos(bool *need_bootstrap)
     if (!f)
       f = -1;
     bufferlist full_bl;
-    osdmap.encode(full_bl, f);
+    osdmap.encode(full_bl, f | CEPH_FEATURE_RESERVED);
     tx_size += full_bl.length();
 
     put_version_full(t, osdmap.epoch, full_bl);
@@ -644,7 +644,7 @@ void OSDMonitor::encode_pending(MonitorDBStore::TransactionRef t)
 
   // encode
   assert(get_last_committed() + 1 == pending_inc.epoch);
-  ::encode(pending_inc, bl, mon->quorum_features);
+  ::encode(pending_inc, bl, mon->quorum_features | CEPH_FEATURE_RESERVED);
 
   /* put everything in the transaction */
   put_version(t, pending_inc.epoch, bl);
index 8dcbec23e3c61f4857e0b277991b19cd1908633c..157988ec93ac431d304c7e0f0ed209bb3109e966 100644 (file)
@@ -6196,7 +6196,7 @@ void OSD::handle_osd_map(MOSDMap *m)
             << dendl;
 
       bufferlist fbl;
-      o->encode(fbl);
+      o->encode(fbl, inc.encode_features | CEPH_FEATURE_RESERVED);
 
       hobject_t fulloid = get_osdmap_pobject_name(e);
       t.write(META_COLL, fulloid, 0, fbl.length(), fbl);
index 3af187ba7448908471be6fe485b3910ee7320819..593cd982ee638aae1b554e68679130f0e07bda25 100644 (file)
@@ -396,6 +396,13 @@ void OSDMap::Incremental::encode(bufferlist& bl, uint64_t features) const
     return;
   }
 
+  // only a select set of callers should *ever* be encoding new
+  // OSDMaps.  others should be passing around the canonical encoded
+  // buffers from on high.  select out those callers by passing in an
+  // "impossible" feature bit.
+  assert(features & CEPH_FEATURE_RESERVED);
+  features &= ~CEPH_FEATURE_RESERVED;
+
   // meta-encoding: how we include client-used and osd-specific data
   ENCODE_START(7, 7, bl);
 
@@ -1786,6 +1793,14 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const
     encode_classic(bl, features);
     return;
   }
+
+  // only a select set of callers should *ever* be encoding new
+  // OSDMaps.  others should be passing around the canonical encoded
+  // buffers from on high.  select out those callers by passing in an
+  // "impossible" feature bit.
+  assert(features & CEPH_FEATURE_RESERVED);
+  features &= ~CEPH_FEATURE_RESERVED;
+
   // meta-encoding: how we include client-used and osd-specific data
   ENCODE_START(7, 7, bl);
 
index 8391f33cb2fab4e7e3c427531e9ba5cc7b5e28a1..3d7d800cce2b25ea67e6cd633e248fe544ed0161 100644 (file)
@@ -312,7 +312,7 @@ int main(int argc, const char **argv)
        usage(cerr);
        exit(1);
       }
-      den->encode(encbl, features);
+      den->encode(encbl, features | CEPH_FEATURE_RESERVED); // hack for OSDMap
     } else if (*i == string("decode")) {
       if (!den) {
        cerr << "must first select type with 'type <name>'" << std::endl;