Skip to content

Commit 50b6c1f

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 45ef3a1 commit 50b6c1f

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 <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+

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
@@ -233,6 +237,15 @@ boringssl_version=$(describe ${source_dir}/boringssl)
233237

234238
zlib_version=$(versionFromTag ${source_dir}/zlib)
235239

240+
bzip2_desc=$(describe ${source_dir}/bzip2)
241+
bzip2_version=${bzip2_desc#bzip2-}
242+
243+
libarchive_version=$(versionFromTag ${source_dir}/libarchive)
244+
245+
mimalloc_version=$(versionFromTag ${source_dir}/mimalloc)
246+
247+
xz_version=$(versionFromTag ${source_dir}/xz)
248+
236249
function quiet_pushd {
237250
pushd "$1" >/dev/null 2>&1
238251
}
@@ -258,6 +271,10 @@ echo " - libxml2 ${libxml2_version}"
258271
echo " - curl ${curl_version}"
259272
echo " - BoringSSL ${boringssl_version}"
260273
echo " - zlib ${zlib_version}"
274+
echo " - bzip2 ${bzip2_version}"
275+
echo " - xz ${xz_version}"
276+
echo " - libarchive ${libarchive_version}"
277+
echo " - mimalloc ${mimalloc_version}"
261278

262279
function run() {
263280
echo "$@"
@@ -297,6 +314,19 @@ else
297314
exit 1
298315
fi
299316

317+
echo "Applying Musl security patches... "
318+
for patch in $(realpath "${resource_dir}/patches/musl")/*; do
319+
echo -n " $(basename $patch)..."
320+
if git -C ${source_dir}/musl apply --reverse --check "$patch" >/dev/null 2>&1; then
321+
echo "already patched"
322+
elif git -C ${source_dir}/musl apply "$patch" >/dev/null 2>&1; then
323+
echo "done"
324+
else
325+
echo "failed"
326+
exit 1
327+
fi
328+
done
329+
300330
# -----------------------------------------------------------------------
301331

302332
header "Patching BoringSSL"
@@ -367,7 +397,7 @@ for arch in $archs; do
367397
cat > $sdk_root/SDKSettings.json <<EOF
368398
{
369399
"DisplayName": "Swift SDK for Statically Linked Linux ($arch)",
370-
"Version": "0.0.1",
400+
"Version": "${static_linux_sdk_version}",
371401
"VersionMap": {},
372402
"CanonicalName": "${arch}-swift-linux-musl"
373403
}
@@ -567,6 +597,37 @@ EOF
567597

568598
# -----------------------------------------------------------------------
569599

600+
header "Building mimalloc for $arch"
601+
602+
run cmake -G Ninja -S ${source_dir}/mimalloc \
603+
-B ${build_dir}/$arch/mimalloc \
604+
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
605+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
606+
-DCMAKE_INSTALL_PREFIX="$sdk_root/usr" \
607+
-DMI_LIBC_MUSL=ON \
608+
-DMI_BUILD_SHARED=OFF \
609+
-DMI_BUILD_STATIC=ON \
610+
-DMI_BUILD_TESTS=OFF \
611+
-DMI_INSTALL_TOPLEVEL=ON
612+
613+
quiet_pushd ${build_dir}/$arch/mimalloc
614+
run ninja -j$parallel_jobs
615+
quiet_popd
616+
617+
header "Installing mimalloc for ${arch}"
618+
619+
quiet_pushd ${build_dir}/$arch/mimalloc
620+
run ninja -j$parallel_jobs install
621+
quiet_popd
622+
623+
# Make sure we link mimalloc
624+
ldflags="-lmimalloc $ldflags"
625+
cxxldflags="-lmimalloc $cxxldflags"
626+
sed -i -e 's/-lc++ /-lmimalloc -lc++ /g' \
627+
${build_dir}/${arch}/toolchain.cmake
628+
629+
# -----------------------------------------------------------------------
630+
570631
header "Building zlib for $arch"
571632

572633
mkdir -p $build_dir/$arch/zlib
@@ -592,17 +653,67 @@ EOF
592653

593654
# -----------------------------------------------------------------------
594655

656+
header "Building bzip2 for $arch"
657+
658+
rm -rf ${build_dir}/$arch/bzip2
659+
cp -R ${source_dir}/bzip2 ${build_dir}/$arch/bzip2
660+
quiet_pushd $build_dir/$arch/bzip2
661+
run make \
662+
CC="$cc" \
663+
CXX="$cxx" \
664+
LDFLAGS="$ldflags" \
665+
CXXLDFLAGS="$cxxldflags" \
666+
AS="$as" \
667+
AR="ar" RANLIB="ranlib" \
668+
PREFIX=$sdk_root/usr
669+
quiet_popd
670+
671+
header "Installing bzip2 for $arch"
672+
673+
quiet_pushd $build_dir/$arch/bzip2
674+
run make install \
675+
CC="$cc" \
676+
CXX="$cxx" \
677+
LDFLAGS="$ldflags" \
678+
CXXLDFLAGS="$cxxldflags" \
679+
AS="$as" \
680+
AR="ar" RANLIB="ranlib" \
681+
PREFIX=$sdk_root/usr
682+
quiet_popd
683+
684+
# -----------------------------------------------------------------------
685+
686+
header "Building xz for $arch"
687+
688+
run cmake -G Ninja -S ${source_dir}/xz -B ${build_dir}/$arch/xz \
689+
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
690+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
691+
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
692+
-DBUILD_SHARED_LIBS=NO
693+
694+
quiet_pushd ${build_dir}/$arch/xz
695+
run ninja -j$parallel_jobs
696+
quiet_popd
697+
698+
header "Installing xz for $arch"
699+
700+
quiet_pushd ${build_dir}/$arch/xz
701+
run ninja -j$parallel_jobs install
702+
quiet_popd
703+
704+
# -----------------------------------------------------------------------
705+
595706
header "Building libxml2 for $arch"
596707

597708
run cmake -G Ninja -S ${source_dir}/libxml2 -B ${build_dir}/$arch/libxml2 \
598709
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
599-
-DCMAKE_EXTRA_LINK_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi" \
710+
-DCMAKE_EXTRA_LINK_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lmimalloc -lc++ -lc++abi" \
600711
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
601712
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
602713
-DBUILD_SHARED_LIBS=NO \
603714
-DLIBXML2_WITH_PYTHON=NO \
604715
-DLIBXML2_WITH_ICU=NO \
605-
-DLIBXML2_WITH_LZMA=NO
716+
-DLIBXML2_WITH_LZMA=YES
606717

607718
quiet_pushd ${build_dir}/$arch/libxml2
608719
run ninja -j$parallel_jobs
@@ -616,6 +727,29 @@ EOF
616727

617728
# -----------------------------------------------------------------------
618729

730+
header "Building libarchive for $arch"
731+
732+
run cmake -G Ninja -S ${source_dir}/libarchive \
733+
-B ${build_dir}/$arch/libarchive \
734+
-DCMAKE_TOOLCHAIN_FILE=${build_dir}/$arch/toolchain.cmake \
735+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
736+
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
737+
-DCMAKE_INSTALL_LIBDIR=$sdk_root/usr/lib \
738+
-DBUILD_SHARED_LIBS=NO \
739+
-DENABLE_OPENSSL=NO
740+
741+
quiet_pushd ${build_dir}/$arch/libarchive
742+
run ninja -j$parallel_jobs
743+
quiet_popd
744+
745+
header "Installing libarchive for $arch"
746+
747+
quiet_pushd ${build_dir}/$arch/libarchive
748+
run ninja -j$parallel_jobs install
749+
quiet_popd
750+
751+
# -----------------------------------------------------------------------
752+
619753
header "Building BoringSSL for $arch"
620754

621755
run cmake -G Ninja -S ${source_dir}/boringssl -B ${build_dir}/$arch/boringssl \
@@ -644,7 +778,9 @@ EOF
644778
-DCMAKE_INSTALL_PREFIX=$sdk_root/usr \
645779
-DBUILD_SHARED_LIBS=NO \
646780
-DBUILD_STATIC_LIBS=YES \
647-
-DBUILD_CURL_EXE=NO
781+
-DBUILD_CURL_EXE=NO \
782+
-DCURL_USE_PKGCONFIG=OFF \
783+
-DCURL_USE_LIBPSL=OFF
648784

649785
quiet_pushd ${build_dir}/$arch/curl
650786
ninja -j$parallel_jobs
@@ -688,6 +824,7 @@ EOF
688824
-stdlib=libc++
689825
-fuse-ld=lld
690826
-unwindlib=libunwind
827+
-lmimalloc
691828
-lc++abi
692829
-static
693830
EOF
@@ -824,7 +961,7 @@ header "Bundling SDK"
824961

825962
spdx_uuid=$(uuidgen)
826963
spdx_doc_uuid=$(uuidgen)
827-
spdx_timestamp=$(date -Iseconds)
964+
spdx_timestamp=$(date -Iseconds -z Z | sed 's/\+00:00$/Z/g')
828965

829966
sdk_name=swift-${swift_version}_static-linux-${static_linux_sdk_version}
830967
bundle="${sdk_name}.artifactbundle"
@@ -845,7 +982,7 @@ cat > info.json <<EOF
845982
"path": "$sdk_name/swift-linux-musl"
846983
}
847984
],
848-
"version": "0.0.1",
985+
"version": "${static_linux_sdk_version}",
849986
"type": "swiftSDK"
850987
}
851988
}

0 commit comments

Comments
 (0)