2009-02-04 09:06:58 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 IBM Corporation
|
|
|
|
|
* Author: Mimi Zohar <zohar@us.ibm.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, version 2 of the License.
|
|
|
|
|
*
|
|
|
|
|
* File: integrity_audit.c
|
2014-03-04 18:04:20 +02:00
|
|
|
* Audit calls for the integrity subsystem
|
2009-02-04 09:06:58 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
2010-03-24 17:04:11 +09:00
|
|
|
#include <linux/gfp.h>
|
2009-02-04 09:06:58 -05:00
|
|
|
#include <linux/audit.h>
|
2013-03-18 14:48:02 -04:00
|
|
|
#include "integrity.h"
|
2009-02-04 09:06:58 -05:00
|
|
|
|
2013-03-18 14:48:02 -04:00
|
|
|
static int integrity_audit_info;
|
2009-02-04 09:06:58 -05:00
|
|
|
|
|
|
|
|
/* ima_audit_setup - enable informational auditing messages */
|
2013-03-18 14:48:02 -04:00
|
|
|
static int __init integrity_audit_setup(char *str)
|
2009-02-04 09:06:58 -05:00
|
|
|
{
|
|
|
|
|
unsigned long audit;
|
|
|
|
|
|
2014-02-05 15:13:14 +09:00
|
|
|
if (!kstrtoul(str, 0, &audit))
|
2013-03-18 14:48:02 -04:00
|
|
|
integrity_audit_info = audit ? 1 : 0;
|
2009-02-04 09:06:58 -05:00
|
|
|
return 1;
|
|
|
|
|
}
|
2013-03-18 14:48:02 -04:00
|
|
|
__setup("integrity_audit=", integrity_audit_setup);
|
2009-02-04 09:06:58 -05:00
|
|
|
|
|
|
|
|
void integrity_audit_msg(int audit_msgno, struct inode *inode,
|
|
|
|
|
const unsigned char *fname, const char *op,
|
|
|
|
|
const char *cause, int result, int audit_info)
|
|
|
|
|
{
|
|
|
|
|
struct audit_buffer *ab;
|
2013-12-24 20:49:01 +09:00
|
|
|
char name[TASK_COMM_LEN];
|
2009-02-04 09:06:58 -05:00
|
|
|
|
2013-03-18 14:48:02 -04:00
|
|
|
if (!integrity_audit_info && audit_info == 1) /* Skip info messages */
|
2009-02-04 09:06:58 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno);
|
2010-04-20 10:21:36 -04:00
|
|
|
audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
|
2013-12-11 13:52:26 -05:00
|
|
|
task_pid_nr(current),
|
2012-05-25 18:24:12 -06:00
|
|
|
from_kuid(&init_user_ns, current_cred()->uid),
|
|
|
|
|
from_kuid(&init_user_ns, audit_get_loginuid(current)),
|
2009-02-11 11:12:28 -05:00
|
|
|
audit_get_sessionid(current));
|
2009-02-04 09:06:58 -05:00
|
|
|
audit_log_task_context(ab);
|
2009-05-05 13:13:00 -04:00
|
|
|
audit_log_format(ab, " op=");
|
|
|
|
|
audit_log_string(ab, op);
|
|
|
|
|
audit_log_format(ab, " cause=");
|
|
|
|
|
audit_log_string(ab, cause);
|
2009-02-04 09:06:58 -05:00
|
|
|
audit_log_format(ab, " comm=");
|
2013-12-24 20:49:01 +09:00
|
|
|
audit_log_untrustedstring(ab, get_task_comm(name, current));
|
2009-02-04 09:06:58 -05:00
|
|
|
if (fname) {
|
|
|
|
|
audit_log_format(ab, " name=");
|
|
|
|
|
audit_log_untrustedstring(ab, fname);
|
|
|
|
|
}
|
2012-01-07 10:41:04 -08:00
|
|
|
if (inode) {
|
|
|
|
|
audit_log_format(ab, " dev=");
|
|
|
|
|
audit_log_untrustedstring(ab, inode->i_sb->s_id);
|
|
|
|
|
audit_log_format(ab, " ino=%lu", inode->i_ino);
|
|
|
|
|
}
|
2012-02-14 17:11:07 -05:00
|
|
|
audit_log_format(ab, " res=%d", !result);
|
2009-02-04 09:06:58 -05:00
|
|
|
audit_log_end(ab);
|
|
|
|
|
}
|