Bug #121348 Concurrent first enable and disable can lose the requested binlog_encryption OFF state
Description:
`Sys_var_binlog_encryption::global_update()` decides whether an update is a
no-op by comparing the requested value with `rpl_encryption.is_enabled()`.
During the first `ON`, `enable()` sets the backing `m_enabled` before master-key
recovery finishes. At that time `is_enabled()` still returns false because it
also requires the recovered key state. The sysvar code releases
`LOCK_global_system_variables` before entering the encryption operation.
Under this ordering, a concurrent later `SET GLOBAL binlog_encryption=OFF` can
observe `is_enabled()==false` and return as a no-op. The earlier `ON` then
finishes and leaves encryption enabled, contrary to the later request. The
requests overlap; this report asks whether a successful `OFF` is meant to be
discarded in this state rather than assuming a documented last-writer-wins rule.
How to repeat:
Use a disposable MySQL 8.4.11 Linux instance; this test changes a global
encryption setting. Start `mysqld` with `--server-id=1 --log-bin=mysql-bin
--binlog-encryption=OFF`. Load `component_keyring_file` at startup with a
`mysqld.my` manifest containing
`{"components":"file://component_keyring_file"}` and a readable
`component_keyring_file.cnf` containing
`{"path":"/tmp/component_keyring_file","read_only":false}`. Use a fresh
keyring data file so the following `ON` is its first enable.
The race needs a scheduling pause. The optional single-file `poc.c` can be
compiled with `gcc -shared -fPIC -O2 -Wall -Wextra -Werror -o my04.so poc.c
-ldl`; start **only this disposable mysqld** with `LD_PRELOAD=/path/to/my04.so`.
It waits at the first real keyring data-file `open`/`fopen`/`rename` after
`/tmp/edbf_hold_arm` exists, creates `/tmp/edbf_hold_blocked`, and continues when
`/tmp/edbf_hold_release` appears (or after a 30-second safety timeout). The marker
files must be created in the same filesystem namespace as `mysqld`. The shim
does not alter I/O results or server variables.
1. Check `SELECT @@global.binlog_encryption;` is `0`. Create
`/tmp/edbf_hold_arm`, with no stale `edbf_hold_blocked` or `edbf_hold_release` file.
2. In session A, start `SET GLOBAL binlog_encryption=ON;` asynchronously.
Wait until `/tmp/edbf_hold_blocked` appears; session A must still be waiting.
3. In session C, `SELECT @@global.binlog_encryption;` returns `1` while A is
waiting. In session B, execute `SET GLOBAL binlog_encryption=OFF;` and wait
for its successful completion **before** releasing A.
4. Create `/tmp/edbf_hold_release`, wait for A to return success, then run
`SELECT @@global.binlog_encryption;` again. The value is `1` despite the
later successful `OFF` request.
The timing and the `edbf_hold_blocked` marker are essential; ordinary unscheduled
concurrent SQL is not a reliable reproducer. A fresh disposable instance is
needed for each attempt because the first-enable transition is stateful.
## Actual result
The deterministic official 8.4.11 run produced:
```text
baseline 0
during paused first enable 1
later SET ... OFF success
earlier SET ... ON success after release
final 1
```
The later successful `OFF` had no effect on the final configuration. A second
official-product run using this directory's standalone `poc.c` reproduced the
same sequence. An earlier unscheduled bounded run ended at `OFF`; that
timing-dependent negative is superseded by these controlled runs.
The server stayed healthy; no crash, plaintext binlog, or data disclosure was
observed. The defect shown here is the incorrect final configuration state.
## Expected result
The `OFF` operation should not silently succeed as a no-op solely because key
recovery makes `is_enabled()` temporarily false during an in-progress `ON`.
Serialize/retry it after the transition or return an explicit conflict error.
If successful overlapping requests are intentionally ordered by completion
rather than issue time, please clarify that contract; the current no-op decision
still needs to be evaluated against the transitional state.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.044 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: `Sys_var_binlog_encryption::global_update()` decides whether an update is a no-op by comparing the requested value with `rpl_encryption.is_enabled()`. During the first `ON`, `enable()` sets the backing `m_enabled` before master-key recovery finishes. At that time `is_enabled()` still returns false because it also requires the recovered key state. The sysvar code releases `LOCK_global_system_variables` before entering the encryption operation. Under this ordering, a concurrent later `SET GLOBAL binlog_encryption=OFF` can observe `is_enabled()==false` and return as a no-op. The earlier `ON` then finishes and leaves encryption enabled, contrary to the later request. The requests overlap; this report asks whether a successful `OFF` is meant to be discarded in this state rather than assuming a documented last-writer-wins rule. How to repeat: Use a disposable MySQL 8.4.11 Linux instance; this test changes a global encryption setting. Start `mysqld` with `--server-id=1 --log-bin=mysql-bin --binlog-encryption=OFF`. Load `component_keyring_file` at startup with a `mysqld.my` manifest containing `{"components":"file://component_keyring_file"}` and a readable `component_keyring_file.cnf` containing `{"path":"/tmp/component_keyring_file","read_only":false}`. Use a fresh keyring data file so the following `ON` is its first enable. The race needs a scheduling pause. The optional single-file `poc.c` can be compiled with `gcc -shared -fPIC -O2 -Wall -Wextra -Werror -o my04.so poc.c -ldl`; start **only this disposable mysqld** with `LD_PRELOAD=/path/to/my04.so`. It waits at the first real keyring data-file `open`/`fopen`/`rename` after `/tmp/edbf_hold_arm` exists, creates `/tmp/edbf_hold_blocked`, and continues when `/tmp/edbf_hold_release` appears (or after a 30-second safety timeout). The marker files must be created in the same filesystem namespace as `mysqld`. The shim does not alter I/O results or server variables. 1. Check `SELECT @@global.binlog_encryption;` is `0`. Create `/tmp/edbf_hold_arm`, with no stale `edbf_hold_blocked` or `edbf_hold_release` file. 2. In session A, start `SET GLOBAL binlog_encryption=ON;` asynchronously. Wait until `/tmp/edbf_hold_blocked` appears; session A must still be waiting. 3. In session C, `SELECT @@global.binlog_encryption;` returns `1` while A is waiting. In session B, execute `SET GLOBAL binlog_encryption=OFF;` and wait for its successful completion **before** releasing A. 4. Create `/tmp/edbf_hold_release`, wait for A to return success, then run `SELECT @@global.binlog_encryption;` again. The value is `1` despite the later successful `OFF` request. The timing and the `edbf_hold_blocked` marker are essential; ordinary unscheduled concurrent SQL is not a reliable reproducer. A fresh disposable instance is needed for each attempt because the first-enable transition is stateful. ## Actual result The deterministic official 8.4.11 run produced: ```text baseline 0 during paused first enable 1 later SET ... OFF success earlier SET ... ON success after release final 1 ``` The later successful `OFF` had no effect on the final configuration. A second official-product run using this directory's standalone `poc.c` reproduced the same sequence. An earlier unscheduled bounded run ended at `OFF`; that timing-dependent negative is superseded by these controlled runs. The server stayed healthy; no crash, plaintext binlog, or data disclosure was observed. The defect shown here is the incorrect final configuration state. ## Expected result The `OFF` operation should not silently succeed as a no-op solely because key recovery makes `is_enabled()` temporarily false during an in-progress `ON`. Serialize/retry it after the transition or return an explicit conflict error. If successful overlapping requests are intentionally ordered by completion rather than issue time, please clarify that contract; the current no-op decision still needs to be evaluated against the transitional state.