blob: 5109173839cc5b820ff5c9712b681b4e4fae6277 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001// SPDX-License-Identifier: GPL-2.0-only
Mimi Zohar3323eec2009-02-04 09:06:58 -05002/*
3 * Copyright (C) 2008 IBM Corporation
4 * Author: Mimi Zohar <zohar@us.ibm.com>
5 *
Mimi Zohar3323eec2009-02-04 09:06:58 -05006 * File: integrity_audit.c
Dmitry Kasatkin2bb930a2014-03-04 18:04:20 +02007 * Audit calls for the integrity subsystem
Mimi Zohar3323eec2009-02-04 09:06:58 -05008 */
9
10#include <linux/fs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/gfp.h>
Mimi Zohar3323eec2009-02-04 09:06:58 -050012#include <linux/audit.h>
Mimi Zohard726d8d2013-03-18 14:48:02 -040013#include "integrity.h"
Mimi Zohar3323eec2009-02-04 09:06:58 -050014
Mimi Zohard726d8d2013-03-18 14:48:02 -040015static int integrity_audit_info;
Mimi Zohar3323eec2009-02-04 09:06:58 -050016
Mimi Zohar3323eec2009-02-04 09:06:58 -050017/* ima_audit_setup - enable informational auditing messages */
Mimi Zohard726d8d2013-03-18 14:48:02 -040018static int __init integrity_audit_setup(char *str)
Mimi Zohar3323eec2009-02-04 09:06:58 -050019{
20 unsigned long audit;
Mimi Zohar3323eec2009-02-04 09:06:58 -050021
Jingoo Han29707b22014-02-05 15:13:14 +090022 if (!kstrtoul(str, 0, &audit))
Mimi Zohard726d8d2013-03-18 14:48:02 -040023 integrity_audit_info = audit ? 1 : 0;
Mimi Zohar3323eec2009-02-04 09:06:58 -050024 return 1;
25}
Mimi Zohard726d8d2013-03-18 14:48:02 -040026__setup("integrity_audit=", integrity_audit_setup);
Mimi Zohar3323eec2009-02-04 09:06:58 -050027
28void integrity_audit_msg(int audit_msgno, struct inode *inode,
29 const unsigned char *fname, const char *op,
30 const char *cause, int result, int audit_info)
31{
32 struct audit_buffer *ab;
Tetsuo Handa73a6b44a2013-12-24 20:49:01 +090033 char name[TASK_COMM_LEN];
Mimi Zohar3323eec2009-02-04 09:06:58 -050034
Mimi Zohard726d8d2013-03-18 14:48:02 -040035 if (!integrity_audit_info && audit_info == 1) /* Skip info messages */
Mimi Zohar3323eec2009-02-04 09:06:58 -050036 return;
37
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -040038 ab = audit_log_start(audit_context(), GFP_KERNEL, audit_msgno);
Eric Paris34c111f2010-04-20 10:21:36 -040039 audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
Richard Guy Briggsf1dc4862013-12-11 13:52:26 -050040 task_pid_nr(current),
Eric W. Biederman8b94eea2012-05-25 18:24:12 -060041 from_kuid(&init_user_ns, current_cred()->uid),
42 from_kuid(&init_user_ns, audit_get_loginuid(current)),
Mimi Zohar523979a2009-02-11 11:12:28 -050043 audit_get_sessionid(current));
Mimi Zohar3323eec2009-02-04 09:06:58 -050044 audit_log_task_context(ab);
Stefan Berger3d2859d2018-06-04 16:54:53 -040045 audit_log_format(ab, " op=%s cause=%s comm=", op, cause);
Tetsuo Handa73a6b44a2013-12-24 20:49:01 +090046 audit_log_untrustedstring(ab, get_task_comm(name, current));
Mimi Zohar3323eec2009-02-04 09:06:58 -050047 if (fname) {
48 audit_log_format(ab, " name=");
49 audit_log_untrustedstring(ab, fname);
50 }
Kees Cook41fdc302012-01-07 10:41:04 -080051 if (inode) {
52 audit_log_format(ab, " dev=");
53 audit_log_untrustedstring(ab, inode->i_sb->s_id);
54 audit_log_format(ab, " ino=%lu", inode->i_ino);
55 }
Eric Parisb0d5de42012-02-14 17:11:07 -050056 audit_log_format(ab, " res=%d", !result);
Mimi Zohar3323eec2009-02-04 09:06:58 -050057 audit_log_end(ab);
58}