Skip to content

Commit

Permalink
Audit: add TTY input auditing
Browse files Browse the repository at this point in the history
Add TTY input auditing, used to audit system administrator's actions.  This is
required by various security standards such as DCID 6/3 and PCI to provide
non-repudiation of administrator's actions and to allow a review of past
actions if the administrator seems to overstep their duties or if the system
becomes misconfigured for unknown reasons.  These requirements do not make it
necessary to audit TTY output as well.

Compared to an user-space keylogger, this approach records TTY input using the
audit subsystem, correlated with other audit events, and it is completely
transparent to the user-space application (e.g.  the console ioctls still
work).

TTY input auditing works on a higher level than auditing all system calls
within the session, which would produce an overwhelming amount of mostly
useless audit events.

Add an "audit_tty" attribute, inherited across fork ().  Data read from TTYs
by process with the attribute is sent to the audit subsystem by the kernel.
The audit netlink interface is extended to allow modifying the audit_tty
attribute, and to allow sending explanatory audit events from user-space (for
example, a shell might send an event containing the final command, after the
interactive command-line editing and history expansion is performed, which
might be difficult to decipher from the TTY input alone).

Because the "audit_tty" attribute is inherited across fork (), it would be set
e.g.  for sshd restarted within an audited session.  To prevent this, the
audit_tty attribute is cleared when a process with no open TTY file
descriptors (e.g.  after daemon startup) opens a TTY.

See https://www.redhat.com/archives/linux-audit/2007-June/msg00000.html for a
more detailed rationale document for an older version of this patch.

[[email protected]: build fix]
Signed-off-by: Miloslav Trmac <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Alan Cox <[email protected]>
Cc: Paul Fulghum <[email protected]>
Cc: Casey Schaufler <[email protected]>
Cc: Steve Grubb <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mtrmac authored and Linus Torvalds committed Jul 16, 2007
1 parent 4f27c00 commit 522ed77
Show file tree
Hide file tree
Showing 14 changed files with 518 additions and 21 deletions.
1 change: 1 addition & 0 deletions drivers/char/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ obj-y += misc.o
obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o \
consolemap_deftbl.o selection.o keyboard.o
obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
obj-$(CONFIG_AUDIT) += tty_audit.o
obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
obj-$(CONFIG_ESPSERIAL) += esp.o
obj-$(CONFIG_MVME147_SCC) += generic_serial.o vme_scc.o
Expand Down
20 changes: 16 additions & 4 deletions drivers/char/n_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include <linux/slab.h>
#include <linux/poll.h>
#include <linux/bitops.h>
#include <linux/audit.h>
#include <linux/file.h>

#include <asm/uaccess.h>
#include <asm/system.h>
Expand Down Expand Up @@ -78,6 +80,13 @@ static inline void free_buf(unsigned char *buf)
free_page((unsigned long) buf);
}

static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
unsigned char __user *ptr)
{
tty_audit_add_data(tty, &x, 1);
return put_user(x, ptr);
}

/**
* n_tty_set__room - receive space
* @tty: terminal
Expand Down Expand Up @@ -1153,6 +1162,7 @@ static int copy_from_read_buf(struct tty_struct *tty,
if (n) {
retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n);
n -= retval;
tty_audit_add_data(tty, &tty->read_buf[tty->read_tail], n);
spin_lock_irqsave(&tty->read_lock, flags);
tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1);
tty->read_cnt -= n;
Expand Down Expand Up @@ -1279,7 +1289,7 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
break;
cs = tty->link->ctrl_status;
tty->link->ctrl_status = 0;
if (put_user(cs, b++)) {
if (tty_put_user(tty, cs, b++)) {
retval = -EFAULT;
b--;
break;
Expand Down Expand Up @@ -1321,7 +1331,7 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,

/* Deal with packet mode. */
if (tty->packet && b == buf) {
if (put_user(TIOCPKT_DATA, b++)) {
if (tty_put_user(tty, TIOCPKT_DATA, b++)) {
retval = -EFAULT;
b--;
break;
Expand Down Expand Up @@ -1352,15 +1362,17 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
spin_unlock_irqrestore(&tty->read_lock, flags);

if (!eol || (c != __DISABLED_CHAR)) {
if (put_user(c, b++)) {
if (tty_put_user(tty, c, b++)) {
retval = -EFAULT;
b--;
break;
}
nr--;
}
if (eol)
if (eol) {
tty_audit_push(tty);
break;
}
}
if (retval)
break;
Expand Down
Loading

0 comments on commit 522ed77

Please sign in to comment.