blob: 90987d15b6fe6c01ca593e185d2ae7a780186c31 [file] [log] [blame]
Mimi Zohar3323eec92009-02-04 09:06:58 -05001/*
2 * Copyright (C) 2008 IBM Corporation
3 * Author: Mimi Zohar <zohar@us.ibm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
8 *
9 * File: integrity_audit.c
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +020010 * Audit calls for the integrity subsystem
Mimi Zohar3323eec92009-02-04 09:06:58 -050011 */
12
13#include <linux/fs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/gfp.h>
Mimi Zohar3323eec92009-02-04 09:06:58 -050015#include <linux/audit.h>
Mimi Zohard726d8d2013-03-18 14:48:02 -040016#include "integrity.h"
Mimi Zohar3323eec92009-02-04 09:06:58 -050017
Mimi Zohard726d8d2013-03-18 14:48:02 -040018static int integrity_audit_info;
Mimi Zohar3323eec92009-02-04 09:06:58 -050019
Mimi Zohar3323eec92009-02-04 09:06:58 -050020/* ima_audit_setup - enable informational auditing messages */
Mimi Zohard726d8d2013-03-18 14:48:02 -040021static int __init integrity_audit_setup(char *str)
Mimi Zohar3323eec92009-02-04 09:06:58 -050022{
23 unsigned long audit;
Mimi Zohar3323eec92009-02-04 09:06:58 -050024
Jingoo Han29707b22014-02-05 15:13:14 +090025 if (!kstrtoul(str, 0, &audit))
Mimi Zohard726d8d2013-03-18 14:48:02 -040026 integrity_audit_info = audit ? 1 : 0;
Mimi Zohar3323eec92009-02-04 09:06:58 -050027 return 1;
28}
Mimi Zohard726d8d2013-03-18 14:48:02 -040029__setup("integrity_audit=", integrity_audit_setup);
Mimi Zohar3323eec92009-02-04 09:06:58 -050030
31void integrity_audit_msg(int audit_msgno, struct inode *inode,
32 const unsigned char *fname, const char *op,
33 const char *cause, int result, int audit_info)
34{
35 struct audit_buffer *ab;
Tetsuo Handa73a6b44a2013-12-24 20:49:01 +090036 char name[TASK_COMM_LEN];
Mimi Zohar3323eec92009-02-04 09:06:58 -050037
Mimi Zohard726d8d2013-03-18 14:48:02 -040038 if (!integrity_audit_info && audit_info == 1) /* Skip info messages */
Mimi Zohar3323eec92009-02-04 09:06:58 -050039 return;
40
41 ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno);
Eric Paris34c111f2010-04-20 10:21:36 -040042 audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
Richard Guy Briggsf1dc4862013-12-11 13:52:26 -050043 task_pid_nr(current),
Eric W. Biederman8b94eea2012-05-25 18:24:12 -060044 from_kuid(&init_user_ns, current_cred()->uid),
45 from_kuid(&init_user_ns, audit_get_loginuid(current)),
Mimi Zohar523979a2009-02-11 11:12:28 -050046 audit_get_sessionid(current));
Mimi Zohar3323eec92009-02-04 09:06:58 -050047 audit_log_task_context(ab);
Mimi Zohare5e520a2009-05-05 13:13:00 -040048 audit_log_format(ab, " op=");
49 audit_log_string(ab, op);
50 audit_log_format(ab, " cause=");
51 audit_log_string(ab, cause);
Mimi Zohar3323eec92009-02-04 09:06:58 -050052 audit_log_format(ab, " comm=");
Tetsuo Handa73a6b44a2013-12-24 20:49:01 +090053 audit_log_untrustedstring(ab, get_task_comm(name, current));
Mimi Zohar3323eec92009-02-04 09:06:58 -050054 if (fname) {
55 audit_log_format(ab, " name=");
56 audit_log_untrustedstring(ab, fname);
57 }
Kees Cook41fdc302012-01-07 10:41:04 -080058 if (inode) {
59 audit_log_format(ab, " dev=");
60 audit_log_untrustedstring(ab, inode->i_sb->s_id);
61 audit_log_format(ab, " ino=%lu", inode->i_ino);
62 }
Eric Parisb0d5de42012-02-14 17:11:07 -050063 audit_log_format(ab, " res=%d", !result);
Mimi Zohar3323eec92009-02-04 09:06:58 -050064 audit_log_end(ab);
65}