Skip to content

Commit 04df20d

Browse files
committed
Update the Static SDK for Linux
Updated the versions of: - libxml2 (2.14.5) - curl (8.15.0) - BoringSSL (newer SHA) and added: - bzip2 (1.0.8) - xz-utils (5.8.1) - libarchive (3.8.1) - mimalloc (2.2.4) Plus two security patches for musl to fix CVE-2025-26519. Also link mimalloc by default, so programs using the Static SDK for Linux get a better memory allocator out of the box. rdar://156423711
1 parent 09fc5a5 commit 04df20d

File tree

4 files changed

+290
-16
lines changed

4 files changed

+290
-16
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 <[email protected]>
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 <[email protected]>
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+

swift-ci/sdks/static-linux/scripts/build.sh

Lines changed: 145 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function declare_package
9797
}
9898

9999
declare_package static_linux_sdk \
100-
"Swift statically linked SDK for Linux" \
100+
"Swift Static SDK for Linux" \
101101
"Apache-2.0" "https://swift.org/install/sdk"
102102
declare_package swift "swift" "Apache-2.0" "https://swift.org"
103103
declare_package musl "musl" "MIT" "https://musl.org"
@@ -109,9 +109,13 @@ declare_package curl "curl" "MIT" "https://curl.se"
109109
declare_package boringssl "boringssl" "OpenSSL AND ISC AND MIT" \
110110
"https://boringssl.googlesource.com/boringssl/"
111111
declare_package zlib "zlib" "Zlib" "https://zlib.net"
112+
declare_package bzip2 "bzip2" "bzip2-1.0.6" "https://sourceware.org/bzip2/"
113+
declare_package xz "XZ Utils" "0BSD" "https://tukaani.org/xz"
114+
declare_package libarchive "libarchive" "BSD-2-Clause" "https://www.libarchive.org"
115+
declare_package mimalloc "mimalloc" "MIT" "https://microsoft.github.io/mimalloc/"
112116

113117
# Parse command line arguments
114-
static_linux_sdk_version=0.0.1
118+
static_linux_sdk_version=0.1.0
115119
sdk_name=
116120
archs=x86_64,aarch64
117121
build_type=RelWithDebInfo
@@ -208,6 +212,15 @@ boringssl_version=$(describe ${source_dir}/boringssl)
208212

209213
zlib_version=$(versionFromTag ${source_dir}/zlib)
210214

215+
bzip2_desc=$(describe ${source_dir}/bzip2)
216+
bzip2_version=${bzip2_desc#bzip2-}
217+
218+
libarchive_version=$(versionFromTag ${source_dir}/libarchive)
219+
220+
mimalloc_version=$(versionFromTag ${source_dir}/mimalloc)
221+
222+
xz_version=$(versionFromTag ${source_dir}/xz)
223+
211224
function quiet_pushd {
212225
pushd "$1" >/dev/null 2>&1
213226
}
@@ -233,6 +246,10 @@ echo " - libxml2 ${libxml2_version}"
233246
echo " - curl ${curl_version}"
234247
echo " - BoringSSL ${boringssl_version}"
235248
echo " - zlib ${zlib_version}"
249+
echo " - bzip2 ${bzip2_version}"
250+
echo " - xz ${xz_version}"
251+
echo " - libarchive ${libarchive_version}"
252+
echo " - mimalloc ${mimalloc_version}"
236253

237254
function run() {
238255
echo "$@"
@@ -268,6 +285,19 @@ else
268285
exit 1
269286
fi
270287

288+
echo "Applying Musl security patches... "
289+
for patch in $(realpath "${resource_dir}/patches/musl")/*; do
290+
echo -n " $(basename $patch)..."
291+
if git -C ${source_dir}/musl apply --reverse --check "$patch" >/dev/null 2>&1; then
292+
echo "already patched"
293+
elif git -C ${source_dir}/musl apply "$patch" >/dev/null 2>&1; then
294+
echo "done"
295+
else
296+
echo "failed"
297+
exit 1
298+
fi
299+
done
300+
271301
for arch in $archs; do
272302

273303
# Fix architecture names
@@ -299,7 +329,7 @@ for arch in $archs; do
299329
cat > $sdk_root/SDKSettings.json <<EOF
300330
{
301331
"DisplayName": "Swift SDK for Statically Linked Linux ($arch)",
302-
"Version": "0.0.1",
332+
"Version": "${static_linux_sdk_version}",
303333
"VersionMap": {},
304334
"CanonicalName": "${arch}-swift-linux-musl"
305335
}
@@ -499,6 +529,37 @@ EOF
499529

500530
# -----------------------------------------------------------------------
501531

532+
header "Building mimalloc for $arch"
533+
534+
run cmake -G Ninja -S ${source_dir}/mimalloc \
535+
-B ${build_dir}/$arch/mimalloc \
536+
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
537+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
538+
-DCMAKE_INSTALL_PREFIX="$sdk_root/usr" \
539+
-DMI_LIBC_MUSL=ON \
540+
-DMI_BUILD_SHARED=OFF \
541+
-DMI_BUILD_STATIC=ON \
542+
-DMI_BUILD_TESTS=OFF \
543+
-DMI_INSTALL_TOPLEVEL=ON
544+
545+
quiet_pushd ${build_dir}/$arch/mimalloc
546+
run ninja -j$parallel_jobs
547+
quiet_popd
548+
549+
header "Installing mimalloc for ${arch}"
550+
551+
quiet_pushd ${build_dir}/$arch/mimalloc
552+
run ninja -j$parallel_jobs install
553+
quiet_popd
554+
555+
# Make sure we link mimalloc
556+
ldflags="-lmimalloc $ldflags"
557+
cxxldflags="-lmimalloc $cxxldflags"
558+
sed -i -e 's/-lc++ /-lmimalloc -lc++ /g' \
559+
${build_dir}/${arch}/toolchain.cmake
560+
561+
# -----------------------------------------------------------------------
562+
502563
header "Building zlib for $arch"
503564

504565
mkdir -p $build_dir/$arch/zlib
@@ -524,17 +585,67 @@ EOF
524585

525586
# -----------------------------------------------------------------------
526587

588+
header "Building bzip2 for $arch"
589+
590+
rm -rf ${build_dir}/$arch/bzip2
591+
cp -R ${source_dir}/bzip2 ${build_dir}/$arch/bzip2
592+
quiet_pushd $build_dir/$arch/bzip2
593+
run make \
594+
CC="$cc" \
595+
CXX="$cxx" \
596+
LDFLAGS="$ldflags" \
597+
CXXLDFLAGS="$cxxldflags" \
598+
AS="$as" \
599+
AR="ar" RANLIB="ranlib" \
600+
PREFIX=$sdk_root/usr
601+
quiet_popd
602+
603+
header "Installing bzip2 for $arch"
604+
605+
quiet_pushd $build_dir/$arch/bzip2
606+
run make install \
607+
CC="$cc" \
608+
CXX="$cxx" \
609+
LDFLAGS="$ldflags" \
610+
CXXLDFLAGS="$cxxldflags" \
611+
AS="$as" \
612+
AR="ar" RANLIB="ranlib" \
613+
PREFIX=$sdk_root/usr
614+
quiet_popd
615+
616+
# -----------------------------------------------------------------------
617+
618+
header "Building xz for $arch"
619+
620+
run cmake -G Ninja -S ${source_dir}/xz -B ${build_dir}/$arch/xz \
621+
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
622+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
623+
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
624+
-DBUILD_SHARED_LIBS=NO
625+
626+
quiet_pushd ${build_dir}/$arch/xz
627+
run ninja -j$parallel_jobs
628+
quiet_popd
629+
630+
header "Installing xz for $arch"
631+
632+
quiet_pushd ${build_dir}/$arch/xz
633+
run ninja -j$parallel_jobs install
634+
quiet_popd
635+
636+
# -----------------------------------------------------------------------
637+
527638
header "Building libxml2 for $arch"
528639

529640
run cmake -G Ninja -S ${source_dir}/libxml2 -B ${build_dir}/$arch/libxml2 \
530641
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
531-
-DCMAKE_EXTRA_LINK_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi" \
642+
-DCMAKE_EXTRA_LINK_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lmimalloc -lc++ -lc++abi" \
532643
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
533644
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
534645
-DBUILD_SHARED_LIBS=NO \
535646
-DLIBXML2_WITH_PYTHON=NO \
536647
-DLIBXML2_WITH_ICU=NO \
537-
-DLIBXML2_WITH_LZMA=NO
648+
-DLIBXML2_WITH_LZMA=YES
538649

539650
quiet_pushd ${build_dir}/$arch/libxml2
540651
run ninja -j$parallel_jobs
@@ -548,6 +659,29 @@ EOF
548659

549660
# -----------------------------------------------------------------------
550661

662+
header "Building libarchive for $arch"
663+
664+
run cmake -G Ninja -S ${source_dir}/libarchive \
665+
-B ${build_dir}/$arch/libarchive \
666+
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
667+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
668+
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
669+
-DCMAKE_INSTALL_LIBDIR=$sdk_root/usr/lib \
670+
-DBUILD_SHARED_LIBS=NO \
671+
-DENABLE_OPENSSL=NO
672+
673+
quiet_pushd ${build_dir}/$arch/libarchive
674+
run ninja -j$parallel_jobs
675+
quiet_popd
676+
677+
header "Installing libarchive for $arch"
678+
679+
quiet_pushd ${build_dir}/$arch/libarchive
680+
run ninja -j$parallel_jobs install
681+
quiet_popd
682+
683+
# -----------------------------------------------------------------------
684+
551685
header "Building BoringSSL for $arch"
552686

553687
run cmake -G Ninja -S ${source_dir}/boringssl -B ${build_dir}/$arch/boringssl \
@@ -576,7 +710,9 @@ EOF
576710
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
577711
-DBUILD_SHARED_LIBS=NO \
578712
-DBUILD_STATIC_LIBS=YES \
579-
-DBUILD_CURL_EXE=NO
713+
-DBUILD_CURL_EXE=NO \
714+
-DCURL_USE_PKGCONFIG=OFF \
715+
-DCURL_USE_LIBPSL=OFF
580716

581717
quiet_pushd ${build_dir}/$arch/curl
582718
ninja -j$parallel_jobs
@@ -619,6 +755,7 @@ EOF
619755
-stdlib=libc++
620756
-fuse-ld=lld
621757
-unwindlib=libunwind
758+
-lmimalloc
622759
-lc++abi
623760
-static
624761
EOF
@@ -750,7 +887,7 @@ header "Bundling SDK"
750887

751888
spdx_uuid=$(uuidgen)
752889
spdx_doc_uuid=$(uuidgen)
753-
spdx_timestamp=$(date -Iseconds)
890+
spdx_timestamp=$(date -Iseconds -z Z | sed 's/\+00:00$/Z/g')
754891

755892
sdk_name=swift-${swift_version}_static-linux-${static_linux_sdk_version}
756893
bundle="${sdk_name}.artifactbundle"
@@ -771,7 +908,7 @@ cat > info.json <<EOF
771908
"path": "$sdk_name/swift-linux-musl"
772909
}
773910
],
774-
"version": "0.0.1",
911+
"version": "${static_linux_sdk_version}",
775912
"type": "swiftSDK"
776913
}
777914
}

0 commit comments

Comments
 (0)