Closed
pam_time/pam_group:is_same() 通配符后缀匹配存在越界读 #74
Lei-ChenAdd on  9 days agoClosed at  7 days ago
Lei-Chen
9 days ago Create

问题描述

pam_time 与 pam_group 各自实现了一份静态函数 is_same(),用于把 /etc/security/time.conf、/etc/security/group.conf 中的规则字段与运行期实际值(service/tty/user)做通配符匹配。

当配置字段形如 *admin(通配符后带后缀)且运行期字符串比后缀更短时,is_same() 以

return (!--len || !strncmp(b+i, a+strlen(a)-len, len));

计算后缀指针 a + strlen(a) - len。此时 strlen(a) < len,指针越过缓冲区起始位置向前下溢,随后的 strncmp() 会读取分配块之前的堆内存,属于越界读(CWE-125)。

同一缺陷在 pam_time、pam_group 两处独立存在。

影响范围

  • 软件包:pam 1.5.3(openEuler master / openEuler-26.09 / openEuler-24.03-LTS 全系列均受影响,已逐一确认)
  • 触发条件:管理员在 time.conf / group.conf 中配置了带后缀的通配符字段(如 *admin),普通用户登录或使用对应服务时即触发;配置文件本身仅 root 可写,因此属于本地、需特定配置的缺陷,但一次越界读可能造成崩溃或信息泄露(取决于 strncmp 比较位置与堆布局)。
  • 上游未分配 CVE 编号(非 CVE 安全缺陷)。

复现

以 pam_time 为例:运行期用户名为 bob,配置字段为 *admin,则 logic_field() 以 is_same(NULL, "bob", "*admin", 6, 1) 调用。

把分支源码(打完现有补丁链)中的 is_same() 原样抽出,用 ASan 编译并以上述参数调用:

==22548==ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 1 at 0x60200000000e thread T0
    #0 ... in __interceptor_strncmp
    #1 ... in is_same is_same.inc:11
0x60200000000e is located 2 bytes to the left of 4-byte region

修复后同一用例正常返回 0(不匹配),不再越界;*admin 对 bobadmin 仍返回 1,普通精确匹配行为不变,make check 全部通过。

修复方案

上游 linux-pam 已修复(无 CVE 号):

修复方式:先判断运行期字符串长度是否不小于后缀长度,不足则直接返回 FALSE,再做指针减法与 strncmp()。

openEuler 侧进展

已按上游提交生成两个 openEuler 风格回移补丁(backport-pam_time-fix-out-of-bounds-read-in-is_same.patch、backport-pam_group-fix-out-of-bounds-read-in-is_same.patch),并在以下分支验证「完整补丁链 + 新补丁」全部 -F0 干净应用、全量构建与 make check 通过:

  • openEuler-24.03-LTS-SP3(代表分支,Release 1.5.3-13,Patch43/44)
  • master(Release 1.5.3-15,Patch45/46)
  • openEuler-26.09(与 master 同源同内容,单独提 PR)

openEuler-24.03-LTS、-Next、-SP1、-SP2、-SP4 经逐分支验证同样受影响(打完现有补丁链后目标文件 blob 与上游脆弱版本一致、修复标记计数为 0、新补丁可干净应用),将通过 SP3 代表 PR 的 /sync 同步。

是否 CVE

否。上游未为此缺陷分配 CVE,本 issue 不使用 CVE/UNFIXED 标签。

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

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

缺陷根因说明:

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

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

likedislike
LLei-Chen
9 days ago Added label: DEFECT/UNFIXED,sig/sig-security-facility
openeuler-ci-botopeneuler-ci-botCollaborators
9 days ago Assign houmingyong as responsible person
openeuler-ci-botopeneuler-ci-botCollaborators
9 days ago Modify description of issue
openeuler-ci-botopeneuler-ci-botCollaborators
9 days ago Assign robertosassu、zhujianwei001、mailofzxf、hello-leichen as responsible person
openeuler-ci-bot
openeuler-ci-botCollaborators
9 days ago 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-SP4:
  3. openEuler-24.03-LTS-SP1:
  4. openEuler-24.03-LTS-SP3:
  5. openEuler-24.03-LTS-SP4:

abi变化(是/否):

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

缺陷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-bot
openeuler-ci-botCollaborators
9 days ago Comments:

Welcome To openEuler Community

Hey @hello-leichen , 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. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: sig-security-facility ,
and any of the maintainers: @mailofzxf, @robertosassu, @zhujianwei001 ,
and any of the committers: @houmingyong .

likedislike
LLei-Chen
9 days ago Associated pull request
LLei-Chen
9 days ago Associated pull request
LLei-Chen
9 days ago Associated pull request
Lei-Chen
9 days ago Comments:

已提交 PR:

其余 24.03 分支(LTS、LTS-Next、SP1、SP2、SP4)已确认受影响,已通过 SP3 PR 的 /sync 排队同步。

影响性分析说明: pam_time / pam_group 的 is_same() 在配置字段形如 "*admin" 且运行期字符串短于后缀时,a + strlen(a) - len 指针下溢,strncmp() 越界读取堆内存。

缺陷严重等级: High

缺陷根因说明: 通配符后缀匹配未校验运行期字符串长度,导致指针下溢和越界读。

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

  1. openEuler-20.03-LTS-SP4: 受影响(本次未提交 PR,后续单独回移)
  2. openEuler-22.03-LTS-SP4: 受影响(本次未提交 PR,后续单独回移)
  3. openEuler-24.03-LTS: 受影响(由 SP3 PR /sync 同步)
  4. openEuler-24.03-LTS-Next: 受影响(由 SP3 PR /sync 同步)
  5. openEuler-24.03-LTS-SP1: 受影响(由 SP3 PR /sync 同步)
  6. openEuler-24.03-LTS-SP2: 受影响(由 SP3 PR /sync 同步)
  7. openEuler-24.03-LTS-SP3: 受影响(PR #194)
  8. openEuler-24.03-LTS-SP4: 受影响(由 SP3 PR /sync 同步)
  9. openEuler-26.09: 受影响(PR #195)
  10. master: 受影响(PR #196)

abi变化(是/否):

  1. openEuler-20.03-LTS-SP4: 否
  2. openEuler-22.03-LTS-SP4: 否
  3. openEuler-24.03-LTS: 否
  4. openEuler-24.03-LTS-Next: 否
  5. openEuler-24.03-LTS-SP1: 否
  6. openEuler-24.03-LTS-SP2: 否
  7. openEuler-24.03-LTS-SP3: 否
  8. openEuler-24.03-LTS-SP4: 否
  9. openEuler-26.09: 否
  10. master: 否
likedislike
Lei-Chen
9 days ago Comments:

/check-issue

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
9 days ago Removed responsible person houmingyong、zhujianwei001、mailofzxf、hello-leichen
openeuler-ci-bot
openeuler-ci-botCollaborators
9 days ago Comments:

@robertosassu 经过defect-manager解析,已分析的内容如下表所示:

状态 需分析 内容
已分析 1.影响性分析说明 pam_time/pam_group的is_same()在配置字段形如"*admin"且运行期字符串短于后缀时,a+strlen(a)-len指针下溢,strncmp()越界读取堆内存。
已分析 2.缺陷严重等级 High
已分析 3.缺陷根因定位 通配符后缀匹配未校验运行期字符串长度,导致指针下溢和越界读。
已分析 4.受影响版本排查 openEuler-20.03-LTS-SP4:受影响,openEuler-22.03-LTS-SP4:受影响,openEuler-24.03-LTS:受影响,openEuler-24.03-LTS-Next:受影响,openEuler-24.03-LTS-SP1:受影响,openEuler-24.03-LTS-SP2:受影响,openEuler-24.03-LTS-SP3:受影响,openEuler-24.03-LTS-SP4:受影响,openEuler-26.09:受影响
已分析 5.abi变化 openEuler-20.03-LTS-SP4:否,openEuler-22.03-LTS-SP4:否,openEuler-24.03-LTS:否,openEuler-24.03-LTS-Next:否,openEuler-24.03-LTS-SP1:否,openEuler-24.03-LTS-SP2:否,openEuler-24.03-LTS-SP3:否,openEuler-24.03-LTS-SP4:否,openEuler-26.09:否

请确认分析内容的准确性,确认无误后,您可以进行后续步骤,否则您可以继续分析

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
8 days ago Associated pull request
5 event messages are collapsed here。 See more
Hhugel
7 days ago Associated pull request
hugel
7 days ago Comments:

/close

likedislike
openeuler-ci-bot
openeuler-ci-botCollaborators
7 days ago Comments:

Notice

@hugel , you can't close an issue unless you are the author of it or a collaborator.

likedislike
hugel
7 days ago Comments:

/check-issue

likedislike
HhoumingyongCollaborators
7 days ago changed custom state from 待办的 to 已完成
HhoumingyongCollaborators
7 days ago Close issue
openeuler-ci-botopeneuler-ci-botCollaborators
7 days ago Added label: DEFECT/FIXED; Removed label: DEFECT/UNFIXED,sig/sig-security-facility