diff options
author | Li Zhou <li.zhou@windriver.com> | 2015-04-28 16:03:09 +0800 |
---|---|---|
committer | Martin Jansa <Martin.Jansa@gmail.com> | 2015-05-11 10:25:53 +0200 |
commit | e7e67108df29927e3ebc5e9566dbbcd3a6e553b0 (patch) | |
tree | 3d7ef9413495bc4737a71f3b291b3756be72f3cc | |
parent | 79167895ce1640cd2ca1414de4c418a03c55f29d (diff) | |
download | meta-openembedded-e7e67108df29927e3ebc5e9566dbbcd3a6e553b0.tar.gz |
rsyslogd: Backport upstream commits to fix rsyslog segmentation fault when heavy load
Backport <commit 9a775051f7373176c6e54bee1110965342dd41ad> and
<commit 17e1ee2539cea6bac16832b488afd52b20a348ac> from rsyslog
upstream <https://github.com/rsyslog/rsyslog> to solve issue:
rsyslog segmentation fault when heavy load.
Solve the race condition in GenerateLocalHostNameProperty between the
prop.Destruct(&propLocalHostName) and prop.Construct(&propLocalHostName).
Signed-off-by: Li Zhou <li.zhou@windriver.com>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
3 files changed, 196 insertions, 0 deletions
diff --git a/meta-oe/recipes-extended/rsyslog/rsyslog/0001-bugfix-potential-abort-during-HUP.patch b/meta-oe/recipes-extended/rsyslog/rsyslog/0001-bugfix-potential-abort-during-HUP.patch new file mode 100644 index 000000000..14e8b3f5a --- /dev/null +++ b/meta-oe/recipes-extended/rsyslog/rsyslog/0001-bugfix-potential-abort-during-HUP.patch | |||
@@ -0,0 +1,91 @@ | |||
1 | From 9a775051f7373176c6e54bee1110965342dd41ad Mon Sep 17 00:00:00 2001 | ||
2 | From: Rainer Gerhards <rgerhards@adiscon.com> | ||
3 | Date: Mon, 28 Oct 2013 12:56:02 +0100 | ||
4 | Subject: [PATCH] bugfix: potential abort during HUP | ||
5 | |||
6 | This could happen when one of imklog, imzmq3, imkmsg, impstats, | ||
7 | imjournal, or imuxsock were under heavy load during a HUP. | ||
8 | closes: http://bugzilla.adiscon.com/show_bug.cgi?id=489 | ||
9 | Thanks to Guy Rozendorn for reporting the problem and Peval Levhshin for | ||
10 | his analysis. | ||
11 | |||
12 | Upstream-Status: backport | ||
13 | |||
14 | Signed-off-by: Li Zhou <li.zhou@windriver.com> | ||
15 | --- | ||
16 | ChangeLog | 6 ++++++ | ||
17 | runtime/glbl.c | 25 ++++++++++++++++++------- | ||
18 | 2 files changed, 24 insertions(+), 7 deletions(-) | ||
19 | |||
20 | Index: rsyslog-7.4.4/ChangeLog | ||
21 | =================================================================== | ||
22 | --- rsyslog-7.4.4.orig/ChangeLog | ||
23 | +++ rsyslog-7.4.4/ChangeLog | ||
24 | @@ -1,5 +1,11 @@ | ||
25 | --------------------------------------------------------------------------- | ||
26 | Version 7.4.4 [v7.4-stable] 2013-09-03 | ||
27 | +- bugfix: potential abort during HUP | ||
28 | + This could happen when one of imklog, imzmq3, imkmsg, impstats, | ||
29 | + imjournal, or imuxsock were under heavy load during a HUP. | ||
30 | + closes: http://bugzilla.adiscon.com/show_bug.cgi?id=489 | ||
31 | + Thanks to Guy Rozendorn for reporting the problem and Peval Levhshin for | ||
32 | + his analysis. | ||
33 | - better error messages in GuardTime signature provider | ||
34 | Thanks to Ahto Truu for providing the patch. | ||
35 | - make rsyslog use the new json-c pkgconfig file if available | ||
36 | Index: rsyslog-7.4.4/runtime/glbl.c | ||
37 | =================================================================== | ||
38 | --- rsyslog-7.4.4.orig/runtime/glbl.c | ||
39 | +++ rsyslog-7.4.4/runtime/glbl.c | ||
40 | @@ -32,6 +32,7 @@ | ||
41 | #include <sys/types.h> | ||
42 | #include <sys/stat.h> | ||
43 | #include <unistd.h> | ||
44 | +#include <pthread.h> | ||
45 | #include <assert.h> | ||
46 | |||
47 | #include "rsyslog.h" | ||
48 | @@ -379,17 +380,24 @@ GetLocalDomain(void) | ||
49 | /* generate the local hostname property. This must be done after the hostname info | ||
50 | * has been set as well as PreserveFQDN. | ||
51 | * rgerhards, 2009-06-30 | ||
52 | + * NOTE: This function DELIBERATELY introduces a small memory leak in order to gain | ||
53 | + * speed. Each time it is called when a property name already exists, a new one is | ||
54 | + * allocated but the previous one is NOT freed. This is so that current readers can | ||
55 | + * continue to use the previous name. Otherwise, we would need to use read/write locks | ||
56 | + * to protect the update process. As this function is called extremely infrequently and | ||
57 | + * the memory leak is very small, this is totally accessible. Think that otherwise we | ||
58 | + * would need to place a read look each time the property is read, which is much more | ||
59 | + * frequent (once per message for the modules that use this local hostname!). | ||
60 | + * rgerhards, 2013-10-28 | ||
61 | */ | ||
62 | static rsRetVal | ||
63 | GenerateLocalHostNameProperty(void) | ||
64 | { | ||
65 | - DEFiRet; | ||
66 | + prop_t *hostnameNew; | ||
67 | uchar *pszName; | ||
68 | + DEFiRet; | ||
69 | |||
70 | - if(propLocalHostName != NULL) | ||
71 | - prop.Destruct(&propLocalHostName); | ||
72 | - | ||
73 | - CHKiRet(prop.Construct(&propLocalHostName)); | ||
74 | + CHKiRet(prop.Construct(&hostnameNew)); | ||
75 | if(LocalHostNameOverride == NULL) { | ||
76 | if(LocalHostName == NULL) | ||
77 | pszName = (uchar*) "[localhost]"; | ||
78 | @@ -403,8 +411,11 @@ GenerateLocalHostNameProperty(void) | ||
79 | pszName = LocalHostNameOverride; | ||
80 | } | ||
81 | DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName); | ||
82 | - CHKiRet(prop.SetString(propLocalHostName, pszName, ustrlen(pszName))); | ||
83 | - CHKiRet(prop.ConstructFinalize(propLocalHostName)); | ||
84 | + CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName))); | ||
85 | + CHKiRet(prop.ConstructFinalize(hostnameNew)); | ||
86 | + | ||
87 | + propLocalHostName = hostnameNew; | ||
88 | + /* inititional MEM LEAK for old value -- see function hdr comment! */ | ||
89 | |||
90 | finalize_it: | ||
91 | RETiRet; | ||
diff --git a/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch b/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch new file mode 100644 index 000000000..fcc5d8ebf --- /dev/null +++ b/meta-oe/recipes-extended/rsyslog/rsyslog/0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch | |||
@@ -0,0 +1,103 @@ | |||
1 | From 17e1ee2539cea6bac16832b488afd52b20a348ac Mon Sep 17 00:00:00 2001 | ||
2 | From: Rainer Gerhards <rgerhards@adiscon.com> | ||
3 | Date: Mon, 28 Oct 2013 14:17:56 +0100 | ||
4 | Subject: [PATCH] remove memleak introduced by GenerateLocalHostName HUP | ||
5 | bugfix | ||
6 | |||
7 | Upstream-Status: backport | ||
8 | |||
9 | Signed-off-by: Li Zhou <li.zhou@windriver.com> | ||
10 | --- | ||
11 | runtime/glbl.c | 45 ++++++++++++++++++++++++++++++++------------- | ||
12 | 1 file changed, 32 insertions(+), 13 deletions(-) | ||
13 | |||
14 | diff --git a/runtime/glbl.c b/runtime/glbl.c | ||
15 | index bcb3795..41d56c2 100644 | ||
16 | --- a/runtime/glbl.c | ||
17 | +++ b/runtime/glbl.c | ||
18 | @@ -72,6 +72,7 @@ static int option_DisallowWarning = 1; /* complain if message from disallowed se | ||
19 | static int bDisableDNS = 0; /* don't look up IP addresses of remote messages */ | ||
20 | static prop_t *propLocalIPIF = NULL;/* IP address to report for the local host (default is 127.0.0.1) */ | ||
21 | static prop_t *propLocalHostName = NULL;/* our hostname as FQDN - read-only after startup */ | ||
22 | +static prop_t *propLocalHostNameToDelete = NULL;/* see GenerateLocalHostName function hdr comment! */ | ||
23 | static uchar *LocalHostName = NULL;/* our hostname - read-only after startup, except HUP */ | ||
24 | static uchar *LocalHostNameOverride = NULL;/* user-overridden hostname - read-only after startup */ | ||
25 | static uchar *LocalFQDNName = NULL;/* our hostname as FQDN - read-only after startup, except HUP */ | ||
26 | @@ -380,24 +381,31 @@ GetLocalDomain(void) | ||
27 | /* generate the local hostname property. This must be done after the hostname info | ||
28 | * has been set as well as PreserveFQDN. | ||
29 | * rgerhards, 2009-06-30 | ||
30 | - * NOTE: This function DELIBERATELY introduces a small memory leak in order to gain | ||
31 | - * speed. Each time it is called when a property name already exists, a new one is | ||
32 | - * allocated but the previous one is NOT freed. This is so that current readers can | ||
33 | - * continue to use the previous name. Otherwise, we would need to use read/write locks | ||
34 | - * to protect the update process. As this function is called extremely infrequently and | ||
35 | - * the memory leak is very small, this is totally accessible. Think that otherwise we | ||
36 | - * would need to place a read look each time the property is read, which is much more | ||
37 | - * frequent (once per message for the modules that use this local hostname!). | ||
38 | + * NOTE: This function tries to avoid locking by not destructing the previous value | ||
39 | + * immediately. This is so that current readers can continue to use the previous name. | ||
40 | + * Otherwise, we would need to use read/write locks to protect the update process. | ||
41 | + * In order to do so, we save the previous value and delete it when we are called again | ||
42 | + * the next time. Note that this in theory is racy and can lead to a double-free. | ||
43 | + * In practice, however, the window of exposure to trigger this is extremely short | ||
44 | + * and as this functions is very infrequently being called (on HUP), the trigger | ||
45 | + * condition for this bug is so highly unlikely that it never occurs in practice. | ||
46 | + * Probably if you HUP rsyslog every few milliseconds, but who does that... | ||
47 | + * To further reduce risk potential, we do only update the property when there | ||
48 | + * actually is a hostname change, which makes it even less likely. | ||
49 | * rgerhards, 2013-10-28 | ||
50 | */ | ||
51 | static rsRetVal | ||
52 | GenerateLocalHostNameProperty(void) | ||
53 | { | ||
54 | + uchar *pszPrev; | ||
55 | + int lenPrev; | ||
56 | prop_t *hostnameNew; | ||
57 | uchar *pszName; | ||
58 | DEFiRet; | ||
59 | |||
60 | - CHKiRet(prop.Construct(&hostnameNew)); | ||
61 | + if(propLocalHostNameToDelete != NULL) | ||
62 | + prop.Destruct(&propLocalHostNameToDelete); | ||
63 | + | ||
64 | if(LocalHostNameOverride == NULL) { | ||
65 | if(LocalHostName == NULL) | ||
66 | pszName = (uchar*) "[localhost]"; | ||
67 | @@ -411,11 +419,20 @@ GenerateLocalHostNameProperty(void) | ||
68 | pszName = LocalHostNameOverride; | ||
69 | } | ||
70 | DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName); | ||
71 | - CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName))); | ||
72 | - CHKiRet(prop.ConstructFinalize(hostnameNew)); | ||
73 | |||
74 | - propLocalHostName = hostnameNew; | ||
75 | - /* inititional MEM LEAK for old value -- see function hdr comment! */ | ||
76 | + if(propLocalHostName == NULL) | ||
77 | + pszPrev = (uchar*)""; /* make sure strcmp() below does not match */ | ||
78 | + else | ||
79 | + prop.GetString(propLocalHostName, &pszPrev, &lenPrev); | ||
80 | + | ||
81 | + if(ustrcmp(pszPrev, pszName)) { | ||
82 | + /* we need to update */ | ||
83 | + CHKiRet(prop.Construct(&hostnameNew)); | ||
84 | + CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName))); | ||
85 | + CHKiRet(prop.ConstructFinalize(hostnameNew)); | ||
86 | + propLocalHostNameToDelete = propLocalHostName; | ||
87 | + propLocalHostName = hostnameNew; | ||
88 | + } | ||
89 | |||
90 | finalize_it: | ||
91 | RETiRet; | ||
92 | @@ -678,6 +695,8 @@ BEGINObjClassExit(glbl, OBJ_IS_CORE_MODULE) /* class, version */ | ||
93 | free(LocalHostNameOverride); | ||
94 | free(LocalFQDNName); | ||
95 | objRelease(prop, CORE_COMPONENT); | ||
96 | + if(propLocalHostNameToDelete != NULL) | ||
97 | + prop.Destruct(&propLocalHostNameToDelete); | ||
98 | DESTROY_ATOMIC_HELPER_MUT(mutTerminateInputs); | ||
99 | ENDObjClassExit(glbl) | ||
100 | |||
101 | -- | ||
102 | 1.7.9.5 | ||
103 | |||
diff --git a/meta-oe/recipes-extended/rsyslog/rsyslog_7.4.4.bb b/meta-oe/recipes-extended/rsyslog/rsyslog_7.4.4.bb index 5ab6a309d..e1dee5947 100644 --- a/meta-oe/recipes-extended/rsyslog/rsyslog_7.4.4.bb +++ b/meta-oe/recipes-extended/rsyslog/rsyslog_7.4.4.bb | |||
@@ -26,6 +26,8 @@ SRC_URI = "http://www.rsyslog.com/files/download/rsyslog/${BPN}-${PV}.tar.gz \ | |||
26 | file://rsyslog-fix-ptest-not-finish.patch \ | 26 | file://rsyslog-fix-ptest-not-finish.patch \ |
27 | file://rsyslog-use-serial-tests-config-needed-by-ptest.patch \ | 27 | file://rsyslog-use-serial-tests-config-needed-by-ptest.patch \ |
28 | file://json-0.12-fix.patch \ | 28 | file://json-0.12-fix.patch \ |
29 | file://0001-bugfix-potential-abort-during-HUP.patch \ | ||
30 | file://0001-remove-memleak-introduced-by-GenerateLocalHostName-H.patch \ | ||
29 | " | 31 | " |
30 | 32 | ||
31 | SRC_URI[md5sum] = "ebcc010a6205c28eb505c0fe862f32c6" | 33 | SRC_URI[md5sum] = "ebcc010a6205c28eb505c0fe862f32c6" |