Skip to content

[Bug]: cp Not working as expected "as it was replaced while being copied" #27

Closed

Description

@Xinmudotmoe

Bug Description / 错误描述

xinmu-server-3c6000 ~ # ls /usr/gnemul/
arch-aarch64  lat-i386  lat-x86_64  latx-i386  latx-x86_64  qemu-riscv64  qemu-x86_64

xinmu-server-3c6000 ~ # ls -lash /usr/gnemul/
total 20K
4.0K drwxr-xr-x  5 root root 4.0K Apr  2 00:48 .
4.0K drwxr-xr-x 18 root root 4.0K Feb  6 20:59 ..
4.0K drwxr-xr-x 16 root root 4.0K Jan  8  2024 arch-aarch64
4.0K drwxr-xr-x  3 1022 1022 4.0K Oct 26  2023 lat-i386
   0 lrwxrwxrwx  1 root root   25 Mar 22 18:39 lat-x86_64 -> /usr/x86_64-pc-linux-gnu/
4.0K drwxr-xr-x  3 root root 4.0K Jan  4  2024 latx-i386
   0 lrwxrwxrwx  1 root root   24 Apr  2 00:48 latx-x86_64 -> /usr/x86_64-pc-linux-gnu
   0 lrwxrwxrwx  1 root root   31 Dec 19 14:51 qemu-riscv64 -> /usr/riscv64-unknown-linux-gnu/
   0 lrwxrwxrwx  1 root root   11 Jan  7  2024 qemu-x86_64 -> lat-x86_64/

xinmu-server-3c6000 ~ # file /usr/x86_64-pc-linux-gnu/usr/bin/cp
/usr/x86_64-pc-linux-gnu/usr/bin/cp: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

xinmu-server-3c6000 ~ # latx-x86_64 /usr/x86_64-pc-linux-gnu/usr/bin/cp a.c c.c
Lat can't find ldinfo.
cp: skipping file 'a.c', as it was replaced while being copied

xinmu-server-3c6000 ~ # qemu-x86_64 /usr/x86_64-pc-linux-gnu/usr/bin/cp a.c c.c

xinmu-server-3c6000 ~ # 

Environment / 环境

OS: Gentoo

Kernel Version: 6.14.0-rc6+
PAGESIZE: 4k

GCC Version: 15.0.1

GLIBC Version: 2.41

LAT Version / Commit Hash: df09d67

Steps to Reproduce / 重现步骤

Describe the issue in detail
在latx下,coreutils下的cp命令未按照预期行为工作

Software Information (e.g., name, version, configuration, etc.)
coreutils 9.6

Expected Behavior / 预期行为

Copy Success

Actual Behavior / 实际行为

cp: skipping file 'a.c', as it was replaced while being copied

Screenshots or Logs / 截图或日志

No response

Severity / 严重性

High / 高

Additional Information / 附加信息

No response

Activity

  1. added
    bug
    on Apr 2, 2025
  2. luzeng87 commented on Apr 2, 2025

    @luzeng87
    Contributor

    Try export LATX_KZT=0 to see if it works.

  3. LaurenIsACoder commented on Apr 2, 2025

    @LaurenIsACoder
    Contributor

    请使用 PR #29 测试看问题是否解决

  4. Xinmudotmoe commented on Apr 2, 2025

    @Xinmudotmoe
    Author

    Try export LATX_KZT=0 to see if it works.

    有差别,但没有解决

    xinmu-server-3c6000 ~ # latx-x86_64 /usr/x86_64-pc-linux-gnu/usr/bin/cp  a.c c.c
    Lat can't find ldinfo.
    cp: skipping file 'a.c', as it was replaced while being copied
    
    xinmu-server-3c6000 ~ # LATX_KZT=0 latx-x86_64 /usr/x86_64-pc-linux-gnu/usr/bin/cp  a.c c.c
    cp: skipping file 'a.c', as it was replaced while being copied
    

    请使用 PR #29 测试看问题是否解决

    同上

    xinmu-server-3c6000 ~ # latx-x86_64 /usr/x86_64-pc-linux-gnu/usr/bin/cp  a.c c.c
    Lat can't find ldinfo.
    cp: skipping file 'a.c', as it was replaced while being copied
    xinmu-server-3c6000 ~ # /media/ssd/lat-build/lat/build64/latx-x86_64 /usr/x86_64-pc-linux-gnu/usr/bin/cp  a.c c.c
    cp: skipping file 'a.c', as it was replaced while being copied

    同时,我测试了busybox的cp实现,在latx和qemu下 busybox的cp都是正常的

  5. Xinmudotmoe commented on Apr 2, 2025

    @Xinmudotmoe
    Author

    Test Cases

    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #define TESTFILE "a.out"
    
    int main() {
      struct stat first;
      struct stat second;
      stat(TESTFILE, &first);
      int source_desc = open (TESTFILE, O_RDONLY);
      fstat (source_desc, &second);
      printf("%lx  %lx\n", first.st_dev, second.st_dev);
      return 0;
    }
    xinmu-server-3c6000 ~ # gcc b.c
    xinmu-server-3c6000 ~ # file ./a.out 
    ./a.out: ELF 64-bit LSB pie executable, LoongArch, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-loongarch-lp64d.so.1, for GNU/Linux 5.19.0, not stripped
    xinmu-server-3c6000 ~ # ./a.out 
    10304  10304
    xinmu-server-3c6000 ~ # x86_64-pc-linux-gnu-gcc b.c
    xinmu-server-3c6000 ~ # file ./a.out 
    ./a.out: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, not stripped
    xinmu-server-3c6000 ~ # latx-x86_64 ./a.out 
    Lat can't find ldinfo.
    10304  304
    xinmu-server-3c6000 ~ # LATX_KZT=0 latx-x86_64 ./a.out 
    10304  304
    xinmu-server-3c6000 ~ # qemu-x86_64 ./a.out 
    10304  10304
    

    fstat与stat的结果出现了st_dev不一致的情况
    以系统环境为预期信息,qemu-x86_64与系统一致,latx-x86_64不一致

  6. LaurenIsACoder commented on Apr 5, 2025

    @LaurenIsACoder
    Contributor

    我在 loongnix20.6 系统上无法复现该问题,不知道该问题依赖的是 OS 还是内核版本?
    有没有小伙伴可以帮着测试一下其它 OS 上的现象?

    lhl@loongson-pc:~/data/lat-opensource/lat$ file a.out     
    a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=64c4f2355c068900f1ffc9371f87c5a39
    466837f, for GNU/Linux 3.2.0, not stripped
    lhl@loongson-pc:~/data/lat-opensource/lat$ ./build64-dbg/latx-x86_64 ./a.out  
    lhl-debug do_openat:11159 ret 3 dirfd -100 pathname a.out flags 0 mode 0
    2f 2f
    lhl@loongson-pc:~/data/lat-opensource/lat$ cd ..
    lhl@loongson-pc:~/data/lat-opensource$ file a.out  
    a.out: ELF 64-bit LSB executable, LoongArch-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 4.15.0, BuildID[sha1]=5b720
    307e8caf7118fee6aa76277a538f884c2ca, not stripped
    lhl@loongson-pc:~/data/lat-opensource$ ./a.out                            
    2f 2f
  7. Xinmudotmoe commented on Apr 5, 2025

    @Xinmudotmoe
    Author

    我在 loongnix20.6 系统上无法复现该问题,不知道该问题依赖的是 OS 还是内核版本? 有没有小伙伴可以帮着测试一下其它 OS 上的现象?

    lhl@loongson-pc:/data/lat-opensource/lat$ file a.out
    a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=64c4f2355c068900f1ffc9371f87c5a39
    466837f, for GNU/Linux 3.2.0, not stripped
    lhl@loongson-pc:
    /data/lat-opensource/lat$ ./build64-dbg/latx-x86_64 ./a.out
    lhl-debug do_openat:11159 ret 3 dirfd -100 pathname a.out flags 0 mode 0
    2f 2f
    lhl@loongson-pc:/data/lat-opensource/lat$ cd ..
    lhl@loongson-pc:
    /data/lat-opensource$ file a.out
    a.out: ELF 64-bit LSB executable, LoongArch-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 4.15.0, BuildID[sha1]=5b720
    307e8caf7118fee6aa76277a538f884c2ca, not stripped
    lhl@loongson-pc:~/data/lat-opensource$ ./a.out
    2f 2f

    我认为是旧内核下比bug较难复现的问题。
    在高版本内核中,st_dev的长度默认会超过2byte( 0x10304 4byte) 并且可能发生了截断问题(只保留了0x0304)
    但4.19内核返回的范围仅1byte(0x2f)

  8. LaurenIsACoder commented on Apr 10, 2025

    @LaurenIsACoder
    Contributor

    是的,确实有可能是之前修复wine的时候引入问题。不过这个 bug 的复现除了对内核版本有要求,还对机器硬件配置有要求,因为 st_dev 的值的高位取决于设备的 major 号,实验发现 nvme 的盘 major 会比较大,我得协调个符合条件的机器复现了再改。

  9. LaurenIsACoder commented on Apr 15, 2025

    @LaurenIsACoder
    Contributor

    请使用 PR #48 测试看问题是否解决

  10. Xinmudotmoe commented on Apr 15, 2025

    @Xinmudotmoe
    Author

    PASS

    xinmu-server-3c6000 /usr/x86_64-pc-linux-gnu/usr/bin # ./cp cp ._ncp
    xinmu-server-3c6000 /usr/x86_64-pc-linux-gnu/usr/bin # file cp
    cp: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions