diff options
Diffstat (limited to 'drivers/tty/tty_audit.c')
| -rw-r--r-- | drivers/tty/tty_audit.c | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c index 28f87fd6a28e..75542333c54a 100644 --- a/drivers/tty/tty_audit.c +++ b/drivers/tty/tty_audit.c @@ -10,13 +10,16 @@ #include <linux/audit.h> #include <linux/slab.h> #include <linux/tty.h> +#include "tty.h" + +#define TTY_AUDIT_BUF_SIZE 4096 struct tty_audit_buf { struct mutex mutex; /* Protects all data below */ dev_t dev; /* The TTY which the data is from */ - unsigned icanon:1; + bool icanon; size_t valid; - unsigned char *data; /* Allocated size N_TTY_BUF_SIZE */ + u8 *data; /* Allocated size TTY_AUDIT_BUF_SIZE */ }; static struct tty_audit_buf *tty_audit_buf_ref(void) @@ -32,16 +35,16 @@ static struct tty_audit_buf *tty_audit_buf_alloc(void) { struct tty_audit_buf *buf; - buf = kmalloc(sizeof(*buf), GFP_KERNEL); + buf = kzalloc(sizeof(*buf), GFP_KERNEL); if (!buf) goto err; - buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); + + buf->data = kmalloc(TTY_AUDIT_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: @@ -58,30 +61,30 @@ static void tty_audit_buf_free(struct tty_audit_buf *buf) } static void tty_audit_log(const char *description, dev_t dev, - unsigned char *data, size_t size) + const u8 *data, size_t size) { struct audit_buffer *ab; pid_t pid = task_pid_nr(current); uid_t uid = from_kuid(&init_user_ns, task_uid(current)); uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current)); unsigned int sessionid = audit_get_sessionid(current); + char name[TASK_COMM_LEN]; - ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); - if (ab) { - char name[sizeof(current->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, current); - audit_log_untrustedstring(ab, name); - audit_log_format(ab, " data="); - audit_log_n_hex(ab, data, size); - audit_log_end(ab); - } + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY); + if (!ab) + return; + + 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, current); + audit_log_untrustedstring(ab, name); + audit_log_format(ab, " data="); + audit_log_n_hex(ab, data, size); + audit_log_end(ab); } -/** +/* * tty_audit_buf_push - Push buffered data out * * Generate an audit message from the contents of @buf, which is owned by @@ -120,7 +123,7 @@ void tty_audit_exit(void) tty_audit_buf_free(buf); } -/** +/* * tty_audit_fork - Copy TTY audit state for a new task * * Set up TTY audit state in @sig from current. @sig needs no locking. @@ -130,10 +133,10 @@ void tty_audit_fork(struct signal_struct *sig) sig->audit_tty = current->signal->audit_tty; } -/** +/* * tty_audit_tiocsti - Log TIOCSTI */ -void tty_audit_tiocsti(struct tty_struct *tty, char ch) +void tty_audit_tiocsti(const struct tty_struct *tty, u8 ch) { dev_t dev; @@ -145,7 +148,7 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch) tty_audit_log("ioctl=TIOCSTI", dev, &ch, 1); } -/** +/* * tty_audit_push - Flush current's pending audit data * * Returns 0 if success, -EPERM if tty audit is disabled @@ -166,7 +169,7 @@ int tty_audit_push(void) return 0; } -/** +/* * tty_audit_buf_get - Get an audit buffer. * * Get an audit buffer, allocate it if necessary. Return %NULL @@ -193,16 +196,17 @@ static struct tty_audit_buf *tty_audit_buf_get(void) return tty_audit_buf_ref(); } -/** +/* * 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) +void tty_audit_add_data(const 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; + bool icanon = L_ICANON(tty); dev_t dev; audit_tty = READ_ONCE(current->signal->audit_tty); @@ -233,14 +237,14 @@ void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size) do { size_t run; - run = N_TTY_BUF_SIZE - buf->valid; + run = TTY_AUDIT_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) + if (buf->valid == TTY_AUDIT_BUF_SIZE) tty_audit_buf_push(buf); } while (size != 0); mutex_unlock(&buf->mutex); |
