public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
From: Miloslav Trmac <mitr@redhat.com>
To: viro <viro@zeniv.linux.org.uk>, Eric Paris <eparis@redhat.com>
Cc: linux-audit <linux-audit@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] Add SELinux context and TTY name to AUDIT_TTY records
Date: Thu, 19 Mar 2009 13:18:00 -0400 (EDT)	[thread overview]
Message-ID: <273781508.1737621237483080376.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com> (raw)
In-Reply-To: <230738142.1737601237483061914.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

From: Miloslav Trmač <mitr@redhat.com>

Add SELinux context information and TTY name (consistent with the
AUDIT_SYSCALL record) to AUDIT_TTY.  An example record after applying
this patch:

 type=TTY msg=audit(1237480806.220:22): tty pid=2601 uid=0 auid=500 ses=1 
 subj=unconfined_u:unconfined_r:unconfined_t:s0 major=136 minor=1 tty=pts1 
 comm="bash" data=6361740D

(line wrapped, new fields are "subj" and "tty".)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
---
 drivers/char/tty_audit.c |   57 ++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 19 deletions(-)

[-- Attachment #2: audit-tty-more-fields.patch --]
[-- Type: application/octet-stream, Size: 4652 bytes --]

From: Miloslav Trmač <mitr@redhat.com>

Add SELinux context information and TTY name (consistent with the
AUDIT_SYSCALL record) to AUDIT_TTY.  An example record after applying
this patch:

 type=TTY msg=audit(1237480806.220:22): tty pid=2601 uid=0 auid=500 ses=1
 subj=unconfined_u:unconfined_r:unconfined_t:s0 major=136 minor=1 tty=pts1
 comm="bash" data=6361740D

(line wrapped, new fields are "subj" and "tty".)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
---
 drivers/char/tty_audit.c |   57 ++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index 34ab6d7..1b7add4 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -12,6 +12,7 @@
 #include <linux/audit.h>
 #include <linux/file.h>
 #include <linux/fdtable.h>
+#include <linux/security.h>
 #include <linux/tty.h>
 
 struct tty_audit_buf {
@@ -19,12 +20,21 @@ struct tty_audit_buf {
 	struct mutex mutex;	/* Protects all data below */
 	int major, minor;	/* The TTY which the data is from */
 	unsigned icanon:1;
+	char tty_name[sizeof(((struct tty_struct *)NULL)->name)];
 	size_t valid;
 	unsigned char *data;	/* Allocated size N_TTY_BUF_SIZE */
 };
 
-static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
-						 int icanon)
+static void tty_audit_buf_setup(struct tty_audit_buf *buf,
+				struct tty_struct *tty)
+{
+	buf->major = tty->driver->major;
+	buf->minor = tty->driver->minor_start + tty->index;
+	buf->icanon = tty->icanon;
+	strcpy(buf->tty_name, tty->name);
+}
+
+static struct tty_audit_buf *tty_audit_buf_alloc(struct tty_struct *tty)
 {
 	struct tty_audit_buf *buf;
 
@@ -39,9 +49,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
 		goto err_buf;
 	atomic_set(&buf->count, 1);
 	mutex_init(&buf->mutex);
-	buf->major = major;
-	buf->minor = minor;
-	buf->icanon = icanon;
+	tty_audit_buf_setup(buf, tty);
 	buf->valid = 0;
 	return buf;
 
@@ -69,7 +77,8 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf)
 
 static void tty_audit_log(const char *description, struct task_struct *tsk,
 			  uid_t loginuid, unsigned sessionid, int major,
-			  int minor, unsigned char *data, size_t size)
+			  int minor, const char *tty_name,
+			  unsigned char *data, size_t size)
 {
 	struct audit_buffer *ab;
 
@@ -77,11 +86,25 @@ static void tty_audit_log(const char *description, struct task_struct *tsk,
 	if (ab) {
 		char name[sizeof(tsk->comm)];
 		uid_t uid = task_uid(tsk);
-
-		audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u "
-				 "major=%d minor=%d comm=", description,
-				 tsk->pid, uid, loginuid, sessionid,
-				 major, minor);
+		u32 sid;
+
+		audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u",
+				 description, tsk->pid, uid, loginuid,
+				 sessionid);
+		security_task_getsecid(tsk, &sid);
+		if (sid) {
+			char *ctx;
+			u32 len;
+
+			if (security_secid_to_secctx(sid, &ctx, &len))
+				audit_log_format(ab, " ssid=%u", sid);
+			else {
+				audit_log_format(ab, " subj=%s", ctx);
+				security_release_secctx(ctx, len);
+			}
+		}
+		audit_log_format(ab, " major=%d minor=%d tty=%s comm=", major,
+				 minor, tty_name);
 		get_task_comm(name, tsk);
 		audit_log_untrustedstring(ab, name);
 		audit_log_format(ab, " data=");
@@ -105,7 +128,7 @@ static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
 	if (audit_enabled == 0)
 		return;
 	tty_audit_log("tty", tsk, loginuid, sessionid, buf->major, buf->minor,
-		      buf->data, buf->valid);
+		      buf->tty_name, buf->data, buf->valid);
 	buf->valid = 0;
 }
 
@@ -191,7 +214,7 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
 		auid = audit_get_loginuid(current);
 		sessionid = audit_get_sessionid(current);
 		tty_audit_log("ioctl=TIOCSTI", current, auid, sessionid, major,
-			      minor, &ch, 1);
+			      minor, tty->name, &ch, 1);
 	}
 }
 
@@ -240,9 +263,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty)
 	}
 	spin_unlock_irq(&current->sighand->siglock);
 
-	buf2 = tty_audit_buf_alloc(tty->driver->major,
-				   tty->driver->minor_start + tty->index,
-				   tty->icanon);
+	buf2 = tty_audit_buf_alloc(tty);
 	if (buf2 == NULL) {
 		audit_log_lost("out of memory in TTY auditing");
 		return NULL;
@@ -294,9 +315,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
 	if (buf->major != major || buf->minor != minor
 	    || buf->icanon != tty->icanon) {
 		tty_audit_buf_push_current(buf);
-		buf->major = major;
-		buf->minor = minor;
-		buf->icanon = tty->icanon;
+		tty_audit_buf_setup(buf, tty);
 	}
 	do {
 		size_t run;

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



       reply	other threads:[~2009-03-19 17:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <230738142.1737601237483061914.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com>
2009-03-19 17:18 ` Miloslav Trmac [this message]
2009-03-19 20:58   ` [PATCH] Add SELinux context and TTY name to AUDIT_TTY records Paul Moore
     [not found] <1446383553.1772511237538977759.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com>
2009-03-20  8:53 ` Miloslav Trmac
2009-03-20 13:51   ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=273781508.1737621237483080376.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com \
    --to=mitr@redhat.com \
    --cc=eparis@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox