Gentoo Archives: gentoo-commits

From: Joonas Niilola <juippis@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: mail-filter/libmilter/files/, mail-filter/libmilter/
Date: Sun, 28 Jun 2020 10:41:22
Message-Id: 1593340858.a9a1ea072ab7c291abce96ee0162a6be3122a1c9.juippis@gentoo
1 commit: a9a1ea072ab7c291abce96ee0162a6be3122a1c9
2 Author: Wynn Wolf Arbor <wolf <AT> oriole <DOT> systems>
3 AuthorDate: Tue Jun 9 14:27:30 2020 +0000
4 Commit: Joonas Niilola <juippis <AT> gentoo <DOT> org>
5 CommitDate: Sun Jun 28 10:40:58 2020 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a9a1ea07
7
8 mail-filter/libmilter: Set default pthread stack size to 256 KB on musl
9
10 The default stack size for glibc is set to 8MB, whilst musl sets it to
11 80 KB. This leads to various crashes of applications depending on
12 libmilter. Enforce a stack size of 256 KB to mitigate these crashes.
13
14 See also the following link, from where this patch was taken.
15 https://git.alpinelinux.org/aports/tree/main/libmilter/default-pthread-stacksize.patch
16
17 Signed-off-by: Wynn Wolf Arbor <wolf <AT> oriole.systems>
18 Package-Manager: Portage-2.3.99, Repoman-2.3.22
19 Closes: https://github.com/gentoo/gentoo/pull/16139
20 Signed-off-by: Joonas Niilola <juippis <AT> gentoo.org>
21
22 .../files/libmilter-musl-stack-size.patch | 42 ++++++++++++++++++++++
23 mail-filter/libmilter/libmilter-1.0.2_p1.ebuild | 1 +
24 2 files changed, 43 insertions(+)
25
26 diff --git a/mail-filter/libmilter/files/libmilter-musl-stack-size.patch b/mail-filter/libmilter/files/libmilter-musl-stack-size.patch
27 new file mode 100644
28 index 00000000000..9993adfece3
29 --- /dev/null
30 +++ b/mail-filter/libmilter/files/libmilter-musl-stack-size.patch
31 @@ -0,0 +1,42 @@
32 +Set default pthread stack size to 256 KB
33 +
34 +This patch tries to fix various crashes for applications depending on libmilter
35 +by setting the stack size for pthreads to 256 KB. The default stack size for
36 +musl libc is set to 80 KB whereas glibc has it set to 8 MB. This causes problems
37 +when a large amount of memory is allocated on the stack.
38 +
39 +For example, opendkim allocates blocks of 64 KB multiple times, which causes
40 +libmilter (and therefore opendkim) to crash. For now, a stack size of 256 KB
41 +looks sufficient and makes opendkim stop crashing.
42 +
43 +Fixes https://bugs.alpinelinux.org/issues/6360
44 +
45 +--- a/libmilter/libmilter.h
46 ++++ b/libmilter/libmilter.h
47 +@@ -127,10 +127,10 @@
48 + # define MI_SOCK_READ(s, b, l) read(s, b, l)
49 + # define MI_SOCK_READ_FAIL(x) ((x) < 0)
50 + # define MI_SOCK_WRITE(s, b, l) write(s, b, l)
51 +-
52 +-# define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg)
53 + # define sthread_get_id() pthread_self()
54 +
55 ++extern int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg);
56 ++
57 + typedef pthread_mutex_t smutex_t;
58 + # define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0)
59 + # define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0)
60 +--- a/libmilter/main.c
61 ++++ b/libmilter/main.c
62 +@@ -16,6 +16,12 @@
63 + #include <fcntl.h>
64 + #include <sys/stat.h>
65 +
66 ++int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg) {
67 ++ pthread_attr_t attr;
68 ++ pthread_attr_init(&attr);
69 ++ pthread_attr_setstacksize(&attr,256*1024);
70 ++ return pthread_create(ptid, &attr, wr, arg);
71 ++}
72 +
73 + static smfiDesc_ptr smfi = NULL;
74
75 diff --git a/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild b/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild
76 index e197eb05925..b9a1147970d 100644
77 --- a/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild
78 +++ b/mail-filter/libmilter/libmilter-1.0.2_p1.ebuild
79 @@ -45,6 +45,7 @@ src_prepare() {
80 if use elibc_musl; then
81 use ipv6 && ENVDEF="${ENVDEF} -DNEEDSGETIPNODE"
82
83 + eapply "${FILESDIR}/${PN}-musl-stack-size.patch"
84 eapply "${FILESDIR}/${PN}-musl-disable-cdefs.patch"
85 fi