Closed
【OLK-6.6】UBASE mailbox reference count & UDMA use unified mailbox interface #9008
mufengyanAdd on  Apr 22Closed at  Apr 23
mufengyan
mufengyanCollaborators
Apr 22 Create

环境信息

【OS版本】(如openEuler-22.03-LTS,参考命令"cat /etc/os-release"结果)
openEuler-24.03-LTS-SP3
【内核版本】(如kernel-5.10.0-60.138.0.165,参考命令"uname -r"结果)

【硬件平台】(缺陷相关的硬件信息,如:处理器型号、内存、磁盘、网卡、BIOS 等信息)

【组网信息】(和网络、性能相关的问题,应该说明详细的组网和场景信息)

缺陷信息

UBASE mailbox DMA 内存存在 use-after-free 风险。当 UDMA 通过 mailbox 向芯片发送 DMA 内存后,如果在超时时间内未收到 AE(Async Event)响应,UDMA 会先行释放该 DMA 内存。此时芯片可能仍在访问这块内存,导致不可预期的硬件行为或内核崩溃。

影响范围

  • 模块:UBASE、UDMA、UNIC
  • 触发条件:mailbox AE 事件响应超时
  • 严重级别:中(内存安全 + 硬件稳定性)

根因分析

  1. mailbox 生命周期管理缺失:UDMA 自行分配和释放 mailbox DMA 内存,与 UBASE 的 AE 事件处理不同步
  2. 竞态窗口:UDMA 超时释放 ↔ 芯片仍在使用 ↔ AE 事件到达,三者无同步机制
  3. 次要问题:drivers/net/ub/unic/unic_ip.c 在持有 spinlock 时使用 GFP_KERNEL 分配内存,违反不可睡眠上下文规则

修复方案

Patch 1: UBASE 引入 mailbox 引用计数

  • 在 struct ubase_cmd_mailbox 中新增 atomic_t count
  • UDMA 请求 mailbox 时 refcount = 1
  • mailbox 发出时 refcount++,保存 DMA 内存引用
  • UDMA 释放 或 AE 事件到达时各自 refcount--
  • refcount 归零才调用 dma_pool_free() 真正释放

Patch 2: UDMA 移除自建 mailbox 管理

  • 删除 udma_alloc_cmd_mailbox() / udma_free_cmd_mailbox() 的实现
  • 改为 inline 包装调用 ubase 统一接口
  • 由 UBASE 全权管理 mailbox 生命周期

附带修复

  • unic_ip.c: spinlock 内 GFP_KERNEL → GFP_ATOMIC
  • 新增 tracepoint:ubase_free_mailbox_user/self, ubase_alloc_mailbox_user, ubase_add_mailbox_count

二、缺陷分析结构反馈
影响性分析说明:

缺陷严重等级:(Critical/High/Moderate/Low)

缺陷根因说明:

受影响版本排查(受影响/不受影响):
openEuler-20.03-LTS-SP4
openEuler-22.03-LTS-SP3
openEuler-22.03-LTS-SP4
openEuler-24.03-LTS
openEuler-24.03-LTS-SP1
openEuler-24.03-LTS-SP2

修复是否涉及abi变化(是/否):
openEuler-20.03-LTS-SP4
openEuler-22.03-LTS-SP3
openEuler-22.03-LTS-SP4
openEuler-24.03-LTS
openEuler-24.03-LTS-SP1
openEuler-24.03-LTS-SP2

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 22 Added label: sig/Kernel
openeuler-ci-bot
openeuler-ci-botCollaborators
Apr 22 Comments:

Welcome To openEuler Community

Hey @mufengyan , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: Kernel ,
and any of the maintainers: @hanjunguo, @oekernel, @sanglipeng, @zeng_zhaorong, @zhengzengkai ,
and any of the committers: @CTC-XiboWang, @Frank_Sae, @GongLei-, @LiuYongQiang0816, @SuperSix173, @Tankll2021, @TrueAI, @allen-shi, @baratta, @caixu-blue, @chenjiesong, @chenjunxin1992, @chenke2026, @chiqijun, @chriszjh, @duanqiangwen, @fangfeng123, @fanghaiqinghw, @gaojuxin09, @gouhao2022, @guzitao, @hanjunguo, @hanliyang, @hellotcc, @hewanhan, @hjx_gitff, @hongwu-wang, @htforge, @hu-chunzhi, @hunan4222, @jackknight, @jerry_lilijun, @junlong-zheng, @juntianlinux, @kailiu42, @kaitiandu, @kazero00, @kevinzhu1, @kile2009, @koishimind, @kongzizaixian, @kylin-mayukun, @leoliu-oc, @li-huisong, @linan888, @linyunsheng, @liulongfang, @lostway1, @luckky7, @lujialin2, @markyuan4ta21, @mingqian218472, @mufengyan, @pigalsofine, @qinirao, @robinorg, @rock_hw, @sanglipeng, @shu-shengming, @shuaijiakun, @sming56_admin, @stavewu, @stkid, @wangboe2022, @wenzhiwei11, @whoisxxx, @wkfxxx, @woqidaideshi, @wsoydl, @xingmz1, @xukuohai, @yeweihua999, @ygn-ndwd-official, @yonghu_4dc5, @young-sun, @yuehaibing_planb, @yuzenghui1, @zhang-changzhong, @zhangyi089, @zhujianwei001, @zichengqu, @zqiao216 .

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 22 changed custom state from 已挂起 to 待办的
openeuler-ci-bot
openeuler-ci-botCollaborators
Apr 22 Comments:

@
issue变更为 [已取消/已挂起] 状态前,请操作者填写相关原因
请按如下格式评论原因后,重新进行操作


/reason xxxxxx

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 22 Assign allen-shi as responsible person
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 22 Modify description of issue
openeuler-ci-bot
openeuler-ci-botCollaborators
Apr 22 Comments:

以下的要求不是强制性的, 未按模板评论时对issue无任何影响
issue处理注意事项:
1. 当前issue受影响的分支提交pr时, 须在pr描述中填写当前issue编号进行关联, 否则无法关闭当前issue;
2. 模板内容需要填写完整, 无论是受影响或者不受影响都需要填写完整内容,未引入的分支不需要填写, 否则无法关闭当前issue;
3. 以下为模板中需要填写完整的内容, 请复制到评论区回复, 注: 内容的标题名称(影响性分析说明, 缺陷严重等级, 受影响版本排查(受影响/不受影响), 修复是否涉及abi变化(是/否))不能省略,省略后defect-manager将无法正常解析填写内容.
评论区可能使用到的指令说明:

指令 指令说明 使用权限
/check-issue 触发defect-manager校验 不限
/reason xxx /reason +挂起或取消条件 不限

影响性分析说明:

缺陷严重等级:(Critical/High/Moderate/Low)

缺陷根因说明:

受影响版本排查(受影响/不受影响):

  1. openEuler-20.03-LTS-SP4:
  2. openEuler-22.03-LTS-SP3:
  3. openEuler-22.03-LTS-SP4:
  4. openEuler-24.03-LTS:
  5. openEuler-24.03-LTS-SP1:
  6. openEuler-24.03-LTS-SP2:

abi变化(是/否):

  1. openEuler-20.03-LTS-SP4:
  2. openEuler-22.03-LTS-SP3:
  3. openEuler-22.03-LTS-SP4:
  4. openEuler-24.03-LTS:
  5. openEuler-24.03-LTS-SP1:
  6. openEuler-24.03-LTS-SP2:

缺陷issue处理具体操作请参考:
https://atomgit.com/openeuler/cve-manager/blob/master/cve-vulner-manager/doc/md/defect-manager-manual.md
pr关联issue具体操作请参考:
https://docs.atomgit.com/docs/help/home/org_project/pullrequests/pr-related-issue

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 22 Added label: DEFECT/UNFIXED
mufengyanmufengyanCollaborators
Apr 22 Associated pull request
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 23 Close issue
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 23 changed custom state from 待办的 to 已完成
openeuler-ci-botopeneuler-ci-botCollaborators
Apr 23 Removed label: DEFECT/UNFIXED
openeuler-ci-bot
openeuler-ci-botCollaborators
Apr 23 Comments:

@allen-shi 未对受影响版本排查/abi变化进行分析

likedislike
close-shuleiclose-shulei
Apr 26 Associated pull request
zhawenruizhawenrui
Apr 26 Associated pull request