Commit 16e1904e authored by Chris Wright's avatar Chris Wright Committed by David Woodhouse

AUDIT: Add helper functions to allocate and free audit_buffers.

Signed-off-by: default avatarChris Wright <chrisw@osdl.org>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent c2f0c7c3
...@@ -620,6 +620,42 @@ static int __init audit_enable(char *str) ...@@ -620,6 +620,42 @@ static int __init audit_enable(char *str)
__setup("audit=", audit_enable); __setup("audit=", audit_enable);
static void audit_buffer_free(struct audit_buffer *ab)
{
unsigned long flags;
atomic_dec(&audit_backlog);
spin_lock_irqsave(&audit_freelist_lock, flags);
if (++audit_freelist_count > AUDIT_MAXFREE)
kfree(ab);
else
list_add(&ab->list, &audit_freelist);
spin_unlock_irqrestore(&audit_freelist_lock, flags);
}
static struct audit_buffer * audit_buffer_alloc(int gfp_mask)
{
unsigned long flags;
struct audit_buffer *ab = NULL;
spin_lock_irqsave(&audit_freelist_lock, flags);
if (!list_empty(&audit_freelist)) {
ab = list_entry(audit_freelist.next,
struct audit_buffer, list);
list_del(&ab->list);
--audit_freelist_count;
}
spin_unlock_irqrestore(&audit_freelist_lock, flags);
if (!ab) {
ab = kmalloc(sizeof(*ab), GFP_ATOMIC);
if (!ab)
goto out;
}
atomic_inc(&audit_backlog);
out:
return ab;
}
/* Obtain an audit buffer. This routine does locking to obtain the /* Obtain an audit buffer. This routine does locking to obtain the
* audit buffer, but then no locking is required for calls to * audit buffer, but then no locking is required for calls to
...@@ -630,7 +666,6 @@ __setup("audit=", audit_enable); ...@@ -630,7 +666,6 @@ __setup("audit=", audit_enable);
struct audit_buffer *audit_log_start(struct audit_context *ctx) struct audit_buffer *audit_log_start(struct audit_context *ctx)
{ {
struct audit_buffer *ab = NULL; struct audit_buffer *ab = NULL;
unsigned long flags;
struct timespec t; struct timespec t;
unsigned int serial; unsigned int serial;
...@@ -649,23 +684,12 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx) ...@@ -649,23 +684,12 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx)
return NULL; return NULL;
} }
spin_lock_irqsave(&audit_freelist_lock, flags); ab = audit_buffer_alloc(GFP_ATOMIC);
if (!list_empty(&audit_freelist)) {
ab = list_entry(audit_freelist.next,
struct audit_buffer, list);
list_del(&ab->list);
--audit_freelist_count;
}
spin_unlock_irqrestore(&audit_freelist_lock, flags);
if (!ab)
ab = kmalloc(sizeof(*ab), GFP_ATOMIC);
if (!ab) { if (!ab) {
audit_log_lost("out of memory in audit_log_start"); audit_log_lost("out of memory in audit_log_start");
return NULL; return NULL;
} }
atomic_inc(&audit_backlog);
skb_queue_head_init(&ab->sklist); skb_queue_head_init(&ab->sklist);
ab->ctx = ctx; ab->ctx = ctx;
...@@ -824,8 +848,6 @@ static void audit_log_end_irq(struct audit_buffer *ab) ...@@ -824,8 +848,6 @@ static void audit_log_end_irq(struct audit_buffer *ab)
* be called in an irq context. */ * be called in an irq context. */
static void audit_log_end_fast(struct audit_buffer *ab) static void audit_log_end_fast(struct audit_buffer *ab)
{ {
unsigned long flags;
BUG_ON(in_irq()); BUG_ON(in_irq());
if (!ab) if (!ab)
return; return;
...@@ -836,14 +858,7 @@ static void audit_log_end_fast(struct audit_buffer *ab) ...@@ -836,14 +858,7 @@ static void audit_log_end_fast(struct audit_buffer *ab)
if (audit_log_drain(ab)) if (audit_log_drain(ab))
return; return;
} }
audit_buffer_free(ab);
atomic_dec(&audit_backlog);
spin_lock_irqsave(&audit_freelist_lock, flags);
if (++audit_freelist_count > AUDIT_MAXFREE)
kfree(ab);
else
list_add(&ab->list, &audit_freelist);
spin_unlock_irqrestore(&audit_freelist_lock, flags);
} }
/* Send or queue the message in the audit buffer, depending on the /* Send or queue the message in the audit buffer, depending on the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment