Release 4.11 drivers/tty/tty_audit.c
/*
* Creating audit events from TTY input.
*
* Copyright (C) 2007 Red Hat, Inc. All rights reserved. This copyrighted
* material is made available to anyone wishing to use, modify, copy, or
* redistribute it subject to the terms and conditions of the GNU General
* Public License v.2.
*
* Authors: Miloslav Trmac <mitr@redhat.com>
*/
#include <linux/audit.h>
#include <linux/slab.h>
#include <linux/tty.h>
struct tty_audit_buf {
struct mutex mutex; /* Protects all data below */
dev_t dev; /* The TTY which the data is from */
unsigned icanon:1;
size_t valid;
unsigned char *data; /* Allocated size N_TTY_BUF_SIZE */
};
static struct tty_audit_buf *tty_audit_buf_ref(void)
{
struct tty_audit_buf *buf;
buf = current->signal->tty_audit_buf;
WARN_ON(buf == ERR_PTR(-ESRCH));
return buf;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Peter Hurley | 37 | 100.00% | 1 | 100.00% |
Total | 37 | 100.00% | 1 | 100.00% |
static struct tty_audit_buf *tty_audit_buf_alloc(void)
{
struct tty_audit_buf *buf;
buf = kmalloc(sizeof(*buf), GFP_KERNEL);
if (!buf)
goto err;
buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
if (!buf->data)
goto err_buf;
mutex_init(&buf->mutex);
buf->dev = MKDEV(0, 0);
buf->icanon = 0;
buf->valid = 0;
return buf;
err_buf:
kfree(buf);
err:
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 94 | 91.26% | 1 | 33.33% |
Peter Hurley | 9 | 8.74% | 2 | 66.67% |
Total | 103 | 100.00% | 3 | 100.00% |
static void tty_audit_buf_free(struct tty_audit_buf *buf)
{
WARN_ON(buf->valid != 0);
kfree(buf->data);
kfree(buf);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 32 | 100.00% | 1 | 100.00% |
Total | 32 | 100.00% | 1 | 100.00% |
static void tty_audit_log(const char *description, dev_t dev,
unsigned char *data, size_t size)
{
struct audit_buffer *ab;
struct task_struct *tsk = current;
pid_t pid = task_pid_nr(tsk);
uid_t uid = from_kuid(&init_user_ns, task_uid(tsk));
uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(tsk));
unsigned int sessionid = audit_get_sessionid(tsk);
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY);
if (ab) {
char name[sizeof(tsk->comm)];
audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
" minor=%d comm=", description, pid, uid,
loginuid, sessionid, MAJOR(dev), MINOR(dev));
get_task_comm(name, tsk);
audit_log_untrustedstring(ab, name);
audit_log_format(ab, " data=");
audit_log_n_hex(ab, data, size);
audit_log_end(ab);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 85 | 50.00% | 2 | 20.00% |
Eric Paris | 49 | 28.82% | 4 | 40.00% |
Al Viro | 17 | 10.00% | 1 | 10.00% |
Peter Hurley | 10 | 5.88% | 1 | 10.00% |
Richard Guy Briggs | 8 | 4.71% | 1 | 10.00% |
Eric W. Biedermann | 1 | 0.59% | 1 | 10.00% |
Total | 170 | 100.00% | 10 | 100.00% |
/**
* tty_audit_buf_push - Push buffered data out
*
* Generate an audit message from the contents of @buf, which is owned by
* the current task. @buf->mutex must be locked.
*/
static void tty_audit_buf_push(struct tty_audit_buf *buf)
{
if (buf->valid == 0)
return;
if (audit_enabled == 0) {
buf->valid = 0;
return;
}
tty_audit_log("tty", buf->dev, buf->data, buf->valid);
buf->valid = 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Al Viro | 42 | 72.41% | 1 | 25.00% |
Xiaotian Feng | 8 | 13.79% | 1 | 25.00% |
Miloslav Trmač | 7 | 12.07% | 1 | 25.00% |
Peter Hurley | 1 | 1.72% | 1 | 25.00% |
Total | 58 | 100.00% | 4 | 100.00% |
/**
* tty_audit_exit - Handle a task exit
*
* Make sure all buffered data is written out and deallocate the buffer.
* Only needs to be called if current->signal->tty_audit_buf != %NULL.
*
* The process is single-threaded at this point; no other threads share
* current->signal.
*/
void tty_audit_exit(void)
{
struct tty_audit_buf *buf;
buf = xchg(¤t->signal->tty_audit_buf, ERR_PTR(-ESRCH));
if (!buf)
return;
tty_audit_buf_push(buf);
tty_audit_buf_free(buf);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 34 | 73.91% | 1 | 25.00% |
Peter Hurley | 11 | 23.91% | 2 | 50.00% |
Eric Paris | 1 | 2.17% | 1 | 25.00% |
Total | 46 | 100.00% | 4 | 100.00% |
/**
* tty_audit_fork - Copy TTY audit state for a new task
*
* Set up TTY audit state in @sig from current. @sig needs no locking.
*/
void tty_audit_fork(struct signal_struct *sig)
{
sig->audit_tty = current->signal->audit_tty;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 20 | 100.00% | 1 | 100.00% |
Total | 20 | 100.00% | 1 | 100.00% |
/**
* tty_audit_tiocsti - Log TIOCSTI
*/
void tty_audit_tiocsti(struct tty_struct *tty, char ch)
{
dev_t dev;
dev = MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index;
if (tty_audit_push())
return;
if (audit_enabled)
tty_audit_log("ioctl=TIOCSTI", dev, &ch, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Al Viro | 47 | 79.66% | 1 | 33.33% |
Peter Hurley | 12 | 20.34% | 2 | 66.67% |
Total | 59 | 100.00% | 3 | 100.00% |
/**
* tty_audit_push - Flush current's pending audit data
*
* Returns 0 if success, -EPERM if tty audit is disabled
*/
int tty_audit_push(void)
{
struct tty_audit_buf *buf;
if (~current->signal->audit_tty & AUDIT_TTY_ENABLE)
return -EPERM;
buf = tty_audit_buf_ref();
if (!IS_ERR_OR_NULL(buf)) {
mutex_lock(&buf->mutex);
tty_audit_buf_push(buf);
mutex_unlock(&buf->mutex);
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 37 | 56.06% | 1 | 16.67% |
Peter Hurley | 24 | 36.36% | 3 | 50.00% |
Thomas Gleixner | 4 | 6.06% | 1 | 16.67% |
Eric Paris | 1 | 1.52% | 1 | 16.67% |
Total | 66 | 100.00% | 6 | 100.00% |
/**
* tty_audit_buf_get - Get an audit buffer.
*
* Get an audit buffer, allocate it if necessary. Return %NULL
* if out of memory or ERR_PTR(-ESRCH) if tty_audit_exit() has already
* occurred. Otherwise, return a new reference to the buffer.
*/
static struct tty_audit_buf *tty_audit_buf_get(void)
{
struct tty_audit_buf *buf;
buf = tty_audit_buf_ref();
if (buf)
return buf;
buf = tty_audit_buf_alloc();
if (buf == NULL) {
audit_log_lost("out of memory in TTY auditing");
return NULL;
}
/* Race to use this buffer, free it if another wins */
if (cmpxchg(¤t->signal->tty_audit_buf, NULL, buf) != NULL)
tty_audit_buf_free(buf);
return tty_audit_buf_ref();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 55 | 72.37% | 1 | 16.67% |
Peter Hurley | 19 | 25.00% | 4 | 66.67% |
Eric Paris | 2 | 2.63% | 1 | 16.67% |
Total | 76 | 100.00% | 6 | 100.00% |
/**
* tty_audit_add_data - Add data for TTY auditing.
*
* Audit @data of @size from @tty, if necessary.
*/
void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size)
{
struct tty_audit_buf *buf;
unsigned int icanon = !!L_ICANON(tty);
unsigned int audit_tty;
dev_t dev;
audit_tty = READ_ONCE(current->signal->audit_tty);
if (~audit_tty & AUDIT_TTY_ENABLE)
return;
if (unlikely(size == 0))
return;
if (tty->driver->type == TTY_DRIVER_TYPE_PTY
&& tty->driver->subtype == PTY_TYPE_MASTER)
return;
if ((~audit_tty & AUDIT_TTY_LOG_PASSWD) && icanon && !L_ECHO(tty))
return;
buf = tty_audit_buf_get();
if (IS_ERR_OR_NULL(buf))
return;
mutex_lock(&buf->mutex);
dev = MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index;
if (buf->dev != dev || buf->icanon != icanon) {
tty_audit_buf_push(buf);
buf->dev = dev;
buf->icanon = icanon;
}
do {
size_t run;
run = N_TTY_BUF_SIZE - buf->valid;
if (run > size)
run = size;
memcpy(buf->data + buf->valid, data, run);
buf->valid += run;
data += run;
size -= run;
if (buf->valid == N_TTY_BUF_SIZE)
tty_audit_buf_push(buf);
} while (size != 0);
mutex_unlock(&buf->mutex);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 172 | 65.40% | 1 | 9.09% |
Peter Hurley | 79 | 30.04% | 8 | 72.73% |
Richard Guy Briggs | 10 | 3.80% | 1 | 9.09% |
Eric Paris | 2 | 0.76% | 1 | 9.09% |
Total | 263 | 100.00% | 11 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Miloslav Trmač | 571 | 58.56% | 2 | 7.69% |
Peter Hurley | 207 | 21.23% | 12 | 46.15% |
Al Viro | 107 | 10.97% | 1 | 3.85% |
Eric Paris | 56 | 5.74% | 5 | 19.23% |
Richard Guy Briggs | 18 | 1.85% | 2 | 7.69% |
Xiaotian Feng | 8 | 0.82% | 1 | 3.85% |
Thomas Gleixner | 4 | 0.41% | 1 | 3.85% |
Tejun Heo | 3 | 0.31% | 1 | 3.85% |
Eric W. Biedermann | 1 | 0.10% | 1 | 3.85% |
Total | 975 | 100.00% | 26 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.