]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/msg_types: fix the entity_addr_t's decoder 17699/head
authorKefu Chai <kchai@redhat.com>
Wed, 13 Sep 2017 14:55:58 +0000 (22:55 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 15 Sep 2017 09:26:19 +0000 (17:26 +0800)
the daemon is vulnerable to malicious client, which is able to send
large elen, and corrupt the stack, etc.

* throw at seeing corrupted entity_addr_t where its elen exceeds
  the length of sockaddr
* handle the exception thrown when decoding entity_addr_t in messenger
  layer.
* if a malicious client manages to send a corrutped entity_addr_t to
  daemon, daemon will crash because decode fails and the exception is
  not handled. it's better than continuing working with the bogus
  message.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/async/AsyncConnection.cc
src/msg/msg_types.h
src/msg/simple/Pipe.cc

index 7899a172759d0c94fbd688ceebfcd0b517e3b4cc..ce76f1508834c9f99d18fa3fa2af42be810ee2eb 100644 (file)
@@ -1261,10 +1261,13 @@ ssize_t AsyncConnection::_process_connection()
         }
 
         addr_bl.append(state_buffer+strlen(CEPH_BANNER), sizeof(ceph_entity_addr));
-        {
+        try {
           bufferlist::iterator ti = addr_bl.begin();
           ::decode(peer_addr, ti);
-        }
+        } catch (const buffer::error& e) {
+         lderr(async_msgr->cct) << __func__ <<  " decode peer_addr failed " << dendl;
+          goto fail;
+       }
 
         ldout(async_msgr->cct, 10) << __func__ << " accept peer addr is " << peer_addr << dendl;
         if (peer_addr.is_blank_ip()) {
index 8a20ba0f060eb5fb3c6286e1b0652eee60f2634f..f98d9600f7a7f8ac0c0f2d44c77339686585b381 100644 (file)
@@ -456,7 +456,15 @@ struct entity_addr_t {
     __u32 elen;
     ::decode(elen, bl);
     if (elen) {
-      bl.copy(elen, (char*)get_sockaddr());
+      if (elen < sizeof(u.sa.sa_family)) {
+       throw buffer::malformed_input("elen smaller than family len");
+      }
+      bl.copy(sizeof(u.sa.sa_family), (char*)&u.sa.sa_family);
+      if (elen > get_sockaddr_len()) {
+       throw buffer::malformed_input("elen exceeds sockaddr len");
+      }
+      elen -= sizeof(u.sa.sa_family);
+      bl.copy(elen, u.sa.sa_data);
     }
     DECODE_FINISH(bl);
   }
index 4a7ab9acab7a0e6a2b8db601c1f9ac8cd008a38d..3e4293cb49eff6e6cf372fba95cde8ca12e27ff5 100644 (file)
@@ -407,9 +407,13 @@ int Pipe::accept()
     ldout(msgr->cct,10) << "accept couldn't read peer_addr" << dendl;
     goto fail_unlocked;
   }
-  {
+  try {
     bufferlist::iterator ti = addrbl.begin();
     ::decode(peer_addr, ti);
+  } catch (const buffer::error& e) {
+    ldout(msgr->cct,2) << __func__ <<  " decode peer_addr failed: " << e.what()
+                       << dendl;
+    goto fail_unlocked;
   }
 
   ldout(msgr->cct,10) << "accept peer addr is " << peer_addr << dendl;