Skip to contentSkip to conversation

coreutils: Backport fix for lseek_copy loop

PATCH In review Paul Barker 2 participants 2 messages Jan 21

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coreutils: Backport fix for lseek_copy loop

We've seen intermittent failures on the autobuilder related to creating hddimg images after updating to coreutils 9.9. The error message seen is:

install: cannot lseek '.../core-image-minimal/1.0/sources/core-image-minimal-1.0/hddimg/rootfs.img': Invalid argument

This corresponds to an invalid argument passed to lseek() in the create_hole() function in src/copy-file-data.c in coreutils. This in turn is being given bad arguments due to incorrect handling of loop variables in lseek_copy().

The upstream bug report [1] refers to an infinite loop, which isn't quite what we're seeing, but the cause is likely the same. So, we're applying the upstream fixes.

[1]: https://github.com/coreutils/coreutils/issues/159

[YOCTO #16120]

---
I've tested this several times on the autobuilder via oe-selftest-debian & oe-selftest-fedora and not hit the lseek error :)

---
 .../coreutils/0001-fix-lseek-copy-loop.patch       | 35 +++++++++++++
 .../coreutils/0002-fix-lseek-copy-loop.patch       | 58 ++++++++++++++++++++++
 meta/recipes-core/coreutils/coreutils_9.9.bb       |  2 +
 3 files changed, 95 insertions(+)
meta/recipes-core/coreutils/coreutils/0001-fix-lseek-copy-loop.patch new file +35 -0
new file mode 100644
index 000000000000..75286dc43cb9
@@ -0,0 +1,35 @@
+From bd528f923482223649aa84be7d131e69356149da Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
+Date: Sun, 4 Jan 2026 12:45:46 +0000
+Subject: [PATCH] copy: fix possible infinite loop with SEEK_HOLE
+
+Commit v9.8-95-g4c0cf3864 intended to initialize
+ext_start to src_pos, as was described at:
+https://lists.gnu.org/r/coreutils/2025-11/msg00035.html
+However ipos was inadvertently used, which is only
+valid the first time through the loop.
+
+* src/copy-file-data.c (lseek_copy): Use scan_inference->hole_start
+only with the initial offset passed to lseek_copy().
+* NEWS: Mention the bug fix.
+Reported at https://github.com/coreutils/coreutils/issues/159
+
+Upstream-Status: Backport (commit bd528f923482223649aa84be7d131e69356149da)
+  - Removed changes to NEWS as they don't apply.
+
+Signed-off-by: Paul Barker <[email protected]>
+---
+
+diff --git a/src/copy-file-data.c b/src/copy-file-data.c
+index 927a6e0480..56b669fe72 100644
+--- a/src/copy-file-data.c
++++ b/src/copy-file-data.c
+@@ -338,7 +338,7 @@ lseek_copy (int src_fd, int dest_fd, char **abuf, idx_t buf_size,
+   for (off_t ext_start = scan_inference->ext_start;
+        0 <= ext_start && ext_start < max_ipos; )
+     {
+-      off_t ext_end = (ext_start == ipos
++      off_t ext_end = (ext_start == src_pos
+                        ? scan_inference->hole_start
+                        : lseek (src_fd, ext_start, SEEK_HOLE));
+       if (0 <= ext_end)
meta/recipes-core/coreutils/coreutils/0002-fix-lseek-copy-loop.patch new file +58 -0

58 lines not on this page · raw message

meta/recipes-core/coreutils/coreutils_9.9.bb +2 -0
index cded545efb2c..7deadded062a 100644
@@ -15,6 +15,8 @@ inherit autotools gettext texinfo
 
 SRC_URI = "${GNU_MIRROR}/coreutils/${BP}.tar.xz \
            file://remove-usr-local-lib-from-m4.patch \
+           file://0001-fix-lseek-copy-loop.patch \
+           file://0002-fix-lseek-copy-loop.patch \
            file://run-ptest \
            "
 SRC_URI[sha256sum] = "19bcb6ca867183c57d77155eae946c5eced88183143b45ca51ad7d26c628ca75"

---
base-commit: c6e2bfc538258086053a569c2143ad8bc9a840bd
change-id: 20260120-fix-coreutils-edb9f37fe599

Best regards,

Signature · 1 line
Paul Barker
#1 lore raw

Hi,

On Wed Jan 21, 2026 at 11:41 AM CET, Paul Barker wrote:
[...]

Quoted 13 lines
meta/recipes-core/coreutils/coreutils/0001-fix-lseek-copy-loop.patch new file +7 -0
new file mode 100644
index 000000000000..75286dc43cb9
@@ -0,0 +1,35 @@
+From bd528f923482223649aa84be7d131e69356149da Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
+Date: Sun, 4 Jan 2026 12:45:46 +0000
+Subject: [PATCH] copy: fix possible infinite loop with SEEK_HOLE
+
+Commit v9.8-95-g4c0cf3864 intended to initialize
+ext_start to src_pos, as was described at:

meta/recipes-core/coreutils/coreutils/0001-fix-lseek-copy-loop.patch line 17

Quoted 10 lines
meta/recipes-core/coreutils/coreutils/0001-fix-lseek-copy-loop.patch new file +10 -0
+https://lists.gnu.org/r/coreutils/2025-11/msg00035.html
+However ipos was inadvertently used, which is only
+valid the first time through the loop.
+
+* src/copy-file-data.c (lseek_copy): Use scan_inference->hole_start
+only with the initial offset passed to lseek_copy().
+* NEWS: Mention the bug fix.
+Reported at https://github.com/coreutils/coreutils/issues/159
+
+Upstream-Status: Backport (commit bd528f923482223649aa84be7d131e69356149da)

I wonder if having the reason between brackets and not parenthesis is important here? That's what we document but they could interchangeable, I don't know for sure.

Antonin

Signature · 3 lines
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com