已关闭
【sentry】smh_message_get函数中存在内存泄露use-after-free问题 #9385
tong_1001创建于  6月11日关闭于  6月11日
tong_1001
6月11日 创建

环境信息

【OS版本】(如openEuler-22.03-LTS,参考命令"cat /etc/os-release"结果)
openEuler-24.03-LTS-SP4
【内核版本】(如kernel-5.10.0-60.138.0.165,参考命令"uname -r"结果)
6.6
【硬件平台】(缺陷相关的硬件信息,如:处理器型号、内存、磁盘、网卡、BIOS 等信息)
灵衢
【组网信息】(和网络、性能相关的问题,应该说明详细的组网和场景信息)

缺陷信息

【问题复现步骤】
UAF问题复现:

  1. 启动sysSentry服务
  2. 触发oom,需要触发那种不需要ack答复的oom事件类型

【实际结果】请描述出问题的结果和影响
系统会发生panic/内存泄露
【期望结果】请描述出期望的结果和影响
系统正常无报错
【其他相关附件信息】比如 syslog、dmesg、panic、lockup、kdump 信息、图片等
NA

【已分析信息】如已经做过分析和定位,请尽量附上详细的分析结果

内存泄露问题:

if (handle->ack) {
   bool found = false;

   spin_lock(&msg_ctx.msgbuf_ack_lock);
   list_for_each_entry(handle_ack, &msg_ctx.msgbuf_ack, ack_list) {
       if (handle_ack->msg.msgid == handle->msg.msgid) {
           found = true;       // ← 发现 msgbuf_ack 中已有同 msgid 的 handle
           break;
       }
   }
   if (!found)
       list_add_tail(&handle->ack_list, &msg_ctx.msgbuf_ack);
   // ← found=true 时,handle 既未 kfree 也未入链,成为孤立指针!
   spin_unlock(&msg_ctx.msgbuf_ack_lock);
} else {
   kfree(handle);
}

found = true 时(即 msgbuf_ack 中已存在相同 msgid 的 handle),代码逻辑是:

  • found = true不做任何操作,既不 kfree(handle),也不 list_add_tail
  • handle 是刚从 kfifo 中 kfifo_out_spinlocked 取出的,已经脱离了 kfifo
  • handle 没有被加入 msgbuf_ack,也没有被释放
  • handle 成为孤立指针,永远无法被回收

UAF问题:

if (handle->ack) {
   bool found = false;

   spin_lock(&msg_ctx.msgbuf_ack_lock);
   list_for_each_entry(handle_ack, &msg_ctx.msgbuf_ack, ack_list) {
       if (handle_ack->msg.msgid == handle->msg.msgid) {
           found = true;
           break;
       }
   }
   if (!found)
       list_add_tail(&handle->ack_list, &msg_ctx.msgbuf_ack);
   spin_unlock(&msg_ctx.msgbuf_ack_lock);
} else {
   kfree(handle);
}

// handle->ack为false时,内存已在前面的else分支释放
return sizeof(handle->msg);  

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

缺陷严重等级:(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-bot成员
6月11日 添加了label:sig/Kernel
openeuler-ci-bot
openeuler-ci-bot成员
6月11日 评论:

Welcome To openEuler Community

Hey @tong_1001 , 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, @wkfxxx, @zeng_zhaorong ,
and any of the committers: @CTC-XiboWang, @Frank_Sae, @GongLei-, @LiuYongQiang0816, @SuperSix173, @Tankll2021, @TrueAI, @allen-shi, @baratta, @caixu-blue, @chen-jun-hw, @chenjiesong, @chenjunxin1992, @chenke2026, @chiqijun, @chriszjh, @duanqiangwen, @fangfeng123, @fanghaiqinghw, @gaojuxin09, @gouhao2022, @guzitao, @hanjunguo, @hanliyang, @hellotcc, @henryze, @hewanhan, @hjx_gitff, @hongbo-lee, @hongwu-wang, @htforge, @hu-chunzhi, @hunan4222, @jackknight, @jerry_lilijun, @jiayi0118, @junlong-zheng, @juntianlinux, @kailiu42, @kaitiandu, @kazero00, @kevinzhu1, @kile2009, @koishimind, @kongzizaixian, @kylin-mayukun, @leoliu-oc, @li-huisong, @linan888, @linyunsheng, @liulongfang, @liyihang0226, @lostway1, @lujialin2, @markyuan4ta21, @mingqian218472, @mingrui-liu, @mufengyan, @pigalsofine, @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-bot成员
6月11日 issue状态由 已挂起 改变为 待办的
openeuler-ci-bot
openeuler-ci-bot成员
6月11日 评论:

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


/reason xxxxxx

likedislike
openeuler-ci-botopeneuler-ci-bot成员
6月11日 将 allen-shi 设为负责人
openeuler-ci-botopeneuler-ci-bot成员
6月11日 修改了issue 的描述
openeuler-ci-bot
openeuler-ci-bot成员
6月11日 评论:

以下的要求不是强制性的, 未按模板评论时对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-bot成员
6月11日 添加了label:DEFECT/UNFIXED
Ttong_1001
6月11日 关联了pull request:drivers/ub/sentry: fix memory leak and use-after-free in smh_message_get()
tong_1001
6月11日 评论:

/assign

likedislike
openeuler-ci-botopeneuler-ci-bot成员
6月11日 将 tong_1001 设为负责人,移除负责人 allen-shi
openeuler-ci-botopeneuler-ci-bot成员
6月11日 关闭了 issue
openeuler-ci-botopeneuler-ci-bot成员
6月11日 issue状态由 待办的 改变为 已完成
openeuler-ci-botopeneuler-ci-bot成员
6月11日 删除了label:DEFECT/UNFIXED
openeuler-ci-bot
openeuler-ci-bot成员
6月11日 评论:

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

likedislike