diff --git a/backport-cksum-consistently-validate-length-attributes.patch b/backport-cksum-consistently-validate-length-attributes.patch new file mode 100644 index 0000000000000000000000000000000000000000..5f337342a859473394204ccd0d471d73be201951 --- /dev/null +++ b/backport-cksum-consistently-validate-length-attributes.patch @@ -0,0 +1,64 @@ +From fea833591ba787b1232d13ac4b985bea1e7601de Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?P=C3=A1draig=20Brady?=
+Date: Mon, 4 Mar 2024 16:33:23 +0000
+Subject: [PATCH] cksum: consistently validate --length attributes
+
+* src/digest.c (main): Only validate the last used --length
+for being a multiple of 8.
+* tests/cksum/b2sum.sh: Add a test case.
+Fixes https://bugs.gnu.org/69546
+
+Reference:https://github.com/coreutils/coreutils/commit/fea833591ba787b1232d13ac4b985bea1e7601de
+Conflict:NA
+
+---
+ src/digest.c | 10 +++++-----
+ tests/cksum/b2sum.sh | 4 ++++
+ 2 files changed, 9 insertions(+), 5 deletions(-)
+
+diff --git a/src/digest.c b/src/digest.c
+index 0d82eb6b4..96b811b6c 100644
+--- a/src/digest.c
++++ b/src/digest.c
+@@ -1397,11 +1397,6 @@ main (int argc, char **argv)
+ digest_length = xdectoumax (optarg, 0, UINTMAX_MAX, "",
+ _("invalid length"), 0);
+ digest_length_str = optarg;
+- if (digest_length % 8 != 0)
+- {
+- error (0, 0, _("invalid length: %s"), quote (digest_length_str));
+- error (EXIT_FAILURE, 0, _("length is not a multiple of 8"));
+- }
+ break;
+ #endif
+ #if !HASH_ALGO_SUM
+@@ -1476,6 +1471,11 @@ main (int argc, char **argv)
+ error (EXIT_FAILURE, 0,
+ _("--length is only supported with --algorithm=blake2b"));
+ # endif
++ if (digest_length % 8 != 0)
++ {
++ error (0, 0, _("invalid length: %s"), quote (digest_length_str));
++ error (EXIT_FAILURE, 0, _("length is not a multiple of 8"));
++ }
+ if (digest_length > BLAKE2B_MAX_LEN * 8)
+ {
+ error (0, 0, _("invalid length: %s"), quote (digest_length_str));
+diff --git a/tests/cksum/b2sum.sh b/tests/cksum/b2sum.sh
+index cc480a478..43a62d2fb 100755
+--- a/tests/cksum/b2sum.sh
++++ b/tests/cksum/b2sum.sh
+@@ -65,6 +65,10 @@ returns_ 1 $prog -c crash.check || fail=1
+ printf '0A0BA0' > overflow.check || framework_failure_
+ returns_ 1 $prog -c overflow.check || fail=1
+
++# This would fail before coreutil-9.4
++# Only validate the last specified, used length
++$prog -l 123 -l 128 /dev/null || fail=1
++
+ done
+
+ Exit $fail
+--
+2.43.0
+
diff --git a/backport-head-off_t-not-uintmax_t-for-file-offset.patch b/backport-head-off_t-not-uintmax_t-for-file-offset.patch
new file mode 100644
index 0000000000000000000000000000000000000000..421a129d559c3e57bbf64118013f10b67db7f7da
--- /dev/null
+++ b/backport-head-off_t-not-uintmax_t-for-file-offset.patch
@@ -0,0 +1,28 @@
+From 0f9e2719e0dd2366f0381daa832f9415f3162af2 Mon Sep 17 00:00:00 2001
+From: Paul Eggert
+Date: Tue, 19 Mar 2024 15:55:18 +0000
+Subject: [PATCH] maint: basenc: consistently check buffer bounds when encoding
+
+* src/basenc.c (base16_encode, base2msbf_encode, base2lsbf_encode):
+Ensure we don't overflow the output buffer, whose length is
+passed in the OUTLEN parameter. This issue was flagged by clang
+with -Wunused-but-set-parameter.
+
+Reference:https://github.com/coreutils/coreutils/commit/a46f34bb56d545369a6b1321c2d78ac08b676c06
+Conflict:Adapt to context.
+
+---
+ src/basenc.c | 10 +++++++---
+ 1 file changed, 7 insertions(+), 3 deletions(-)
+
+diff --git a/src/basenc.c b/src/basenc.c
+index f4ca872..a3f89da 100644
+--- a/src/basenc.c
++++ b/src/basenc.c
+@@ -508,12 +508,14 @@ static void
+ base16_encode (char const *restrict in, idx_t inlen,
+ char *restrict out, idx_t outlen)
+ {
+- while (inlen--)
++ while (inlen && outlen)
+ {
+ unsigned char c = *in;
+ *out++ = base16[c >> 4];
+ *out++ = base16[c & 0x0F];
+ ++in;
++ inlen--;
++ outlen -= 2;
+ }
+ }
+
+@@ -784,7 +786,7 @@ inline static void
+ base2msbf_encode (char const *restrict in, idx_t inlen,
+ char *restrict out, idx_t outlen)
+ {
+- while (inlen--)
++ while (inlen && outlen)
+ {
+ unsigned char c = *in;
+ for (int i = 0; i < 8; i++)
+@@ -792,6 +794,7 @@ base2msbf_encode (char const *restrict in, idx_t inlen,
+ *out++ = c & 0x80 ? '1' : '0';
+ c <<= 1;
+ }
++ inlen--;
+ outlen -= 8;
+ ++in;
+ }
+@@ -801,7 +804,7 @@ inline static void
+ base2lsbf_encode (char const *restrict in, idx_t inlen,
+ char *restrict out, idx_t outlen)
+ {
+- while (inlen--)
++ while (inlen && outlen)
+ {
+ unsigned char c = *in;
+ for (int i = 0; i < 8; i++)
+@@ -809,6 +812,7 @@ base2lsbf_encode (char const *restrict in, idx_t inlen,
+ *out++ = c & 0x01 ? '1' : '0';
+ c >>= 1;
+ }
++ inlen--;
+ outlen -= 8;
+ ++in;
+ }
+--
+2.33.0
+
diff --git a/backport-pinky-fix-string-size-calculation.patch b/backport-pinky-fix-string-size-calculation.patch
new file mode 100644
index 0000000000000000000000000000000000000000..219363e25f3e70f253e861db4d4c5cd791d5cc5d
--- /dev/null
+++ b/backport-pinky-fix-string-size-calculation.patch
@@ -0,0 +1,66 @@
+From 3e0d7787e67d4f732298d99eee772fc2631ddfb8 Mon Sep 17 00:00:00 2001
+From: Paul Eggert
+Date: Mon, 11 Mar 2024 13:46:24 +0000
+Subject: [PATCH] timeout: fix narrow race in failing to kill processes
+
+* src/timeout.c (main): Block cleanup signals earlier so that cleanup()
+is not runnable until monitored_pid is in a deterministic state.
+This ensures we always send a termination signal to the child
+once it's forked.
+* NEWS: Mention the bug fix.
+Reported at https://github.com/coreutils/coreutils/issues/82
+
+Reference:https://github.com/coreutils/coreutils/commit/ab4ffc85039f7398dde2ec4b307dfb2aa0fcf4f8
+Conflict:Delete NEWS.
+
+---
+ src/timeout.c | 32 +++++++++++++++++++++-----------
+ 2 files changed, 21 insertions(+), 11 deletions(-)
+
+diff --git a/src/timeout.c b/src/timeout.c
+index 9aa46a4f5..68d872b12 100644
+--- a/src/timeout.c
++++ b/src/timeout.c
+@@ -248,7 +248,7 @@ cleanup (int sig)
+ { /* were in the parent, so let it continue to exit below. */
+ }
+ else /* monitored_pid == 0 */
+- { /* we're the child or the child is not exec'd yet. */
++ { /* parent hasn't forked yet, or child has not exec'd yet. */
+ _exit (128 + sig);
+ }
+ }
+@@ -537,14 +537,29 @@ main (int argc, char **argv)
+ signal (SIGTTOU, SIG_IGN); /* Don't stop if background child needs tty. */
+ install_sigchld (); /* Interrupt sigsuspend() when child exits. */
+
++ /* We configure timers so that SIGALRM is sent on expiry.
++ Therefore ensure we don't inherit a mask blocking SIGALRM. */
++ unblock_signal (SIGALRM);
++
++ /* Block signals now, so monitored_pid is deterministic in cleanup(). */
++ sigset_t orig_set;
++ block_cleanup_and_chld (term_signal, &orig_set);
++
+ monitored_pid = fork ();
+ if (monitored_pid == -1)
+ {
+ error (0, errno, _("fork system call failed"));
+ return EXIT_CANCELED;
+ }
+- else if (monitored_pid == 0)
+- { /* child */
++ else if (monitored_pid == 0) /* child */
++ {
++ /* Restore signal mask for child. */
++ if (sigprocmask (SIG_SETMASK, &orig_set, nullptr) != 0)
++ {
++ error (0, errno, _("child failed to reset signal mask"));
++ return EXIT_CANCELED;
++ }
++
+ /* exec doesn't reset SIG_IGN -> SIG_DFL. */
+ signal (SIGTTIN, SIG_DFL);
+ signal (SIGTTOU, SIG_DFL);
+@@ -561,19 +576,14 @@ main (int argc, char **argv)
+ pid_t wait_result;
+ int status;
+
+- /* We configure timers so that SIGALRM is sent on expiry.
+- Therefore ensure we don't inherit a mask blocking SIGALRM. */
+- unblock_signal (SIGALRM);
+-
+ settimeout (timeout, true);
+
+- /* Ensure we don't cleanup() after waitpid() reaps the child,
++ /* Note signals remain blocked in parent here, to ensure
++ we don't cleanup() after waitpid() reaps the child,
+ to avoid sending signals to a possibly different process. */
+- sigset_t cleanup_set;
+- block_cleanup_and_chld (term_signal, &cleanup_set);
+
+ while ((wait_result = waitpid (monitored_pid, &status, WNOHANG)) == 0)
+- sigsuspend (&cleanup_set); /* Wait with cleanup signals unblocked. */
++ sigsuspend (&orig_set); /* Wait with cleanup signals unblocked. */
+
+ if (wait_result < 0)
+ {
+--
+2.43.0
+
diff --git a/backport-timeout-fix-race-where-we-might-kill-arbitrary-proce.patch b/backport-timeout-fix-race-where-we-might-kill-arbitrary-proce.patch
new file mode 100644
index 0000000000000000000000000000000000000000..206cc89f3da09a84774cd97acab101a506502385
--- /dev/null
+++ b/backport-timeout-fix-race-where-we-might-kill-arbitrary-proce.patch
@@ -0,0 +1,51 @@
+From c1cf5148a1c6302d27661ff0af772de1e7dbb2b6 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?P=C3=A1draig=20Brady?=
+Date: Mon, 11 Mar 2024 13:18:37 +0000
+Subject: [PATCH] timeout: fix race where we might kill arbitrary processes
+
+* src/timeout.c (cleanup): Handle the case where monitored_pid
+might be -1, which could happen if a signal was received
+immediately after a failed fork() call. In that case it would
+send the termination signal to all processes that the timeout
+process has permission to send signals too.
+* NEWS: Mention the bug fix.
+
+Reference:https://github.com/coreutils/coreutils/commit/c1cf5148a1c6302d27661ff0af772de1e7dbb2b6
+Conflict:Delete NEWS.
+
+---
+ src/timeout.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+diff --git a/src/timeout.c b/src/timeout.c
+index 6505634..641592c 100644
+--- a/src/timeout.c
++++ b/src/timeout.c
+@@ -208,7 +208,7 @@ cleanup (int sig)
+ timed_out = 1;
+ sig = term_signal;
+ }
+- if (monitored_pid)
++ if (0 < monitored_pid)
+ {
+ if (kill_after)
+ {
+@@ -245,8 +245,13 @@ cleanup (int sig)
+ }
+ }
+ }
+- else /* we're the child or the child is not exec'd yet. */
+- _exit (128 + sig);
++ else if (monitored_pid == -1)
++ { /* were in the parent, so let it continue to exit below. */
++ }
++ else /* monitored_pid == 0 */
++ { /* we're the child or the child is not exec'd yet. */
++ _exit (128 + sig);
++ }
+ }
+
+ void
+--
+2.33.0
+
diff --git a/coreutils.spec b/coreutils.spec
index 1ace8e274302aa6079e229ed53d86001cc687456..7978c530a16c364d876b62b603da75cbfb0b178f 100644
--- a/coreutils.spec
+++ b/coreutils.spec
@@ -1,6 +1,6 @@
Name: coreutils
Version: 9.4
-Release: 9
+Release: 10
License: GPLv3+
Summary: A set of basic GNU tools commonly used in shell scripts
Url: https://www.gnu.org/software/coreutils/
@@ -28,6 +28,15 @@ patch13: backport-sort-don-t-trust-st_size-on-proc-files.patch
patch14: backport-cat-don-t-trust-st_size-on-proc-files.patch
patch15: backport-dd-don-t-trust-st_size-on-proc-files.patch
patch16: backport-split-don-t-trust-st_size-on-proc-files.patch
+Patch17: backport-pinky-fix-string-size-calculation.patch
+Patch18: backport-cksum-consistently-validate-length-attributes.patch
+Patch19: backport-timeout-fix-race-where-we-might-kill-arbitrary-proce.patch
+Patch20: backport-timeout-fix-narrow-race-in-failing-to-kill-processes.patch
+Patch21: backport-maint-basenc-consistently-check-buffer-bounds-when-e.patch
+Patch22: backport-putenv-Don-t-crash-upon-out-of-memory.patch
+Patch23: backport-head-off_t-not-uintmax_t-for-file-offset.patch
+Patch24: backport-shuf-avoid-integer-overflow-on-huge-inputs.patch
+Patch25: backport-shuf-fix-randomness-bug.patch
Patch9001: coreutils-9.0-sw.patch
@@ -168,6 +177,18 @@ fi
%{_mandir}/man*/*
%changelog
+* Wed Sep 11 2024 huyubiao