]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: Fix segfault in update_from_hook 43944/head
authorAdam Kupczyk <akupczyk@redhat.com>
Tue, 16 Nov 2021 12:33:28 +0000 (13:33 +0100)
committerAdam Kupczyk <akupczyk@redhat.com>
Tue, 16 Nov 2021 13:04:31 +0000 (14:04 +0100)
We create SubProcess to run script conf.crush_location_hook.
We pass arguments via add_cmd_args(const char*, ...).
One of the arguments, cct->_conf->name.get_type_str(), is string_view.
x86-64-ABI states that when struct/class is passed by value, its fields are extracted to
registers/pushed on stack.
string_view is a class with fields:
    class basic_string_view {
    ...
      size_t     _M_len;
      const _CharT* _M_str;
    };

As a result, a 7th parameter on stack (1st is `this` of SubProcess),
is _M_len, but is it interpreted as char*, which leads to SIGSEGV.

Fixes: https://tracker.ceph.com/issues/50659
Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
src/common/entity_name.cc
src/common/entity_name.h

index 2eb24829a1c86adf0d3ca95137a4f7df805377e1..5357b34eacb7f3f5f190c7183130c56568f1a54e 100644 (file)
@@ -106,7 +106,7 @@ void EntityName::set_name(entity_name_t n)
   set(n.type(), s);
 }
 
-std::string_view EntityName::
+const char* EntityName::
 get_type_str() const
 {
   return ceph_entity_type_name(type);
index 886c4b4946f8ed94bc29e435388b6e1942b7ffac..5e5ab111404a68f9a72c91b3794990aeb7f89b54 100644 (file)
@@ -52,7 +52,7 @@ struct EntityName
   void set_id(std::string_view id_);
   void set_name(entity_name_t n);
 
-  std::string_view get_type_str() const;
+  const char* get_type_str() const;
 
   uint32_t get_type() const { return type; }
   bool is_osd() const { return get_type() == CEPH_ENTITY_TYPE_OSD; }