]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
messages,mds: Fix decoding of enum types on big-endian systems
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 18 Aug 2020 07:51:22 +0000 (09:51 +0200)
committerNathan Cutler <ncutler@suse.com>
Fri, 25 Sep 2020 14:09:25 +0000 (16:09 +0200)
commitcf8ff54d208cef665d316cde3fc6d01a36f943ca
tree6d40a500d197339a200543e39445ae1b15a865be
parent3480d2223c79680a792ed1e5c2d0c217ccb8528c
messages,mds: Fix decoding of enum types on big-endian systems

When a struct member that has enum type needs to be encoded or
decoded, we need to use an explicit integer type, since there
are no encode routines for the enum type.  (This is probably
to avoid introducing dependencies on implementation-defined
choices by the compiler to use a particular underlying type.)

This leads to code sequences along the lines of:
  encode((int32_t)state, bl);
and
  decode((int32_t&)(state), bl);

The encode line is actually fine, but the decode line is
incorrect on big-endian systems if the underlying type of
the enum differs from the explicitly chosen integer type.

This is because this performs in effect a pointer cast,
and will write the decoded int32_t value into the memory
backing the "state" member variable.  If the sizes differ,
the value is written into the wrong bytes of "state" on
big-endian systems.

This patch fixes the problem by decoding into an intermediate
variable of the integer type first, and then casting the result
while assigning to the struct member of enum type.

This bug showed up initially as invalid health-status values
causing Ceph daemon aborts on s390x.  I've tried to find and
fix all other instances of the same enum decode pattern as well.

Fixes: https://tracker.ceph.com/issues/47015
Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
(cherry picked from commit 7ed716823fd02d84ea53cb61350bf14f248ebb8b)

Conflicts:
src/mds/PurgeQueue.cc
- nautilus has "p.advance(pad_size)", instead of "p += pad_size",
  in the line immediately preceding the first change
src/mds/MDSMap.cc
src/mds/PurgeQueue.cc
src/messages/MMDSBeacon.h
src/messages/MMgrReport.h