From: Oleg Nesterov <oleg@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: linux-audit@redhat.com, linux-kernel@vger.kernel.org,
Andi Kleen <andi@firstfloor.org>, Steve Grubb <sgrubb@redhat.com>,
Eric Paris <eparis@redhat.com>
Subject: Re: [PATCH v3] audit: Turn off TIF_SYSCALL_AUDIT when there are no rules
Date: Mon, 10 Feb 2014 17:57:23 +0100 [thread overview]
Message-ID: <20140210165723.GA10856@redhat.com> (raw)
In-Reply-To: <ee359482b77f8f633014ec300bc5a4b93f8961e8.1391893528.git.luto@amacapital.net>
On 02/08, Andy Lutomirski wrote:
>
> +void audit_inc_n_rules()
> +{
> + struct task_struct *p, *t;
> +
> + read_lock(&tasklist_lock);
> + audit_n_rules++;
> + smp_wmb();
> + if (audit_n_rules == 1) {
> + /*
> + * We now have a rule; we need to hook syscall entry.
> + */
> + for_each_process_thread(p, t) {
> + if (t->audit_context)
> + set_tsk_thread_flag(t, TIF_SYSCALL_AUDIT);
> + }
> + }
> + read_unlock(&tasklist_lock);
> +}
> +
> +void audit_dec_n_rules()
> +{
> + read_lock(&tasklist_lock);
> + --audit_n_rules;
> + BUG_ON(audit_n_rules < 0);
> +
> + /*
> + * If audit_n_rules == 0, then __audit_syscall_exit will clear
> + * TIF_SYSCALL_AUDIT.
> + */
> +
> + read_unlock(&tasklist_lock);
> +}
To be honest, I do not understand why _dec_ takes tasklist_lock...
And why _inc_ increments audit_n_rules under tasklist.
> @@ -1528,6 +1562,25 @@ void __audit_syscall_exit(int success, long return_code)
> context->filterkey = NULL;
> }
> tsk->audit_context = context;
> +
> + if (ACCESS_ONCE(audit_n_rules) == 0) {
> + /*
> + * Either this is the very first syscall by this process or
> + * audit_dec_n_rules recently set audit_n_rules to zero.
> + */
> + smp_rmb();
rmb() looks wrong, we need mb() to serialize ACCESS_ONCE() and
clear_tsk_thread_flag().
But, otoh, I think we do not need any barrier at all, we can rely on
control dependency. See the recent 18c03c61444a21 "Documentation/
memory-barriers.txt: Prohibit speculative writes".
> + /* audit_inc_n_rules could increment audit_n_rules here... */
> +
> + clear_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
> +
> + smp_rmb();
Again, I guess this should be mb() or smp_mb__after_clear_bit().
And I still think this needs more changes. Once again, I do not think
that, say, __audit_log_bprm_fcaps() should populate context->aux if
!TIF_SYSCALL_AUDIT, this list can grow indefinitely. Or __audit_signal_info()...
Perhaps __audit_syscall_exit() should also set context->dummy?
Oleg.
next prev parent reply other threads:[~2014-02-10 16:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-08 21:06 [PATCH v3] audit: Turn off TIF_SYSCALL_AUDIT when there are no rules Andy Lutomirski
2014-02-10 16:57 ` Oleg Nesterov [this message]
2014-02-10 17:29 ` Andy Lutomirski
2014-02-10 17:47 ` Steve Grubb
2014-02-10 18:05 ` Andy Lutomirski
2014-02-10 19:01 ` Andy Lutomirski
2014-02-10 19:12 ` Steve Grubb
2014-02-10 19:12 ` Steve Grubb
2014-02-10 20:04 ` Andy Lutomirski
2014-02-18 17:32 ` Eric Paris
2014-02-18 17:31 ` Eric Paris
2014-02-18 20:17 ` Eric Paris
2014-02-18 20:17 ` Eric Paris
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=20140210165723.GA10856@redhat.com \
--to=oleg@redhat.com \
--cc=andi@firstfloor.org \
--cc=eparis@redhat.com \
--cc=linux-audit@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=sgrubb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.