Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-2402

Misaligned structure accesses lead to undefined behavior

    • Storage 2016-12-12, Storage 2017-01-23

      Running the MongoDB core JS tests under undefined behavior sanitizer leads to many errors of the following form:

      [MongoDFixture:job0] src/third_party/wiredtiger/src/session/session_api.c:1405:21: runtime error: member access within misaligned address 0x7f8331082010 for type 'WT_SESSION_IMPL' (aka 'struct __wt_session_impl'), which requires 64 byte alignment
      [MongoDFixture:job0] 0x7f8331082010: note: pointer points here
      [MongoDFixture:job0]  00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
      [MongoDFixture:job0]               ^
      [MongoDFixture:job0]     #0 0x2901369 in __open_session /home/andrew/Documents/10gen/dev/src/mongodb/src/third_party/wiredtiger/src/session/session_api.c:1405:8
      [MongoDFixture:job0]     #1 0x2901369 in __wt_open_session /home/andrew/Documents/10gen/dev/src/mongodb/src/third_party/wiredtiger/src/session/session_api.c:1514
      [MongoDFixture:job0]     #2 0x29015f1 in __wt_open_internal_session /home/andrew/Documents/10gen/dev/src/mongodb/src/third_party/wiredtiger/src/session/session_api.c:1552:2
      [MongoDFixture:job0]     #3 0x284463e in __wt_connection_open /home/andrew/Documents/10gen/dev/src/mongodb/src/third_party/wiredtiger/src/conn/conn_open.c:40:2
      [MongoDFixture:job0]     #4 0x2831943 in wiredtiger_open /home/andrew/Documents/10gen/dev/src/mongodb/src/third_party/wiredtiger/src/conn/conn_api.c:2019:2
      [MongoDFixture:job0]     #5 0x1ac3702 in mongo::WiredTigerKVEngine::WiredTigerKVEngine(std::string const&, std::string const&, std::string const&, unsigned long, bool, bool, bool) /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp:239:15
      [MongoDFixture:job0]     #6 0x1ac22f4 in mongo::(anonymous namespace)::WiredTigerFactory::create(mongo::StorageGlobalParams const&, mongo::StorageEngineLockFile const&) const /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp:79:34
      [MongoDFixture:job0]     #7 0x196f7b9 in mongo::ServiceContextMongoD::initializeGlobalStorageEngine() /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/service_context_d.cpp:160:22
      [MongoDFixture:job0]     #8 0x1004412 in mongo::_initAndListen(int) /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/db.cpp:481:5
      [MongoDFixture:job0]     #9 0x100380a in mongo::initAndListen(int) /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/db.cpp:668:9
      [MongoDFixture:job0]     #10 0x1007b3f in mongoDbMain(int, char**, char**) /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/db.cpp:893:25
      [MongoDFixture:job0]     #11 0x1007b3f in main /home/andrew/Documents/10gen/dev/src/mongodb/src/mongo/db/db.cpp:713
      [MongoDFixture:job0] Waiting to connect to mongod on port 20000.
      [MongoDFixture:job0]     #12 0x7f8332b16a3f in __libc_start_main /build/buildd/glibc-2.21/csu/libc-start.c:289
      [MongoDFixture:job0]     #13 0xfeb3c8 in _start (/home/andrew/Documents/10gen/dev/src/mongodb/mongod+0xfeb3c8)
      [MongoDFixture:job0]
      

      This is not the only error, there are many others, but they are generally of this form, where a structure member is read out of a structure that is not aligned.

      This is undefined behavior unless the member is copied to/from an aligned temporary with memcpy. On architectures where unaligned access is legal, the memcpy will be elided.

            Assignee:
            david.hows David Hows
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: