Skip to content

Commit 818b320

Browse files
committed
fix: patch musl to mitigate CVE-2025-26519
Ref: https://www.openwall.com/lists/musl/2025/02/13/1 Also ensure usr and sbin merge in the final image Signed-off-by: Dmitry Sharshakov <dmitry.sharshakov@siderolabs.com>
1 parent c92f2ed commit 818b320

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
>From e5adcd97b5196e29991b524237381a0202a60659 Mon Sep 17 00:00:00 2001
2+
From: Rich Felker <dalias@aerifal.cx>
3+
Date: Sun, 9 Feb 2025 10:07:19 -0500
4+
Subject: [PATCH] iconv: fix erroneous input validation in EUC-KR decoder
5+
6+
as a result of incorrect bounds checking on the lead byte being
7+
decoded, certain invalid inputs which should produce an encoding
8+
error, such as "\xc8\x41", instead produced out-of-bounds loads from
9+
the ksc table.
10+
11+
in a worst case, the loaded value may not be a valid unicode scalar
12+
value, in which case, if the output encoding was UTF-8, wctomb would
13+
return (size_t)-1, causing an overflow in the output pointer and
14+
remaining buffer size which could clobber memory outside of the output
15+
buffer.
16+
17+
bug report was submitted in private by Nick Wellnhofer on account of
18+
potential security implications.
19+
---
20+
src/locale/iconv.c | 2 +-
21+
1 file changed, 1 insertion(+), 1 deletion(-)
22+
23+
diff --git a/src/locale/iconv.c b/src/locale/iconv.c
24+
index 9605c8e9..008c93f0 100644
25+
--- a/src/locale/iconv.c
26+
+++ b/src/locale/iconv.c
27+
@@ -502,7 +502,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
28+
if (c >= 93 || d >= 94) {
29+
c += (0xa1-0x81);
30+
d += 0xa1;
31+
- if (c >= 93 || c>=0xc6-0x81 && d>0x52)
32+
+ if (c > 0xc6-0x81 || c==0xc6-0x81 && d>0x52)
33+
goto ilseq;
34+
if (d-'A'<26) d = d-'A';
35+
else if (d-'a'<26) d = d-'a'+26;
36+
--
37+
2.21.0
38+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
>From c47ad25ea3b484e10326f933e927c0bc8cded3da Mon Sep 17 00:00:00 2001
2+
From: Rich Felker <dalias@aerifal.cx>
3+
Date: Wed, 12 Feb 2025 17:06:30 -0500
4+
Subject: [PATCH] iconv: harden UTF-8 output code path against input decoder
5+
bugs
6+
7+
the UTF-8 output code was written assuming an invariant that iconv's
8+
decoders only emit valid Unicode Scalar Values which wctomb can encode
9+
successfully, thereby always returning a value between 1 and 4.
10+
11+
if this invariant is not satisfied, wctomb returns (size_t)-1, and the
12+
subsequent adjustments to the output buffer pointer and remaining
13+
output byte count overflow, moving the output position backwards,
14+
potentially past the beginning of the buffer, without storing any
15+
bytes.
16+
---
17+
src/locale/iconv.c | 4 ++++
18+
1 file changed, 4 insertions(+)
19+
20+
diff --git a/src/locale/iconv.c b/src/locale/iconv.c
21+
index 008c93f0..52178950 100644
22+
--- a/src/locale/iconv.c
23+
+++ b/src/locale/iconv.c
24+
@@ -545,6 +545,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
25+
if (*outb < k) goto toobig;
26+
memcpy(*out, tmp, k);
27+
} else k = wctomb_utf8(*out, c);
28+
+ /* This failure condition should be unreachable, but
29+
+ * is included to prevent decoder bugs from translating
30+
+ * into advancement outside the output buffer range. */
31+
+ if (k>4) goto ilseq;
32+
*out += k;
33+
*outb -= k;
34+
break;
35+
--
36+
2.21.0
37+
38+

toolchain-musl/pkg.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ steps:
2020
2121
patch -p1 < /pkg/patches/handle-aux-at-base.patch
2222
patch -p1 < /pkg/patches/close-range.patch
23+
patch -p1 < /pkg/patches/0001-iconv-fix-erroneous-input-validation-in-EUC-KR-decod.patch
24+
patch -p1 < /pkg/patches/0002-iconv-harden-UTF-8-output-code-path-against-input-de.patch
2325
2426
mkdir build
2527
cd build

toolchain/pkg.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ dependencies:
99
- stage: make
1010
- stage: golang
1111
steps:
12+
- build:
13+
- |
14+
# Check usrmerge symlinks are in place and point to directories
15+
mkdir -p /usr/bin /usr/lib
16+
[ -L /bin ] && [ -d /bin ]
17+
[ -L /lib ] && [ -d /lib ]
18+
[ -L /lib64 ] && [ -d /lib64 ]
19+
[ -L /usr/lib64 ] && [ -d /usr/lib64 ]
20+
- |
21+
# Ensure sbin either doesn't exist or is empty, so we don't lose any executables
22+
[ ! -e /sbin ] || [ -z "$(ls -A /sbin 2>/dev/null)" ]
23+
[ ! -e /usr/sbin ] || [ -z "$(ls -A /usr/sbin 2>/dev/null)" ]
24+
rm -rf /sbin
25+
rm -rf /usr/sbin
26+
- |
27+
# /usr/sbin -> /usr/bin
28+
ln -sT usr/bin /sbin
29+
ln -sT bin /usr/sbin
1230
- test:
1331
- |
1432
echo 'int main(){}' > dummy.c

0 commit comments

Comments
 (0)