commit: a9a1ea072ab7c291abce96ee0162a6be3122a1c9 Author: Wynn Wolf Arbor <wolf <AT> oriole <DOT> systems> AuthorDate: Tue Jun 9 14:27:30 2020 +0000 Commit: Joonas Niilola <juippis <AT> gentoo <DOT> org> CommitDate: Sun Jun 28 10:40:58 2020 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a9a1ea07
mail-filter/libmilter: Set default pthread stack size to 256 KB on musl The default stack size for glibc is set to 8MB, whilst musl sets it to 80 KB. This leads to various crashes of applications depending on libmilter. Enforce a stack size of 256 KB to mitigate these crashes. See also the following link, from where this patch was taken. https://git.alpinelinux.org/aports/tree/main/libmilter/default-pthread-stacksize.patch Signed-off-by: Wynn Wolf Arbor <wolf <AT> oriole.systems> Package-Manager: Portage-2.3.99, Repoman-2.3.22 Closes: https://github.com/gentoo/gentoo/pull/16139 Signed-off-by: Joonas Niilola <juippis <AT> gentoo.org> .../files/libmilter-musl-stack-size.patch | 42 ++++++++++++++++++++++ mail-filter/libmilter/libmilter-1.0.2_p1.ebuild | 1 + 2 files changed, 43 insertions(+) diff --git a/mail-filter/libmilter/files/libmilter-musl-stack-size.patch b/mail-filter/libmilter/files/libmilter-musl-stack-size.patch new file mode 100644 index 00000000000..9993adfece3 --- /dev/null +++ b/mail-filter/libmilter/files/libmilter-musl-stack-size.patch @@ -0,0 +1,42 @@ +Set default pthread stack size to 256 KB + +This patch tries to fix various crashes for applications depending on libmilter +by setting the stack size for pthreads to 256 KB. The default stack size for +musl libc is set to 80 KB whereas glibc has it set to 8 MB. This causes problems +when a large amount of memory is allocated on the stack. + +For example, opendkim allocates blocks of 64 KB multiple times, which causes +libmilter (and therefore opendkim) to crash. For now, a stack size of 256 KB +looks sufficient and makes opendkim stop crashing. + +Fixes https://bugs.alpinelinux.org/issues/6360 + +--- a/libmilter/libmilter.h ++++ b/libmilter/libmilter.h +@@ -127,10 +127,10 @@ + # define MI_SOCK_READ(s, b, l) read(s, b, l) + # define MI_SOCK_READ_FAIL(x) ((x) < 0) + # define MI_SOCK_WRITE(s, b, l) write(s, b, l) +- +-# define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg) + # define sthread_get_id() pthread_self() + ++extern int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg); ++ + typedef pthread_mutex_t smutex_t; + # define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0) + # define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0) +--- a/libmilter/main.c ++++ b/libmilter/main.c +@@ -16,6 +16,12 @@ + #include <fcntl.h> + #include <sys/stat.h> + ++int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg) { ++ pthread_attr_t attr; ++ pthread_attr_init(&attr); ++ pthread_attr_setstacksize(&attr,256*1024); ++ return pthread_create(ptid, &attr, wr, arg); ++} + + static smfiDesc_ptr smfi = NULL; diff --git a/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild b/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild index e197eb05925..b9a1147970d 100644 --- a/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild +++ b/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild @@ -45,6 +45,7 @@ src_prepare() { if use elibc_musl; then use ipv6 && ENVDEF="${ENVDEF} -DNEEDSGETIPNODE" + eapply "${FILESDIR}/${PN}-musl-stack-size.patch" eapply "${FILESDIR}/${PN}-musl-disable-cdefs.patch" fi
