Skip to content

[Bug]: low-privilege users can read other users' SQL from processlist #30278

Closed

Description

@iamlinjunhong

Is there an existing issue for the same bug?

Branch Name

main

Commit ID

17a6200

Other Environment Information

  • Hardware parameters: Apple silicon, arm64
  • OS type: macOS 15.5 (24F74)
  • Others: standalone mo-service built by make build, MySQL-compatible port 26401

Actual Behavior

A user whose grants are only connect plus SELECT on one test table can query information_schema.processlist and read the exact SQL being executed by root in another connection. The issue reproduced 3/3 times with fresh root connections and connection IDs.

Expected Behavior

MySQL 8.0 users without the PROCESS privilege should see only their own process information, not sessions and SQL statements belonging to other users. MatrixOne should enforce an equivalent session-owner or administrative-privilege boundary.

Steps to Reproduce

  1. Create loom_read and grant only SELECT on loom_frontend.priv_a through loom_read_role (setup as in the repro below).
  2. Start a root query in another connection:
select sleep(5)
  1. While it is running, connect as loom_read and execute:
SET ROLE loom_read_role;
SELECT conn_id, account, user, info
FROM information_schema.processlist
WHERE info = 'select sleep(5)' ORDER BY conn_id;
SHOW GRANTS;

Additional information

pkg/sql/colexec/table_function/processlist.go determines visibility using only the tenant name. For account sys, isSysTenant returns true and the response filter accepts every session in that tenant; there is no requesting-user or PROCESS-privilege check. The predefined information_schema.PROCESSLIST view is an unfiltered projection over this table function. This allowed a non-admin user in sys to see root SQL.

Found by Loom bug hunt (module: sql-frontend; tests: unit, black-box, end-to-end, fuzzing)

Activity

  1. added
    kind/bug
    ai-easy
    on Oct 15, 2026
  2. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main;完整 commit:873282742714436bff407dfcdbbe879147162bd3,包含修复 PR #30299。
    • 部署方式:macOS arm64 隔离本地 2 CN(MySQL 16001/16002)/ 1 TN / 1 LogService / Proxy(6001),真实 PyMySQL 协议;2026-10-19。临时用户、角色、数据库由测试清理,服务已停止。

    原问题验证

    仓库随修复提供的双 CN+Proxy 公开协议验收脚本在当前 main 重复 3 次。三轮都到达最终断连步骤,说明低权限用户在 information_schema.processlist、processlist()、SHOW [FULL] PROCESSLIST、prepared 查询和角色切换后的跨用户会话可见性断言均通过;没有在这些原始权限路径再次观察到其他用户 SQL。

    但整段脚本三轮均在最终连接清理检查失败:已切换身份的普通用户执行中的 SELECT SLEEP(60) 遭客户端无 COM_QUIT 断开后,10 秒期限内后端仍在 information_schema.processlist,第 220 行报 AssertionError: disconnected backend remained alive。这不是“原 processlist 可见性又回归”的证据,而是同一验收链的未通过路径。

    Happy Path 覆盖

    1. 原跨用户可见性边界及本用户可见性、角色和 prepared 变体:每轮到达末尾断言前均通过;管理员查看进程列表及本用户控制正常。

    Unhappy Path 覆盖

    1. 无权读取其他用户运行中 SQL 的检查通过;无效用户/角色切换检查通过。
    2. 客户端在运行中断连后的清理检查 3/3 失败。另一次未切换身份的 root/Proxy 对照同样在 12.012 秒后仍见后端,提示这可能是通用断连行为;本轮未将其归因于权限过滤代码。

    白盒验证

    本轮只用真实外部协议验证;未执行新的内部 fault/race 测试,也未完成通用断连现象的代码归因。

    回归测试

    上述公开脚本整体未通过,故未将当前失败场景做成 MOTR #247 的成功 golden。完整 MOTR suite/集成 CI 未在本轮运行。

    测试证据

    • 公开协议脚本列出完整可重放夹具、断言与清理。
    • 三轮均在 session_authorization.py:220 同样失败;此前权限可见性断言均已执行,root 对照 12.012 秒仍存在。测试版本和拓扑如上。

    测试结论

    测试不通过。

  3. iamlinjunhong commented on Oct 25, 2026

    @iamlinjunhong
    ContributorAuthor

    Local verification failed: the issue still reproduces after #30928

    Verified on a local single-node build of 69bbcae (the merge commit of #30928); the server was running normally throughout.

    The comment's own-user control claim does not hold after Proxy backend cache reuse. After the visible connection ID changes from 908 to 909, the same user's KILL QUERY and KILL CONNECTION, and the administrator's KILL QUERY, all return Unknown connection id 909 while the target SLEEP(60) remains running. MO stays healthy. Fresh Proxy backends and direct-CN controls work. This does not demonstrate a regression in SQL visibility or disconnect cleanup, nor establish that PR #30928 introduced the defect.

    Steps to reproduce

    # Preconditions: current-build CN on 36001, actual MatrixOne Proxy on 26001,
    # conn-cache-enabled=true, default root password 111.
    # Retained isolated launch command from the verified repository root:
    # DYLD_LIBRARY_PATH="$PWD/cgo:$PWD/thirdparties/install/lib" GOMEMLIMIT=6GiB GOMAXPROCS=6 ./mo-service -launch "$PWD/.loom-test/launch-proxy/launch.toml" -with-proxy
    # Run the complete public-protocol reproduction below after SQL readiness.
    python3 - <<'PY'
    import contextlib, json, time
    import pymysql
    opened = []
    def connect(port, user='root'):
        c = pymysql.connect(host='127.0.0.1', port=port, user=user, password='111', autocommit=True, read_timeout=10)
        opened.append(c)
        return c
    def sql(c, statement):
        with c.cursor() as cur:
            cur.execute(statement)
            return cur.fetchall()
    admin = connect(36001)
    try:
        setup = ['drop user if exists loom_cache_low', 'drop role if exists loom_cache_role', 'drop database if exists loom_cache_db', 'create database loom_cache_db', 'create table loom_cache_db.t(a int)', 'create role loom_cache_role', 'grant connect on account * to loom_cache_role', 'grant select on table loom_cache_db.t to loom_cache_role', "create user loom_cache_low identified by '111' default role loom_cache_role"]
        for statement in setup:
            sql(admin, statement)
        assert sql(admin, 'select 1') == ((1,),)
        actor = connect(26001, 'loom_cache_low')
        warm = connect(26001, 'loom_cache_low')
        old_id = sql(warm, 'select connection_id()')[0][0]
        warm.close()  # COM_QUIT allows backend caching.
        time.sleep(.3)
        target = connect(26001, 'loom_cache_low')
        cid = sql(target, 'select connection_id()')[0][0]
        target._execute_command(3, 'select sleep(60) /* loom_cache_kill_repro */')
        lookup = f"select conn_id,user,info from information_schema.processlist where conn_id={cid} and info like '%loom_cache_kill_repro%'"
        deadline = time.monotonic() + 10
        while not sql(admin, lookup):
            assert time.monotonic() < deadline
            time.sleep(.02)
        result = {'old_id': old_id, 'new_id': cid, 'visible': sql(admin, lookup)}
        for label, c, statement in [('own_query', actor, f'kill query {cid}'), ('admin_query', admin, f'kill query {cid}'), ('own_connection', actor, f'kill connection {cid}')]:
            try:
                sql(c, statement)
                result[label] = 'OK'
            except pymysql.MySQLError as error:
                result[label] = str(error)
        result['still_running'] = sql(admin, lookup)
        result['mo_healthy'] = sql(admin, 'select 1') == ((1,),)
        print(json.dumps(result), flush=True)
        target._force_close()  # Bound the failed query's lifetime without COM_QUIT.
    finally:
        for c in opened:
            c._force_close()
        with contextlib.closing(pymysql.connect(host='127.0.0.1', port=36001, user='root', password='111', autocommit=True)) as cleanup:
            for statement in ['drop user if exists loom_cache_low', 'drop role if exists loom_cache_role', 'drop database if exists loom_cache_db']:
                sql(cleanup, statement)
    PY
    

    Expected

    同用户及管理员可按当前 connection_id() 取消目标:KILL QUERY 返回 OK 并终止查询;KILL CONNECTION 关闭目标会话。
    

    Actual

    {"old_id":908,"new_id":909,"visible":[[909,"loom_cache_low","select sleep(60) /* loom_cache_kill_repro */"]],"own_query":"(20101, 'internal error: Unknown connection id 909')","admin_query":"(20101, 'internal error: Unknown connection id 909')","own_connection":"(20101, 'internal error: Unknown connection id 909')","still_running":[[909,"loom_cache_low","select sleep(60) /* loom_cache_kill_repro */"]],"mo_healthy":true}
    
  4. XuPeng-SH commented on Oct 25, 2026

    @XuPeng-SH
    Contributor

    Fixed-pin SQL evidence for processlist visibility at 1732bb3297f598bc9a90a41b8c5e4c9557cf0e9c.

    Command: PYTHONPATH=/tmp/qa-pymysql python3 /workspace/qa-evidence-1732bb/run_gap_privilege_acceptance.py against the isolated service at 127.0.0.1:16601. A task-local sys user with only CONNECT and one table-level SELECT grant queried both processlist entrances while an admin observer confirmed connection 227 was running SELECT SLEEP(12).

    The low-privilege user's foreign-user counts were 0 in both information_schema.processlist and processlist(); querying connection 227 returned 0 rows. Its own-session control returned 1 row through both entrances. The harness exited with 0 failures and cleaned up the test user, role, and database.

    This is a single-service SQL check. It does not test the separate Proxy backend-cache/KILL behavior described in the existing comment.

  5. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main;完整 commit:5fe08a3307e246e1ab9951ab690b50557af0f509。隔离构建的 mo-service 经 go version -m 核对为该 SHA 且 vcs.modified=false,服务端 git_version() 为 5fe08a3307。
    • 对应修复:PR #30299 合入提交 95eb0f0ca39ff33af4d8d6d3e902d6609f08eff0 与 PR #30928 合入提交 69bbcae88174a017ffa1a8c9f60e8e307d6c41cf,均已核实在该官方 main 祖先链上。
    • 部署:macOS arm64、隔离本地 2 CN(直连 26101/26102)、1 TN、1 LogService、1 MatrixOne Proxy(26001),真实 PyMySQL 协议;未使用共享 TKE。日期:2026-10-26。

    原问题验证

    仓库现有 test/manual/issue30276_30278/session_authorization.py --proxy-port 26001 --cn-ports 26101 26102 连续运行 3/3 status=PASS。另一个 CN 上 root 的在途查询不再出现在低权限用户的 information_schema.processlist 或 processlist() 查询结果中;SHOW PROCESSLIST / SHOW FULL PROCESSLIST、预编译查询及角色切换后可见性都由脚本逐项断言。管理员对照仍可定位该连接。

    Happy Path 覆盖

    1. root/moadmin 能看到并控制目标连接;低权限用户仍能看自己的会话,3/3 通过。
    2. SET ROLE 降级/升级与同一连接上的 COM_CHANGE_USER 后,普通查询、预编译和多语句可见性按当前身份变化,3/3 通过。

    Unhappy Path 覆盖

    1. 无管理权限的用户从视图、表函数、SHOW 与 prepared 查询尝试读取 root 的连接和 SQL,均不可见;跨用户 KILL 被拒且目标未被取消,3/3 通过。
    2. 错误的 COM_CHANGE_USER 认证和无效角色切换不能留下 root 的旧权限;客户端在执行 SLEEP(60) 时直接 EOF、不发 COM_QUIT,切换用户与未切换 root 对照均在 10 秒内从 processlist 消失,3/3 通过。临时对象已清理。

    白盒验证

    本轮为实际双 CN+Proxy 的公开协议验收;未新增或重跑 Go UT/race,不把 PR 自带结果当作本轮执行。

    回归测试

    已把该完整协议路径加入 MOTR #278 的 issue_30276_30278_session_authorization.py。MOTR runner 在该隔离拓扑 --branch main --repeat 3:3 success、0 failed、0 skipped。完整 suite 与新提交 CI 尚未运行/核对;未向 MO 仓库提交 PR。

    测试证据

    • 固定 SHA 的原始双 CN 协议脚本:本轮 3 次均完成所有可见性、权限、断连清理断言。
    • MOTR 本地 runner 结果:/private/tmp/mo-qa-new-20261026-ROza73/motr-278/var/log/run-1792982035360182000/results.jsonl,提交 SHA ed0f538e28e9bd8aacbbbed8f8a91e42d9b42b15。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions