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

Add Missing Binlog Log Event Validation

    XMLWordPrintable

Details

    • Can result in hang or crash
    • Q4/2026 Replic. Development

    Description

      A binlog event that is malformed or deliberately crafted can make the
      server or mariadb-binlog read, and in some cases write, outside the
      event buffer while the event is being parsed. The outcome depends on
      the event type and the field. Reports so far include a crash of the
      slave SQL thread that takes the whole server down, a crash of
      mariadb-binlog, a replica that applies wrong data, and sanitizer
      reports of heap buffer overflows.

      Such an event reaches the parser from (1) a master the attacker
      controls, (2) an unencrypted replication stream the attacker can
      modify, (3) a BINLOG statement run by a user with the
      BINLOG REPLAY privilege, and (4) a binlog or relay log file given to
      mariadb-binlog. The event checksum does not stop this, since whoever
      writes the event also computes its checksum.

      Each event type is parsed by its own Log_event subclass
      constructor, called from Log_event::read_log_event(). The
      constructor takes lengths, counts and offsets from the event bytes
      themselves, and uses them to size allocations, advance the read pointer
      and copy data. The slave IO and SQL threads, the BINLOG statement
      and mariadb-binlog all parse events through these constructors.

      The constructors check some of these values against the end of the
      event and not others, and some existing checks cannot catch a large
      value. Each external report so far has found one more such field, and
      each was filed and fixed on its own ticket: MDEV-39485, MDEV-39660,
      MDEV-39689, MDEV-39762, MDEV-40365, MDEV-40366, MDEV-40643, MDEV-40644,
      MDEV-40645, MDEV-40647, MDEV-40648. A fix for one field does not cover
      the next one, and a bound added for one report can itself be bypassed.
      For example, the column count bound in Table_map_log_event added by
      MDEV-39689 adds the count to the read pointer and compares the sum to
      the end of the event. A column count sent as the single byte 0xfb
      decodes to NULL_LENGTH, the sum wraps, the bound passes, and the
      following memcpy() runs with a length of SIZE_MAX.

      This ticket aims to encompass future missing validation to do a pass
      over the log event code to add many missing validations.

      Attachments

        Issue Links

          Activity

            People

              knielsen Kristian Nielsen
              bnestere Brandon Nesterenko
              Kristian Nielsen Kristian Nielsen
              Brandon Nesterenko Brandon Nesterenko
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 10d
                  10d
                  Remaining:
                  Remaining Estimate - 2d
                  2d
                  Logged:
                  Time Spent - Not Specified Time Not Required
                  Not Specified

                  Git Integration

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