Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 IBM Corporation |
| 4 | * Author: Mimi Zohar <zohar@us.ibm.com> |
| 5 | * |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 6 | * File: integrity_audit.c |
Dmitry Kasatkin | 2bb930a | 2014-03-04 18:04:20 +0200 | [diff] [blame] | 7 | * Audit calls for the integrity subsystem |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/gfp.h> |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 12 | #include <linux/audit.h> |
Mimi Zohar | d726d8d | 2013-03-18 14:48:02 -0400 | [diff] [blame] | 13 | #include "integrity.h" |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 14 | |
Mimi Zohar | d726d8d | 2013-03-18 14:48:02 -0400 | [diff] [blame] | 15 | static int integrity_audit_info; |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 16 | |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 17 | /* ima_audit_setup - enable informational auditing messages */ |
Mimi Zohar | d726d8d | 2013-03-18 14:48:02 -0400 | [diff] [blame] | 18 | static int __init integrity_audit_setup(char *str) |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 19 | { |
| 20 | unsigned long audit; |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 21 | |
Jingoo Han | 29707b2 | 2014-02-05 15:13:14 +0900 | [diff] [blame] | 22 | if (!kstrtoul(str, 0, &audit)) |
Mimi Zohar | d726d8d | 2013-03-18 14:48:02 -0400 | [diff] [blame] | 23 | integrity_audit_info = audit ? 1 : 0; |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 24 | return 1; |
| 25 | } |
Mimi Zohar | d726d8d | 2013-03-18 14:48:02 -0400 | [diff] [blame] | 26 | __setup("integrity_audit=", integrity_audit_setup); |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 27 | |
| 28 | void 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 | { |
Lakshmi Ramasubramanian | 2f84588 | 2020-06-18 14:10:11 -0700 | [diff] [blame] | 32 | integrity_audit_message(audit_msgno, inode, fname, op, cause, |
| 33 | result, audit_info, 0); |
| 34 | } |
| 35 | |
| 36 | void integrity_audit_message(int audit_msgno, struct inode *inode, |
| 37 | const unsigned char *fname, const char *op, |
| 38 | const char *cause, int result, int audit_info, |
| 39 | int errno) |
| 40 | { |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 41 | struct audit_buffer *ab; |
Tetsuo Handa | 73a6b44a | 2013-12-24 20:49:01 +0900 | [diff] [blame] | 42 | char name[TASK_COMM_LEN]; |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 43 | |
Mimi Zohar | d726d8d | 2013-03-18 14:48:02 -0400 | [diff] [blame] | 44 | if (!integrity_audit_info && audit_info == 1) /* Skip info messages */ |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 45 | return; |
| 46 | |
Richard Guy Briggs | cdfb6b3 | 2018-05-12 21:58:20 -0400 | [diff] [blame] | 47 | ab = audit_log_start(audit_context(), GFP_KERNEL, audit_msgno); |
Eric Paris | 34c111f | 2010-04-20 10:21:36 -0400 | [diff] [blame] | 48 | audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u", |
Richard Guy Briggs | f1dc486 | 2013-12-11 13:52:26 -0500 | [diff] [blame] | 49 | task_pid_nr(current), |
Denis Efremov | e44f128 | 2020-08-24 15:54:35 +0300 | [diff] [blame] | 50 | from_kuid(&init_user_ns, current_uid()), |
Eric W. Biederman | 8b94eea | 2012-05-25 18:24:12 -0600 | [diff] [blame] | 51 | from_kuid(&init_user_ns, audit_get_loginuid(current)), |
Mimi Zohar | 523979a | 2009-02-11 11:12:28 -0500 | [diff] [blame] | 52 | audit_get_sessionid(current)); |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 53 | audit_log_task_context(ab); |
Stefan Berger | 3d2859d | 2018-06-04 16:54:53 -0400 | [diff] [blame] | 54 | audit_log_format(ab, " op=%s cause=%s comm=", op, cause); |
Tetsuo Handa | 73a6b44a | 2013-12-24 20:49:01 +0900 | [diff] [blame] | 55 | audit_log_untrustedstring(ab, get_task_comm(name, current)); |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 56 | if (fname) { |
| 57 | audit_log_format(ab, " name="); |
| 58 | audit_log_untrustedstring(ab, fname); |
| 59 | } |
Kees Cook | 41fdc30 | 2012-01-07 10:41:04 -0800 | [diff] [blame] | 60 | if (inode) { |
| 61 | audit_log_format(ab, " dev="); |
| 62 | audit_log_untrustedstring(ab, inode->i_sb->s_id); |
| 63 | audit_log_format(ab, " ino=%lu", inode->i_ino); |
| 64 | } |
Lakshmi Ramasubramanian | 2f84588 | 2020-06-18 14:10:11 -0700 | [diff] [blame] | 65 | audit_log_format(ab, " res=%d errno=%d", !result, errno); |
Mimi Zohar | 3323eec | 2009-02-04 09:06:58 -0500 | [diff] [blame] | 66 | audit_log_end(ab); |
| 67 | } |