Bug 12341

Summary: cpio is broken on encrypted ext4
Product: Busybox Reporter: David Heidelberg (okias) <david>
Component: Standard ComplianceAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs, david
Priority: P5    
Version: 1.31.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: busybox-1.31.1
cpio_strace.log
strace_log_damanaged-busybox_cpio.txt

Description David Heidelberg (okias) 2019-11-22 20:18:22 UTC
busybox cpio generate invalid archive.

Reproduction script, with dataset in archive.
Comment 1 David Heidelberg (okias) 2019-11-22 20:19:35 UTC
Archive with "test suite" just run shell script. Good and bad files will be generated (busybox cpio and cpio):

https://ufile.io/inz57nv9
Comment 2 David Heidelberg (okias) 2019-11-22 20:22:50 UTC
$  ./TEST_case.sh 
Running correct unpack
27049 blocks
Running damaged unpack
cpio: warning: skipped 9408 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 91828 bytes of junk
cpio: warning: skipped 75008 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 5268 bytes of junk
cpio: warning: skipped 620000 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 1084136 bytes of junk
cpio: warning: skipped 144 bytes of junk
cpio: warning: skipped 160 bytes of junk
cpio: warning: skipped 164 bytes of junk
cpio: warning: skipped 969948 bytes of junk
cpio: warning: skipped 17708 bytes of junk
cpio: warning: skipped 148 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 152 bytes of junk
cpio: warning: skipped 301076 bytes of junk
cpio: warning: skipped 148 bytes of junk
cpio: warning: skipped 38236 bytes of junk
cpio: warning: skipped 165224 bytes of junk
cpio: warning: skipped 140 bytes of junk
cpio: warning: skipped 144 bytes of junk
cpio: warning: skipped 350556 bytes of junk
cpio: warning: skipped 140 bytes of junk
cpio: warning: skipped 280428 bytes of junk
27049 blocks
Comment 3 Denys Vlasenko 2019-11-23 15:58:20 UTC
Can't reproduce: my busybox created a cpio which unpacks to exactly the same files as dataset/*

Please post your .config file
Comment 4 David Heidelberg (okias) 2019-11-23 21:47:39 UTC
Created attachment 8296 [details]
busybox-1.31.1
Comment 5 David Heidelberg (okias) 2019-11-23 21:50:48 UTC
My machine is amd64, kernel 5.3.
Reproducible on
- my main system with Gentoo 
- with alpine (postmarketOS) in chroot running inside.
Comment 6 David Heidelberg (okias) 2019-11-24 21:31:27 UTC
So, I tested on different EXT4 partition and it also worked just fine.

Since my parition is encrypted with CONFIG_FS_ENCRYPTION=y (e4crypt, but also  fscrypt utility can be used), they're 
- incorrectly packed with busybox cpio
- correctly packed with standalone cpio

So, can be reproduced only on encrypted EXT4 filesystem. Also I'd like to say, that I didn't encounter any issue and using this setup for long time, so I presume, that filesystem with encryption probably working correctly.

My guess is busybox cpio incorrectly grab encrypted data?
Comment 7 David Heidelberg (okias) 2019-11-24 22:38:10 UTC
Reproducing:

# dd if=/dev/zero bs=4K count=100000 of=/tmp/filesystem
# losetup /dev/loop1 /tmp/filesystem
# mkfs.ext4 -O encrypt -b 4096 /dev/loop1
# mkdir -p /mnt/test
# mount /dev/loop1 /mnt/test
# mkdir /mnt/test/a
# cd /mnt/test
# e4crypt add_key a # choose random password
# cd a
unpack archive into /mnt/test/a
# ./TEST_case.sh

100% reproducible. Tested on animals.
Comment 8 Denys Vlasenko 2019-11-29 17:26:33 UTC
There should be no way for cpio to know that it's on an encrypted fs.

I suggest running the same cpio invocation under strace, on the same set of files, once on unencrypted fs, second time on the encrypted fs. A-la:

strace -o CPIO_GOOD.log -f -s99 cpio ....

and then compare the resulting logs line-by-line, to see where things start to diverge. If you don't find the problem this way, attach strace logs to this bug.
Comment 9 David Heidelberg (okias) 2019-12-14 14:03:25 UTC
Created attachment 8321 [details]
cpio_strace.log

no difference between strace on encrypted and unencrypted fs.
Comment 10 David Heidelberg (okias) 2020-03-04 10:19:02 UTC
Created attachment 8386 [details]
strace_log_damanaged-busybox_cpio.txt

reupload testcase: https://ufile.io/59z7axpw

I tried to do strace between busybox and cpio. It seems like cpio works with encrypted data differently. Due to filesize limit, good cpio log is here: https://ufile.io/7o8g032i
Comment 11 David Heidelberg (okias) 2020-03-09 10:24:10 UTC
Can debug this issue from different angle? Or if you're sure it's kernel bug, I'll fill bug at bugzilla.kernel.org .

Thank you
Comment 12 David Heidelberg (okias) 2020-03-18 20:51:54 UTC
Kindly reminder, can you give me a hand on this issue please? Thank you
Comment 13 David Heidelberg (okias) 2020-03-29 22:03:26 UTC
Hello, is there anything more I can do about this issue?
Comment 14 David Heidelberg (okias) 2020-05-18 11:54:00 UTC
Can I supply any more useful debug informations? Thank you
Comment 15 David Heidelberg (okias) 2020-05-25 12:35:01 UTC
Hello, is there anything more I can do about this issue?
Comment 16 David Heidelberg (okias) 2020-06-08 11:00:44 UTC
Issue is still valid, is there anyone interested in fixing it?