* [PATCH] Fix 100% CPU usage (again) due to log rotate
@ 2019-10-25 19:37 Steven Rostedt (VMware)
2019-10-28 22:53 ` Steve Grubb
0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt (VMware) @ 2019-10-25 19:37 UTC (permalink / raw)
To: linux-audit
Cc: Srikantha Munipemmareddy, Ravi Soundararajan, Clark Williams,
Stepan Broz, Tanmay Nag, Darren Hart, Joseph Zuk, Srivatsa Bhat,
Loi Tran
If the num_logs is set to 0 and keep_logs is set, we go back into a
loop of MAX_INT! in rotate_logs().
commit 9145e97c ("Do not rotate logs when num_logs < 2.") fixed the
issue with not going further if num_logs is less than 2, because if
num_logs is zero, we trigger this bug because of the loop:
for (i=num_logs - 1; i>1; i--) {
As i is an unsigned int, if num_logs is zero, we initialize i to
"0 - 1" or 4,294,967,295. Thus, runs this loop over 4 billion times!
But this caused a regressing if keep_logs is set, so this
num_logs < 2 was skipped if keep_logs is set, causing the huge loop
to run once again if num_logs is zero!
There's no reason i needs to be unsigned, if i is signed, then if we
pass in num_logs = 0, then i will start off as -1, and -1 > 1 will fail
the loop and fix the issue. I don't envision anyone wanting to
keep 2,147,483,648 log files around.
Fixes: a7f9f8b5 ("Fix auditd regression where keep_logs is limited by rotate_logs 2 file test")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
diff --git a/src/auditd-event.c b/src/auditd-event.c
index 1c93173..68eacd5 100644
--- a/src/auditd-event.c
+++ b/src/auditd-event.c
@@ -1012,8 +1012,8 @@ static void fix_disk_permissions(void)
static void rotate_logs(unsigned int num_logs, unsigned int keep_logs)
{
- int rc;
- unsigned int len, i;
+ int rc, i;
+ unsigned int len;
char *oldname, *newname;
/* Check that log rotation is enabled in the configuration file. There
@@ -1065,7 +1065,7 @@ static void rotate_logs(unsigned int num_logs, unsigned int keep_logs)
snprintf(oldname, len, "%s.1", config->log_file);
known_logs = 0;
- for (i=num_logs - 1; i>1; i--) {
+ for (i=(int)num_logs - 1; i>1; i--) {
snprintf(oldname, len, "%s.%u", config->log_file, i-1);
snprintf(newname, len, "%s.%u", config->log_file, i);
/* if the old file exists */
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] Fix 100% CPU usage (again) due to log rotate
2019-10-25 19:37 [PATCH] Fix 100% CPU usage (again) due to log rotate Steven Rostedt (VMware)
@ 2019-10-28 22:53 ` Steve Grubb
0 siblings, 0 replies; 2+ messages in thread
From: Steve Grubb @ 2019-10-28 22:53 UTC (permalink / raw)
To: Steven Rostedt (VMware)
Cc: Srikantha Munipemmareddy, Soundararajan, Clark Williams,
Stepan Broz, Srivatsa, Tanmay Nag, Darren Hart, Ravi, Joseph Zuk,
linux-audit, Bhat, Loi Tran
On Fri, 25 Oct 2019 15:37:09 -0400
"Steven Rostedt (VMware)" <rostedt@goodmis.org> wrote:
> If the num_logs is set to 0 and keep_logs is set, we go back into a
> loop of MAX_INT! in rotate_logs().
Thanks. Applied.
-Steve
> commit 9145e97c ("Do not rotate logs when num_logs < 2.") fixed the
> issue with not going further if num_logs is less than 2, because if
> num_logs is zero, we trigger this bug because of the loop:
>
> for (i=num_logs - 1; i>1; i--) {
>
> As i is an unsigned int, if num_logs is zero, we initialize i to
> "0 - 1" or 4,294,967,295. Thus, runs this loop over 4 billion times!
>
> But this caused a regressing if keep_logs is set, so this
> num_logs < 2 was skipped if keep_logs is set, causing the huge loop
> to run once again if num_logs is zero!
>
> There's no reason i needs to be unsigned, if i is signed, then if we
> pass in num_logs = 0, then i will start off as -1, and -1 > 1 will
> fail the loop and fix the issue. I don't envision anyone wanting to
> keep 2,147,483,648 log files around.
>
> Fixes: a7f9f8b5 ("Fix auditd regression where keep_logs is limited by
> rotate_logs 2 file test") Signed-off-by: Steven Rostedt (VMware)
> <rostedt@goodmis.org> ---
> diff --git a/src/auditd-event.c b/src/auditd-event.c
> index 1c93173..68eacd5 100644
> --- a/src/auditd-event.c
> +++ b/src/auditd-event.c
> @@ -1012,8 +1012,8 @@ static void fix_disk_permissions(void)
>
> static void rotate_logs(unsigned int num_logs, unsigned int
> keep_logs) {
> - int rc;
> - unsigned int len, i;
> + int rc, i;
> + unsigned int len;
> char *oldname, *newname;
>
> /* Check that log rotation is enabled in the configuration
> file. There @@ -1065,7 +1065,7 @@ static void rotate_logs(unsigned
> int num_logs, unsigned int keep_logs) snprintf(oldname, len, "%s.1",
> config->log_file);
> known_logs = 0;
> - for (i=num_logs - 1; i>1; i--) {
> + for (i=(int)num_logs - 1; i>1; i--) {
> snprintf(oldname, len, "%s.%u", config->log_file,
> i-1); snprintf(newname, len, "%s.%u", config->log_file, i);
> /* if the old file exists */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-28 22:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-25 19:37 [PATCH] Fix 100% CPU usage (again) due to log rotate Steven Rostedt (VMware)
2019-10-28 22:53 ` Steve Grubb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox