Reference counter width of log messages and group/user handling
Hi all, These patches fix two segmentation fault and abort signal problems which we encountered in our use case of syslog-ng 2.0.8. Patch 1: "syslog-ng-2.0.8-refcounter.diff". If specifying more than about 256 "destination" directives inside one log directive, then the reference counter of a log message wraps. The reference counter width of LogMessage is expanded from 8 bit to unsigned int (32 bit). Reason: The reference counter wraps after 256 increments, which causes an abort() call when decrementing the reference counter below 0 at a later time. The additional 3 bytes per message in memory seem to be affordable. Patch 2: "syslog-ng-2.0.8-group.diff". Handling of "-g" and "-u" options is not mutual exclusive: If group is specified on the command line, but not the user, then the user is a NULL pointer. Calling initgroups() with a null pointer segfaults in our case. And once again, many thanks to Bazsi for the syslog-ng software. -- Roger -- --------------------------------------------------------------- addr://Kasinostrasse 30, CH-5001 Aarau fon://++41 62 823 9355 http://www.terreactive.com fax://++41 62 823 9356 --------------------------------------------------------------- Wir sichern Ihren Erfolg. terreActive AG --------------------------------------------------------------- --- syslog-ng-2.0.8-orig/src/logmsg.h 2008-01-26 16:15:14 +0100 +++ syslog-ng-2.0.8/src/logmsg.h 2008-02-08 13:58:48 +0100 @@ -77,7 +77,7 @@ typedef struct _LogMessage { - guint8 ref_cnt; + guint ref_cnt; guint8 flags; guint8 pri; guint8 num_re_matches; --- syslog-ng-2.0.8-orig/src/main.c 2007-12-27 11:55:59 +0100 +++ syslog-ng-2.0.8/src/main.c 2008-02-08 18:31:49 +0100 @@ -287,7 +287,8 @@ if (uid || gid || run_as_user) { setgid(gid); - initgroups(run_as_user, gid); + if (run_as_user) + initgroups(run_as_user, gid); setuid(uid); } return 1;
On Wed, 2008-02-13 at 10:04 +0100, Roger J. Meier wrote:
Hi all,
These patches fix two segmentation fault and abort signal problems which we encountered in our use case of syslog-ng 2.0.8.
Patch 1: "syslog-ng-2.0.8-refcounter.diff".
If specifying more than about 256 "destination" directives inside one log directive, then the reference counter of a log message wraps.
The reference counter width of LogMessage is expanded from 8 bit to unsigned int (32 bit). Reason: The reference counter wraps after 256 increments, which causes an abort() call when decrementing the reference counter below 0 at a later time. The additional 3 bytes per message in memory seem to be affordable.
This one does not affect syslog-ng 2.1 OSE, that one uses 32 bits when the SQL destination is enabled (threads are used, and atomic operations require int), and 16 bits when not. I'm trying to minimize LogMessage size as much as possible to minimize cache usage, however some extra bytes still fit in. 32 bit mode: syslog-ng 2.0: 104 bytes syslog-ng 2.1 OSE: 116 bytes syslog-ng 2.1 PE: 104 bytes I guess in 64 bit mode it becomes more than two cachelines, not good. I'm changing the refcounter to a 16 bit value, that'll permit about 65530 destination, is that enough for you? I've committed this patch, it avoids a hole by increasing the "flags" value as well. --- a/src/logmsg.h +++ b/src/logmsg.h @@ -77,8 +77,8 @@ void log_stamp_format(LogStamp *stamp, GString *target, gint ts_format, glong zo typedef struct _LogMessage { - guint8 ref_cnt; - guint8 flags; + guint16 ref_cnt; + guint16 flags; guint8 pri; guint8 num_re_matches; /* meta information */
Patch 2: "syslog-ng-2.0.8-group.diff".
Handling of "-g" and "-u" options is not mutual exclusive: If group is specified on the command line, but not the user, then the user is a NULL pointer. Calling initgroups() with a null pointer segfaults in our case.
Right, this is true, I've applied and pushed this patch in the syslog-ng 2.1 branch. I'll backport this to 2.0 once I get there.
And once again, many thanks to Bazsi for the syslog-ng software.
:) You are welcome. -- Bazsi
Hi Bazsi,
I'm changing the refcounter to a 16 bit value, that'll permit about 65530 destination, is that enough for you?
That's perfect for my use case, thanks! -- Roger -- --------------------------------------------------------------- addr://Kasinostrasse 30, CH-5001 Aarau fon://++41 62 823 9355 http://www.terreactive.com fax://++41 62 823 9356 --------------------------------------------------------------- Wir sichern Ihren Erfolg. terreActive AG ---------------------------------------------------------------
participants (2)
-
Balazs Scheidler
-
Roger J. Meier