10 Star 0 Fork 15

src-openEuler / sed

 / 详情

openEuler-22.03-LTS-Next sed -f 参数中引用的文件长度超过2G时执行失败

已完成
缺陷
创建于  
2022-01-29 09:44

【标题描述】openEuler-22.03-LTS-Next sed -f 参数中引用的文件长度超过2G时执行失败
【环境信息】
输入图片说明
【问题复现步骤】
必现问题
1、创建1个大小超过2G的文件 dd if=/dev/zero bs=1M count=2049 | tr '\0' e > test.txt,有预期结果1
2、将1中创建的文件作为sed -f的参数,sed -f test.txt test_sed,有预期结果2
3、将1中创建的文件作为sed R的参数,sed Rtest.txt test_sed,有预期结果2
【预期结果】
1、文件创建成功 2、命令执行成功,不出现段错误
输入图片说明
【实际结果】
输入图片说明
【附件信息】

评论 (5)

tttttty 创建了缺陷

Hi tttttty, welcome to the openEuler Community.
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here.
If you have any questions, please contact the SIG: Base-service, and any of the maintainers: @syyhao , @BigSkySea , @Monday , @hexiaowen , @zhujianwei001 , @谢志鹏 , @chenjialong , @hanxinke , @朱春意 , @yanan-rock

openeuler-ci-bot 添加了
 
sig/Base-service
标签
ltx 里程碑设置为openEuler-22.03-LTS

1.该现象sed基于 glibc-2.2x版本执行正常; 基于glibc-2.3x 出现上述异常场景; sed 命令存在依赖库 /usr/lib64/libpthread.so.0 ,该库由glibc 提供,据此推测glibc 存在行为变更,细节原因,建议glibc侧协同分析 @tttttty 2.sed侧将基于glibc侧的反馈做进一步分析

1.sed 分析问题产生基于glibc 2.3x 版本中函数popen 存在变更 ;
2.验证示例:
2.1 dd if=/dev/zero bs=1K count=512 | tr '\0' e > test.txt
2.2 编译一下代码:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
FILE * fd_str;
FILE * fd_cmd;

char buf[524288]="0";

fd_str = open("/root/test.txt", O_RDONLY); // 注意此处填写 test.txt的绝对路径

if(NULL == fd_str)
{
    printf("debug.info: #1 pro error ...... exit \n");
}

read(fd_str, buf, sizeof(buf));

fd_cmd = popen(buf, "r");

printf("debug.info: #1 error_NUM: %m \n");
printf("debug.info: #1 fd_cmd: %p\n",fd_cmd);

if(NULL == fd_cmd)
{
    printf("debug.info: #2 pro error ...... exit \n");
}
return 0;

}
2.3 编译以上示例代码: gcc -g -o popen-test popen-test.c
3. 不同glibc版本下执行示例二进制
3.1 glibc 2.2x 版本:
[root@localhost ~]# ./popen-test
debug.info: #1 error_NUM: Success
debug.info: #1 fd_cmd: 0x3d853260
3.2 glibc 2.3x 版本:
[root@localhost ~]# ./popen-test
debug.info: #1 error_NUM: Cannot allocate memory
debug.info: #1 fd_cmd: (nil)
debug.info: #2 pro error ...... exit

  1. 本issue上 sed侧非问题, sed 侧重点关注是否引起 coredump (针对之前sed 数据溢出修复看护)
  2. 关于popen 差异问题,glibc 需进一步分析

popen返回值的差异分析:
glibc2.28使用的clone接口,该接口不对过长的入参校验,因此clone结果返回成功,但是最终应用会执行失败。
glibc 2.34优先使用clone3接口:https://sourceware.org/git/?p=glibc.git;a=commit;h=d8ea0d0168b190bdf138a20358293c939509367f

commit d8ea0d0168b190bdf138a20358293c939509367f
Author: H.J. Lu hjl.tools@gmail.com
Date: Sat Feb 13 11:47:46 2021 -0800
Add an internal wrapper for clone, clone2 and clone3

clone3系统调用在安全方面做了加固,内核实现会校验入参是否正常,因此会返回E2BIG:
输入图片说明

clone3引起的相关的差异在glibc升级issue中记录:
#I4HFNR:2203LTS glibc版本变更
输入图片说明

对于实际的功能使用的影响分析:clone在实际执行二进制文件的时候失败,clone3是在入参判断时失败,对实际应用的最终表现并无影响,而上游社区的clone3的演进则更为合理。

tttttty 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(4)
5329419 openeuler ci bot 1632792936
1
https://gitee.com/src-openeuler/sed.git
git@gitee.com:src-openeuler/sed.git
src-openeuler
sed
sed

搜索帮助