From: Steve Grubb <sgrubb@redhat.com>
To: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Cc: Srikantha Munipemmareddy <smunipemmareddy@vmware.com>,
Soundararajan <ravi@vmware.com>,
Clark Williams <williams@redhat.com>,
Stepan Broz <sbroz@starbug.usersys.redhat.com>,
Srivatsa, Tanmay Nag <Tanmay@vmware.com>,
Darren Hart <dvhart@vmware.com>,
Ravi, Joseph Zuk <jzuk@vmware.com>,
linux-audit@redhat.com, Bhat <srivatsab@vmware.com>,
Loi Tran <loi@vmware.com>
Subject: Re: [PATCH] Fix 100% CPU usage (again) due to log rotate
Date: Mon, 28 Oct 2019 18:53:44 -0400 [thread overview]
Message-ID: <20191028185344.3e9bf236@ivy-bridge> (raw)
In-Reply-To: <20191025153709.2cdbaca5@gandalf.local.home>
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 */
prev parent reply other threads:[~2019-10-28 22:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191028185344.3e9bf236@ivy-bridge \
--to=sgrubb@redhat.com \
--cc=Tanmay@vmware.com \
--cc=dvhart@vmware.com \
--cc=jzuk@vmware.com \
--cc=linux-audit@redhat.com \
--cc=loi@vmware.com \
--cc=ravi@vmware.com \
--cc=rostedt@goodmis.org \
--cc=sbroz@starbug.usersys.redhat.com \
--cc=smunipemmareddy@vmware.com \
--cc=srivatsab@vmware.com \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox