Bug #121349 mysql_native_password once-per-start warning uses a non-atomic claim sequence

Submitted: 22 Sep 7:48
Reporter: Wwwwing Wwwwing Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Connection Handling Severity:S3 (Non-critical)
Version:MySQL 8.4 branch, commit `99960bf74fa919 OS:Any
Assigned to: CPU Architecture:Any

[22 Sep 7:48] Wwwwing Wwwwing
Description:
`native_password_authentication_deprecation_warning()` intends to log once per
server start. It uses an atomic boolean, but the check and claim are separate:

```cpp
static std::atomic<bool> warning_logged = false;
if (warning_logged) return;
LogPluginErr(...);
warning_logged = true;
```

Two first-use threads can both load `false`, both log, and only then both store
`true`.

How to repeat:
Use a disposable official MySQL 8.4.11 Linux instance with
`--mysql-native-password=ON --log-error-verbosity=3` and a writable error log.
No native-password authentication must occur before the trigger; the warning
flag is once-per-server-start. Create the test account without authenticating
as it:

```sql
CREATE USER 'native'@'localhost' IDENTIFIED WITH mysql_native_password
  AS '*F47AF3CA7E4EC69A43870A67227AB6C4C0D08102';
```

That fixed authentication string corresponds to the synthetic test password
`NativePass1!`. The optional single-file `poc.c` compiles with
`gcc -shared -fPIC -O2 -Wall -Wextra -Werror -o my11.so poc.c -ldl`.
Start only the disposable `mysqld` with
`LD_PRELOAD=/path/to/my11.so EDBF_HOLD_MODE=my11`. This
shim pauses the first formatted/error-log write containing `MY-013360` or
`mysql_native_password`, signals `/tmp/edbf_hold_blocked`, and resumes when
`/tmp/edbf_hold_release` appears (30-second safety timeout). It does not change
the write return value or the warning flag; marker files are created in the
server's filesystem namespace.

1. Record the count of `MY-013360` in the error log, ensure no stale
   `edbf_hold_blocked`/`edbf_hold_release` marker exists, then create `/tmp/edbf_hold_arm`.
2. Start 96 login attempts with 48 concurrent clients, each using the local
   Unix socket and `mysql -unative -pNativePass1! -e 'SELECT 1'`. Keep the
   same newly started server for all attempts.
3. Wait for `/tmp/edbf_hold_blocked`; allow other login threads about 0.5 seconds
   to pass the separate flag check, then create `/tmp/edbf_hold_release`.
4. Wait for all 96 clients, count only **new** `MY-013360` lines in the server
   error log, and run a final `SELECT 1` health query.

The pause is necessary to make the race repeatable. In an earlier unscheduled
96-login control, only one warning was emitted.

## Actual result

In the deterministic official 8.4.11 run, all 96 logins succeeded, the server
remained healthy, and **48 new error-log lines** contained both `MY-013360`
and `mysql_native_password`. A second product run using this directory's
standalone `poc.c` gave the same count; two earlier shortened shim attempts
did not reach the pause and emitted just one line each. This is duplicate
diagnostic output, not an authentication bypass or server crash. Related
[Bug #109635](https://bugs.mysql.com/bug.php?id=109635) describes warning
volume with invalid users, not this concurrent first-use claim race.

## Expected result

Only one thread should atomically claim the right to emit the once-per-start
warning.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 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.