We now have a patch that implements my suggestion above. This patch could theoretically backported to 10.2 and 10.3. If that patch were applied, an IMPORT TABLESPACE or a downgrade to an earlier version would seemingly succeed, but we would get crashes somewhere later when the encrypted spatial index is being accessed.
During the recent work on MDEV-12112 and MDEV-17957, an alternative (and in my opinion better) approach occurred to me.
Instead of shuffling bytes in multiple higher-level places of InnoDB, I think that the clean solution is to introduce a new encrypted file format, identified by a new flag in FSP_SPACE_FLAGS that would also prevent downgrading to earlier versions of MariaDB. This flag would indicate the following:
- Unused bytes on data pages are initialized to zero. (As noted in
MDEV-18097, files created before this change in MySQL 5.1.48 could contain any garbage values, limiting the ability to repurpose pages.)
- A new page checksum algorithm is always being used, and it cannot be overridden by innodb_checksum_algorithm.
- Only one page_compressed algorithm is allowed, and it cannot be overridden. The page header will include the checksum and the compressed size of the page.
- Only one checksum will be computed on the page payload (after any compression or encryption).
- The key_version will be stored in the first 4 bytes of each page. So, there is no collision with SPATIAL INDEX.
We’d introduce a new (and default) configuration parameter value
innodb_checksum_algorithm=full_crc32 (or a better name) with a strict_ counterpart, which would refuse to open old data files.
The non-strict variant would open old tablespaces fine, but it would create new files with the new bit in FSP_SPACE_FLAGS set, preventing a downgrade.
If compatibility with older MariaDB or MySQL versions is desired, then innodb_checksum_algorithm=crc32 can be set. In this case, any pre-existing new-checksum files would be opened fine, but they would keep using the new format. Any new created files would use the old format and the configured innodb_checksum_algorithm.
Setting innodb_checksum_algorithm to something else than the default value (or its strict_ counterpart) would issue a deprecation warning, because we would want to remove the old algorithms and formats in some future release of MariaDB.
To implement this, we’d have to do a few things differently when decrypting or encrypting pages, based on fil_space_t::flags. A member function could be introduced for those checks, something like this:
bool use_full_checksum() const {return flags & FSP_FLAGS_FULL_CHECKSUM; }
|
A CREATE TABLE or ALTER TABLE of an encrypted table with SPATIAL INDEX was prevented in
MDEV-11974, at least in some tested cases. There was a refinement for ALTER TABLE.Surprises with unencrypted data (minimum bounding rectangles and PRIMARY KEY values) might be possible with innodb_encrypt_tables=ON.
I think that we can do the following:
MDEV-15562did it for the clustered index root page.Thanks to the new page type code, the index pages should be unaccessible in earlier versions of MariaDB.
As part of this fix, the creation of encrypted tables with SPATIAL INDEX must be re-enabled.