Commit fbaa1227 authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: audit: Simplify first-use allocation

The first-use tty audit buffer allocation is a potential race
amongst multiple attempts at 'first-use'; only one 'winner' is
acceptable.

The successful buffer assignment occurs if tty_audit_buf == NULL
(which will also be the return from cmpxchg()); otherwise, another
racer 'won' and this buffer allocation is freed.
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5493090f
...@@ -181,30 +181,22 @@ int tty_audit_push(void) ...@@ -181,30 +181,22 @@ int tty_audit_push(void)
*/ */
static struct tty_audit_buf *tty_audit_buf_get(void) static struct tty_audit_buf *tty_audit_buf_get(void)
{ {
struct tty_audit_buf *buf, *buf2; struct tty_audit_buf *buf;
unsigned long flags;
buf = current->signal->tty_audit_buf; buf = current->signal->tty_audit_buf;
if (buf) if (buf)
return buf; return buf;
buf2 = tty_audit_buf_alloc(); buf = tty_audit_buf_alloc();
if (buf2 == NULL) { if (buf == NULL) {
audit_log_lost("out of memory in TTY auditing"); audit_log_lost("out of memory in TTY auditing");
return NULL; return NULL;
} }
spin_lock_irqsave(&current->sighand->siglock, flags); /* Race to use this buffer, free it if another wins */
buf = current->signal->tty_audit_buf; if (cmpxchg(&current->signal->tty_audit_buf, NULL, buf) != NULL)
if (!buf) { tty_audit_buf_free(buf);
current->signal->tty_audit_buf = buf2; return current->signal->tty_audit_buf;
buf = buf2;
buf2 = NULL;
}
spin_unlock_irqrestore(&current->sighand->siglock, flags);
if (buf2)
tty_audit_buf_free(buf2);
return buf;
} }
/** /**
......
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