From: Paul Moore <paul@paul-moore.com>
To: luhuaxin <luhuaxin1@huawei.com>
Cc: linux-audit@redhat.com, linux-kernel@vger.kernel.org,
eparis@redhat.com, fangxiuning@huawei.com
Subject: Re: [PATCH -next 1/1] audit: ignore userspace log when backlog limit exceeded and backlog_wait_time is 0
Date: Tue, 28 Dec 2021 20:20:51 -0500 [thread overview]
Message-ID: <CAHC9VhR_w6sfKf3uegXkvKg26VNsr7pCJJjxzBoS-C0GmVt-dQ@mail.gmail.com> (raw)
In-Reply-To: <20211228065023.118744-2-luhuaxin1@huawei.com>
On Tue, Dec 28, 2021 at 1:50 AM luhuaxin <luhuaxin1@huawei.com> wrote:
>
> When the backlog exceed the backlog_limit and backlog_wait_time is set
> to 0, the process will only sleep for a very short time (jiffies). The
> backlog may still exceed backlog_limit in extreme cases.
>
> The more reasonable way to fix this problem is:
>
> 1. If backlog_wait_time is set to zero, ignore the log;
> 2. If backlog_wait_time is set to non-zero, let process sleep for
> backlog_wait_time.
>
> The above log limit logic is also the same as that in the existing
> audit_log_start function.
>
> Fixes: 8f110f530635 ("[PATCH] audit: ensure userspace is penalized the
> same as the kernel when under pressure")
One quick comment on the "Fixes" tag above: you shouldn't add the
"[PATCH]" string to the commit's subject, you should use the commit
subject that you would see if you typed `git log --oneline`. It also
shouldn't be word-wrapped, it should be all on one line in your
patch/email.
Regardless of the above, I don't think this is a patch we want to
merge upstream. I can understand the desire to improve performance,
but this doesn't seem appropriate to me; adjusting the
backlog_wait_time to very low values just so you can drop audit
records is not an approach we want to advocate, or support, upstream.
> Signed-off-by: luhuaxin <luhuaxin1@huawei.com>
> ---
> kernel/audit.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 249e11628..70450f70a 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -1545,7 +1545,8 @@ static void audit_receive(struct sk_buff *skb)
>
> /* can't block with the ctrl lock, so penalize the sender now */
> if (audit_backlog_limit &&
> - (skb_queue_len(&audit_queue) > audit_backlog_limit)) {
> + (skb_queue_len(&audit_queue) > audit_backlog_limit) &&
> + audit_backlog_wait_time) {
> DECLARE_WAITQUEUE(wait, current);
>
> /* wake kauditd to try and flush the queue */
> @@ -1842,9 +1843,8 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
> * while holding the mutex, although we do penalize the sender
> * later in audit_receive() when it is safe to block
> */
> + long stime = audit_backlog_wait_time;
> if (!(auditd_test_task(current) || audit_ctl_owner_current())) {
> - long stime = audit_backlog_wait_time;
> -
> while (audit_backlog_limit &&
> (skb_queue_len(&audit_queue) > audit_backlog_limit)) {
> /* wake kauditd to try and flush the queue */
> @@ -1872,6 +1872,14 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
> return NULL;
> }
> }
> + } else if (!stime && audit_backlog_limit &&
> + (skb_queue_len(&audit_queue) > audit_backlog_limit)) {
> + if (audit_rate_check() && printk_ratelimit())
> + pr_warn("audit_backlog=%d > audit_backlog_limit=%d\n",
> + skb_queue_len(&audit_queue),
> + audit_backlog_limit);
> + audit_log_lost("backlog limit exceeded");
> + return NULL;
> }
>
> ab = audit_buffer_alloc(ctx, gfp_mask, type);
> --
> 2.23.0
--
paul moore
www.paul-moore.com
--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit
prev parent reply other threads:[~2021-12-29 1:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-28 6:50 [PATCH -next 0/1] audit: ignore userspace log when backlog limit exceeded and backlog_wait_time is 0 luhuaxin
2021-12-28 6:50 ` [PATCH -next 1/1] " luhuaxin
2021-12-29 1:20 ` Paul Moore [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=CAHC9VhR_w6sfKf3uegXkvKg26VNsr7pCJJjxzBoS-C0GmVt-dQ@mail.gmail.com \
--to=paul@paul-moore.com \
--cc=eparis@redhat.com \
--cc=fangxiuning@huawei.com \
--cc=linux-audit@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luhuaxin1@huawei.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).