diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-05-31 19:05:20 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-05-31 19:05:20 -0500 |
commit | d448f4e0c6a17170cad364b25d7208c29ac7604e (patch) | |
tree | 2cead6dd20c7f8c5c629733c624e855d0b64596a | |
parent | 0ee2191bdaf224bcc5c9bd4cfd3e42e0fe5fed16 (diff) | |
download | packages-d448f4e0c6a17170cad364b25d7208c29ac7604e.tar.gz packages-d448f4e0c6a17170cad364b25d7208c29ac7604e.tar.bz2 packages-d448f4e0c6a17170cad364b25d7208c29ac7604e.tar.xz packages-d448f4e0c6a17170cad364b25d7208c29ac7604e.zip |
system/musl: fix TLS accesses, add %l to strftime
-rw-r--r-- | system/musl/APKBUILD | 6 | ||||
-rw-r--r-- | system/musl/arm64-tls.patch | 116 | ||||
-rw-r--r-- | system/musl/strftime-add-l-support.patch | 25 |
3 files changed, 146 insertions, 1 deletions
diff --git a/system/musl/APKBUILD b/system/musl/APKBUILD index 19606c44f..1c30abdfb 100644 --- a/system/musl/APKBUILD +++ b/system/musl/APKBUILD @@ -1,7 +1,7 @@ # Maintainer: A. Wilcox <awilfox@adelielinux.org> pkgname=musl pkgver=1.1.22 -pkgrel=0 +pkgrel=1 pkgdesc="System library (libc) implementation" url="https://www.musl-libc.org/" arch="all" @@ -23,9 +23,11 @@ nolibc) ;; esac source="https://www.musl-libc.org/releases/musl-$pkgver.tar.gz amalgamation.patch + arm64-tls.patch 3001-make-real-lastlog-h.patch handle-aux-at_base.patch fgetspent_r.patch + strftime-add-l-support.patch ldconfig getent.c @@ -120,9 +122,11 @@ utils() { sha512sums="08a40d722672504427238e71c9e52a723c6a14735abe9581d6d4bb3f86662d5d51a3f32a6aed6420c1f9680e22a3a554a9b87ae342635be971e2db49cc9fdb87 musl-1.1.22.tar.gz 8eadf9933e729e8a6d99f667257284eaf06cb0160b40e6307ed69159c03ba4ed3c67a2943c71b5abc258bbc6c9ff321a34aa55357ebb460be9363dd605e18144 amalgamation.patch +a1127de160cbf820875d415f8fdda3c894e03748070070e282e1cf0604c883db3f8e1c311dd8c3f318ac8a158cb2183c757bcbbbd666b63676074bdec6a29983 arm64-tls.patch 88ae443dbb8e0a4368235bdc3a1c5c7b718495afa75e06deb8e01becc76cb1f0d6964589e2204fc749c9c1b3190b8b9ac1ae2c0099cab8e2ce3ec877103d4332 3001-make-real-lastlog-h.patch 6a7ff16d95b5d1be77e0a0fbb245491817db192176496a57b22ab037637d97a185ea0b0d19da687da66c2a2f5578e4343d230f399d49fe377d8f008410974238 handle-aux-at_base.patch ded41235148930f8cf781538f7d63ecb0c65ea4e8ce792565f3649ee2523592a76b2a166785f0b145fc79f5852fd1fb1729a7a09110b3b8f85cba3912e790807 fgetspent_r.patch +7ed6c620a5ea5585c323936b1ff01eb7f01a1192240706a0d0470b661a7a03ea10ed17507c59678aaedce51b7a5ea839c2f528f19f12de02119bf4e47f7c3998 strftime-add-l-support.patch cce2f1eeb61e55674469c26871a573cce61d739c3defe9c8f56f2b774f6ba5435849ad542a6714120efddc98c297098e9c98a1a424ac593df2243d4aa479f9a9 ldconfig 378d70e65bcc65bb4e1415354cecfa54b0c1146dfb24474b69e418cdbf7ad730472cd09f6f103e1c99ba6c324c9560bccdf287f5889bbc3ef0bdf0e08da47413 getent.c 9d42d66fb1facce2b85dad919be5be819ee290bd26ca2db00982b2f8e055a0196290a008711cbe2b18ec9eee8d2270e3b3a4692c5a1b807013baa5c2b70a2bbf iconv.c" diff --git a/system/musl/arm64-tls.patch b/system/musl/arm64-tls.patch new file mode 100644 index 000000000..4a6d7f7a4 --- /dev/null +++ b/system/musl/arm64-tls.patch @@ -0,0 +1,116 @@ +From 6104dae9088da7ffd9346671be867a43a4b03295 Mon Sep 17 00:00:00 2001 +From: Szabolcs Nagy <nsz@port70.net> +Date: Thu, 16 May 2019 17:15:33 +0000 +Subject: fix static tls offsets of shared libs on TLS_ABOVE_TP targets + +tls_offset should always point to the end of the allocated static tls +area, but this was not handled correctly on "tls variant 1" targets +in the dynamic linker: + +after application tls was allocated, tls_offset was aligned up, +potentially wasting tls space. (alignment may be needed at the +begining of the tls area, not at the end, but that will be fixed +separately as it is unlikely to affect real binaries.) + +when static tls was allocated for a shared library, tls_offset was +only updated with the size of the tls segment which does not include +alignment gaps, which can easily happen if the tls size update for +one library leaves tls_offset misaligned for the next one. this can +cause oob access in __copy_tls or arbitrary breakage at tls access. +(the issue was observed on aarch64 with rust binaries) +--- + ldso/dynlink.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/ldso/dynlink.c b/ldso/dynlink.c +index ad0cdba2..967f1fd9 100644 +--- a/ldso/dynlink.c ++++ b/ldso/dynlink.c +@@ -1127,7 +1127,7 @@ static struct dso *load_library(const char *name, struct dso *needed_by) + #ifdef TLS_ABOVE_TP + p->tls.offset = tls_offset + ( (tls_align-1) & + -(tls_offset + (uintptr_t)p->tls.image) ); +- tls_offset += p->tls.size; ++ tls_offset = p->tls.offset + p->tls.size; + #else + tls_offset += p->tls.size + p->tls.align - 1; + tls_offset -= (tls_offset + (uintptr_t)p->tls.image) +@@ -1797,9 +1797,7 @@ _Noreturn void __dls3(size_t *sp) + #ifdef TLS_ABOVE_TP + app.tls.offset = GAP_ABOVE_TP; + app.tls.offset += -GAP_ABOVE_TP & (app.tls.align-1); +- tls_offset = app.tls.offset + app.tls.size +- + ( -((uintptr_t)app.tls.image + app.tls.size) +- & (app.tls.align-1) ); ++ tls_offset = app.tls.offset + app.tls.size; + #else + tls_offset = app.tls.offset = app.tls.size + + ( -((uintptr_t)app.tls.image + app.tls.size) +-- +cgit v1.2.1 + +From a60b9e06861e56c0810bae0249b421e1758d281a Mon Sep 17 00:00:00 2001 +From: Szabolcs Nagy <nsz@port70.net> +Date: Mon, 13 May 2019 18:47:11 +0000 +Subject: fix tls offsets when p_vaddr%p_align != 0 on TLS_ABOVE_TP targets + +currently the bfd linker does not seem to create tls segments where +p_vaddr%p_align != 0, but this is valid in ELF and then the runtime +computed tls offset must satisfy + + offset%p_align == (base+p_vaddr)%p_align + +and in case of local exec tls (main executable) the smallest such +offset must be used (otherwise it is incompatible with the offset +computed by the static linker). the !TLS_ABOVE_TP case is handled +correctly (the offset is negative then in the formula). + +the ldso code for TLS_ABOVE_TP is changed so the static tls offset +of each module satisfies the formula. +--- + ldso/dynlink.c | 7 ++++--- + src/env/__init_tls.c | 3 ++- + 2 files changed, 6 insertions(+), 4 deletions(-) + +diff --git a/ldso/dynlink.c b/ldso/dynlink.c +index 967f1fd9..1398ff45 100644 +--- a/ldso/dynlink.c ++++ b/ldso/dynlink.c +@@ -1125,8 +1125,8 @@ static struct dso *load_library(const char *name, struct dso *needed_by) + p->tls_id = ++tls_cnt; + tls_align = MAXP2(tls_align, p->tls.align); + #ifdef TLS_ABOVE_TP +- p->tls.offset = tls_offset + ( (tls_align-1) & +- -(tls_offset + (uintptr_t)p->tls.image) ); ++ p->tls.offset = tls_offset + ( (p->tls.align-1) & ++ (-tls_offset + (uintptr_t)p->tls.image) ); + tls_offset = p->tls.offset + p->tls.size; + #else + tls_offset += p->tls.size + p->tls.align - 1; +@@ -1796,7 +1796,8 @@ _Noreturn void __dls3(size_t *sp) + app.tls_id = tls_cnt = 1; + #ifdef TLS_ABOVE_TP + app.tls.offset = GAP_ABOVE_TP; +- app.tls.offset += -GAP_ABOVE_TP & (app.tls.align-1); ++ app.tls.offset += (-GAP_ABOVE_TP + (uintptr_t)app.tls.image) ++ & (app.tls.align-1); + tls_offset = app.tls.offset + app.tls.size; + #else + tls_offset = app.tls.offset = app.tls.size +diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c +index 5f12500c..772baba3 100644 +--- a/src/env/__init_tls.c ++++ b/src/env/__init_tls.c +@@ -115,7 +115,8 @@ static void static_init_tls(size_t *aux) + & (main_tls.align-1); + #ifdef TLS_ABOVE_TP + main_tls.offset = GAP_ABOVE_TP; +- main_tls.offset += -GAP_ABOVE_TP & (main_tls.align-1); ++ main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) ++ & (main_tls.align-1); + #else + main_tls.offset = main_tls.size; + #endif +-- +cgit v1.2.1 + diff --git a/system/musl/strftime-add-l-support.patch b/system/musl/strftime-add-l-support.patch new file mode 100644 index 000000000..8305a9910 --- /dev/null +++ b/system/musl/strftime-add-l-support.patch @@ -0,0 +1,25 @@ +From 481def0e92ebfe81f40f416ddf345de15647e46b Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Fri, 31 May 2019 19:03:20 -0500 +Subject: [PATCH] strftime: add %l support + +--- + src/time/strftime.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/time/strftime.c b/src/time/strftime.c +index cc53d536..98caa1f6 100644 +--- a/src/time/strftime.c ++++ b/src/time/strftime.c +@@ -95,6 +95,8 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * + case 'H': + val = tm->tm_hour; + goto number; ++ case 'l': ++ def_pad = ' '; + case 'I': + val = tm->tm_hour; + if (!val) val = 12; +-- +2.21.0 + |