0-byte files created in overlay filesystem

Bug #1953199 reported by Stan Hu
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux-base (Ubuntu)
New
Undecided
Unassigned

Bug Description

Copied from https://lore.kernel<email address hidden>/:

A number of users have reported that under certain conditions using
the overlay filesystem, copy_file_range() can unexpectedly create a
0-byte file. [0]

This bug can cause significant problems because applications that copy
files expect the target file to match the source immediately after the
copy. After upgrading from Linux 5.4 to Linux 5.10, our Docker-based
CI tests started failing due to this bug, since Ruby's IO.copy_stream
uses this system call. We have worked around the problem by touching
the target file before using it, but this shouldn't be necessary.
Other projects, such as Rust, have added similar workarounds. [1]

As discussed in the linux-fsdevel mailing list [2], the bug appears to
be present in Linux 5.6 to 5.10, but not in Linux 5.11. We should be
able to cherry-pick the following upstream patches to fix this. Could
you cherry-pick them to 5.10.x stable? I've confirmed that these
patches, applied from top to bottom to that branch, pass the
reproduction test [3]:

82a763e61e2b601309d696d4fa514c77d64ee1be
9b91b6b019fda817eb52f728eb9c79b3579760bc

The diffstat:

 fs/overlayfs/file.c | 59
+++++++++++++++++++++++++++++++----------------------------
 1 file changed, 31 insertions(+), 28 deletions(-)

Note that these patches do not pick cleanly into 5.6.x - 5.9.x stable.

[0] https://github.com/docker/for-linux/issues/1015
[1] https://github.com/rust-lang/rust/blob/342db70ae4ecc3cd17e4fa6497f0a8d9534ccfeb/library/std/src/sys/unix/kernel_copy.rs#L565-L569
[2] https://marc.info/?l=linux-fsdevel&m=163847383311699&w=2
[3] https://github.com/docker/for-linux/issues/1015#issuecomment-841915668

---

I reproduced this bug in Ubuntu 18.04:

```
# bash test.sh
Sending build context to Docker daemon 43.05kB
Step 1/2 : FROM debian:10.8-slim
 ---> 115566c891d1
Step 2/2 : RUN apt update && apt install -y gcc strace
 ---> Using cache
 ---> 0dfb7ffcd427
Successfully built 0dfb7ffcd427
Successfully tagged strace:latest

Local:
OK

Docker - mounted:
Copy failed

Docker - copied:
OK
```

```
root@stanhu-ubuntu-18:/home/stanhu# lsb_release -rd
Description: Ubuntu 18.04.6 LTS
Release: 18.04
root@stanhu-ubuntu-18:/home/stanhu# uname -r
5.4.0-1057-gcp
```

Per [the latest update on the kernel stable mailing list](https://<email address hidden>), the kernel backport fix for 5.10 has been queued for review and should land in the [`stable-5.10.y` branch](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y) soon.

To avoid this bug, I'd suggest avoid Linux v5.6.0 - v5.10.83 for now, unless you backport the two patches below:

1. https://github.com/torvalds/linux/commit/@82a763e61e2b601309d696d4fa514c77d64ee1be
1. https://github.com/torvalds/linux/commit/@9b91b6b019fda817eb52f728eb9c79b3579760bc

I've confirmed that 5.5.19 does NOT have this bug, and it was introduced in 5.6.0 via https://github.com/torvalds/linux/commit/1a980b8cbf0059a5308eea61522f232fd03002e2.

Revision history for this message
Stan Hu (stanhu) wrote (last edit ):

* Ubuntu 18.04.6 LTS appears affected.
* Ubuntu 20.04.3 LTS does NOT appear affected with the Linux 5.11 kernel (HWE).

affects: linux (Ubuntu) → linux-base (Ubuntu)
Revision history for this message
Pete Woods (pete-woods) wrote :
Revision history for this message
Stan Hu (stanhu) wrote :

Yes.

It's worth checking Ubuntu 20.04. 20.04.3 seems to have upgraded to kernel 5.11, but I'm not sure if this is just because it's the HWE version.

Revision history for this message
Stan Hu (stanhu) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers