Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-30942

MSAN_OPTIONS=poison_in_dtor=1 causes failures in free_root()

    XMLWordPrintable

Details

    Description

      Recently, MSAN_OPTIONS=poison_in_dtor=1 was enabled by default. This caught some foul play in InnoDB (to be fixed in MDEV-30936) as well as massive amounts of failures in free_root(), because the root->used or root->free lists could be marked as uninitialized in various destructors for objects that are allocated from a MEM_ROOT.

      It would be good programming style to make sure that MemorySanitizer does not report any errors when MSAN_OPTIONS=poison_in_dtor=1 is set.

      It is possible to work around the errors with the following patch:

      diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
      index aa0182c755e..b9071ad7eee 100644
      --- a/mysys/my_alloc.c
      +++ b/mysys/my_alloc.c
      @@ -415,14 +415,26 @@ void free_root(MEM_ROOT *root, myf MyFlags)
         if (!(MyFlags & MY_KEEP_PREALLOC))
           root->pre_alloc=0;
       
      +#if __has_feature(memory_sanitizer)
      +  /* Work around MSAN_OPTIONS=poison_in_dtor=1 */
      +  MEM_MAKE_DEFINED(&root->used, sizeof root->used);
      +  MEM_MAKE_DEFINED(&root->free, sizeof root->free);
      +#endif
      +
         for (next=root->used; next ;)
         {
      +#if __has_feature(memory_sanitizer)
      +    MEM_MAKE_DEFINED(&next->next, sizeof next->next);
      +#endif
           old=next; next= next->next ;
           if (old != root->pre_alloc)
             my_free(old);
         }
         for (next=root->free ; next ;)
         {
      +#if __has_feature(memory_sanitizer)
      +    MEM_MAKE_DEFINED(&next->next, sizeof next->next);
      +#endif
           old=next; next= next->next;
           if (old != root->pre_alloc)
             my_free(old);
      

      I think that explicitly setting MSAN_OPTIONS=poison_in_dtor=0 when using Clang 15 or later is a lesser evil. The above patch could mask other errors as well.

      Attachments

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.