Linux-audit Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Guy Briggs <rgb@redhat.com>
To: Paul Moore <paul@paul-moore.com>
Cc: linux-audit@redhat.com, Gaosheng Cui <cuigaosheng1@huawei.com>
Subject: Re: [PATCH] audit: ensure userspace is penalized the same as the kernel when under pressure
Date: Wed, 15 Dec 2021 12:42:24 -0500	[thread overview]
Message-ID: <20211215174224.GS1550715@madcap2.tricolour.ca> (raw)
In-Reply-To: <163949858723.23091.5301356986109432893.stgit@olly>

On 2021-12-14 11:16, Paul Moore wrote:
> Due to the audit control mutex necessary for serializing audit
> userspace messages we haven't been able to block/penalize userspace
> processes that attempt to send audit records while the system is
> under audit pressure.  The result is that privileged userspace
> applications have a priority boost with respect to audit as they are
> not bound by the same audit queue throttling as the other tasks on
> the system.
> 
> This patch attempts to restore some balance to the system when under
> audit pressure by blocking these privileged userspace tasks after
> they have finished their audit processing, and dropped the audit
> control mutex, but before they return to userspace.

I can't speak to the exact wait queue mechanism here, but this seems
like a reasonable action in this location.  FWIW: Reviewed-by

> Reported-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> Signed-off-by: Paul Moore <paul@paul-moore.com>
> ---
>  kernel/audit.c |   18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 4cebadb5f30d..eab7282668ab 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -1540,6 +1540,20 @@ static void audit_receive(struct sk_buff  *skb)
>  		nlh = nlmsg_next(nlh, &len);
>  	}
>  	audit_ctl_unlock();
> +
> +	/* can't block with the ctrl lock, so penalize the sender now */
> +	if (audit_backlog_limit &&
> +	    (skb_queue_len(&audit_queue) > audit_backlog_limit)) {
> +		DECLARE_WAITQUEUE(wait, current);
> +
> +		/* wake kauditd to try and flush the queue */
> +		wake_up_interruptible(&kauditd_wait);
> +
> +		add_wait_queue_exclusive(&audit_backlog_wait, &wait);
> +		set_current_state(TASK_UNINTERRUPTIBLE);
> +		schedule_timeout(audit_backlog_wait_time);
> +		remove_wait_queue(&audit_backlog_wait, &wait);
> +	}
>  }
>  
>  /* Log information about who is connecting to the audit multicast socket */
> @@ -1824,7 +1838,9 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
>  	 *    task_tgid_vnr() since auditd_pid is set in audit_receive_msg()
>  	 *    using a PID anchored in the caller's namespace
>  	 * 2. generator holding the audit_cmd_mutex - we don't want to block
> -	 *    while holding the mutex */
> +	 *    while holding the mutex, although we do penalize the sender
> +	 *    later in audit_receive() when it is safe to block
> +	 */
>  	if (!(auditd_test_task(current) || audit_ctl_owner_current())) {
>  		long stime = audit_backlog_wait_time;
>  
> 
> --
> Linux-audit mailing list
> Linux-audit@redhat.com
> https://listman.redhat.com/mailman/listinfo/linux-audit
> 

- RGB

--
Richard Guy Briggs <rgb@redhat.com>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit


  parent reply	other threads:[~2021-12-15 17:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14 16:16 [PATCH] audit: ensure userspace is penalized the same as the kernel when under pressure Paul Moore
2021-12-15  1:26 ` cuigaosheng
2021-12-15 17:42 ` Richard Guy Briggs [this message]
2021-12-15 18:15 ` Paul Moore

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=20211215174224.GS1550715@madcap2.tricolour.ca \
    --to=rgb@redhat.com \
    --cc=cuigaosheng1@huawei.com \
    --cc=linux-audit@redhat.com \
    --cc=paul@paul-moore.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