Skip to content

Commit

Permalink
audit, sched/wait: Fixup kauditd_thread() wait loop
Browse files Browse the repository at this point in the history
The kauditd_thread wait loop is a bit iffy; it has a number of problems:

 - calls try_to_freeze() before schedule(); you typically want the
   thread to re-evaluate the sleep condition when unfreezing, also
   freeze_task() issues a wakeup.

 - it unconditionally does the {add,remove}_wait_queue(), even when the
   sleep condition is false.

Use wait_event_freezable() that does the right thing.

Reported-by: Mike Galbraith <umgwanakikbuti@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Eric Paris <eparis@redhat.com>
Cc: oleg@redhat.com
Cc: Eric Paris <eparis@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20141002102251.GA6324@worktop.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Nov 4, 2014
1 parent 5d4d565 commit 6b55fc6
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ static int kauditd_thread(void *dummy)
set_freezable();
while (!kthread_should_stop()) {
struct sk_buff *skb;
DECLARE_WAITQUEUE(wait, current);

flush_hold_queue();

Expand All @@ -514,16 +513,8 @@ static int kauditd_thread(void *dummy)
audit_printk_skb(skb);
continue;
}
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&kauditd_wait, &wait);

if (!skb_queue_len(&audit_skb_queue)) {
try_to_freeze();
schedule();
}

__set_current_state(TASK_RUNNING);
remove_wait_queue(&kauditd_wait, &wait);
wait_event_freezable(kauditd_wait, skb_queue_len(&audit_skb_queue));
}
return 0;
}
Expand Down

0 comments on commit 6b55fc6

Please sign in to comment.