linux-audit.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: linux-audit@redhat.com
Cc: Richard Guy Briggs <rgb@redhat.com>,
	linux-kernel@vger.kernel.org, v.rathor@gmail.com
Subject: Re: [RFC PATCH 5/7] audit: allow audit_cmd_mutex holders to use reserves
Date: Thu, 05 Nov 2015 19:48:35 -0500	[thread overview]
Message-ID: <11488687.IdOeCSumoo@sifl> (raw)
In-Reply-To: <7f62a8c1d8cf031dda3c41bdf39ee4902e6f897e.1445539473.git.rgb@redhat.com>

On Thursday, October 22, 2015 02:53:18 PM Richard Guy Briggs wrote:
> If we hold the audit_cmd_mutex, we should never sleep waiting for auditd
> to drain the queue since auditd may need the mutex to shut down.
> 
> This was first implemented with mutex_trylock(), but since
> audit_log_start() can be called in softirq context, that won't work.
> Next, owner_running() was used to check audit_cmd_mutex but another
> process could have this locked on another cpu.  Use rcu_read_lock() and
> ACCESS_ONCE() to check audit_cmd_mutex.
> 
> Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
> ---
>  kernel/audit.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)

Ungh.  This is painful ... and I'm talking about the problem, not necessarily 
the solution your proposing here.  I'm going to pass on this patch for now 
because I'd like to see us step back and reexamine our approach here.

When it comes down to it, audit_cmd_mutex is really just there because we 
don't have proper, granular locking in audit_receive_msg(), right?  Looking 
quickly at it, it appears that AUDIT_GET/SET could be dealt with via a 
spinlock (we could add RCU if GET is frequent) ... similar could be done with 
AUDIT_GET/SET_FEATURE ... AUDIT_USER is a little more complex and not 
immediately obvious, but it looks like most of the pain points 
(audit_filter_user() and tty_audit_push_current() are already safe ... 
AUDIT_ADD/DEL_RULE look to be already protected via the audit_filter_mutex ... 
same with AUDIT_LIST_RULES ... same with AUDIT_TRIM ... same with 
AUDIT_MAKE_EQUIV ... AUDIT_SIGNAL_INFO shouldn't be a problem ... 
AUDIT_TTY_GET/SET already have spinlocks.

Am I missing something?

> diff --git a/kernel/audit.c b/kernel/audit.c
> index 02a5ec0..34411af 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -1376,12 +1376,15 @@ struct audit_buffer *audit_log_start(struct
> audit_context *ctx, gfp_t gfp_mask, return NULL;
> 
>  	if (gfp_mask & __GFP_WAIT) {
> -		if (current->tgid == 1 || (audit_pid && audit_pid == current->tgid))
> +		rcu_read_lock();
> +		if (ACCESS_ONCE(audit_cmd_mutex.owner) == current ||
> +		    current->tgid == 1 ||
> +		    (audit_pid && audit_pid == current->tgid))
>  			gfp_mask &= ~__GFP_WAIT;
>  		else
>  			reserve = 0;
> +		rcu_read_unlock();
>  	}
> -
>  	while (audit_backlog_limit
>  	       && skb_queue_len(&audit_skb_queue) > audit_backlog_limit + reserve)
> { if (gfp_mask & __GFP_WAIT && audit_backlog_wait_time) {

-- 
paul moore
www.paul-moore.com

  reply	other threads:[~2015-11-06  0:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-22 18:53 [RFC PATCH 0/7] audit: clean up audit queue handling Richard Guy Briggs
2015-10-22 18:53 ` [RFC PATCH 1/7] audit: don't needlessly reset valid wait time Richard Guy Briggs
2015-11-04 23:03   ` Paul Moore
2015-11-05  3:13     ` Richard Guy Briggs
2015-11-05 15:17       ` Paul Moore
2015-10-22 18:53 ` [RFC PATCH 2/7] audit: include auditd's threads in audit_log_start() wait exception Richard Guy Briggs
2015-11-04 23:08   ` Paul Moore
2015-10-22 18:53 ` [RFC PATCH 3/7] audit: allow systemd to use queue reserves Richard Guy Briggs
2015-10-22 19:26   ` Steve Grubb
2015-10-22 19:51     ` Richard Guy Briggs
2015-11-05 22:38       ` Paul Moore
2016-06-15 17:35         ` Richard Guy Briggs
2015-10-22 18:53 ` [RFC PATCH 4/7] audit: wake up threads if queue switched from limited to unlimited Richard Guy Briggs
2015-11-06  0:05   ` Paul Moore
2015-10-22 18:53 ` [RFC PATCH 5/7] audit: allow audit_cmd_mutex holders to use reserves Richard Guy Briggs
2015-11-06  0:48   ` Paul Moore [this message]
2015-10-22 18:53 ` [RFC PATCH 6/7] audit: wake up audit_backlog_wait queue when auditd goes away Richard Guy Briggs
2015-11-06  1:21   ` Paul Moore
2015-10-22 18:53 ` [RFC PATCH 7/7] audit: wake up kauditd_thread after auditd registers Richard Guy Briggs
2015-11-06  1:23   ` Paul Moore
2015-10-27 18:44 ` [RFC PATCH 0/7] audit: clean up audit queue handling Paul Moore
2015-10-28 18:43   ` Richard Guy Briggs
2015-10-28 18:58     ` 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=11488687.IdOeCSumoo@sifl \
    --to=paul@paul-moore.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rgb@redhat.com \
    --cc=v.rathor@gmail.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 NNTP newsgroup(s).