xref: /linux/lib/audit.c (revision 42f355ef59a2f98fa4affb4265d3ba3e2d86baf1)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2e65e1fc2SAl Viro #include <linux/init.h>
3e65e1fc2SAl Viro #include <linux/types.h>
4e65e1fc2SAl Viro #include <linux/audit.h>
5e65e1fc2SAl Viro #include <asm/unistd.h>
6e65e1fc2SAl Viro 
7e65e1fc2SAl Viro static unsigned dir_class[] = {
8e65e1fc2SAl Viro #include <asm-generic/audit_dir_write.h>
9e65e1fc2SAl Viro ~0U
10e65e1fc2SAl Viro };
11e65e1fc2SAl Viro 
12e65e1fc2SAl Viro static unsigned read_class[] = {
13e65e1fc2SAl Viro #include <asm-generic/audit_read.h>
14e65e1fc2SAl Viro ~0U
15e65e1fc2SAl Viro };
16e65e1fc2SAl Viro 
17e65e1fc2SAl Viro static unsigned write_class[] = {
18e65e1fc2SAl Viro #include <asm-generic/audit_write.h>
19e65e1fc2SAl Viro ~0U
20e65e1fc2SAl Viro };
21e65e1fc2SAl Viro 
22e65e1fc2SAl Viro static unsigned chattr_class[] = {
23e65e1fc2SAl Viro #include <asm-generic/audit_change_attr.h>
24e65e1fc2SAl Viro ~0U
25e65e1fc2SAl Viro };
26e65e1fc2SAl Viro 
277f13da40SAmy Griffis static unsigned signal_class[] = {
287f13da40SAmy Griffis #include <asm-generic/audit_signal.h>
297f13da40SAmy Griffis ~0U
307f13da40SAmy Griffis };
317f13da40SAmy Griffis 
32e54dc243SAmy Griffis int audit_classify_arch(int arch)
33e54dc243SAmy Griffis {
344b588411SAKASHI Takahiro 	if (audit_is_compat(arch))
354b588411SAKASHI Takahiro 		return 1;
364b588411SAKASHI Takahiro 	else
37e54dc243SAmy Griffis 		return 0;
38e54dc243SAmy Griffis }
39e54dc243SAmy Griffis 
40e65e1fc2SAl Viro int audit_classify_syscall(int abi, unsigned syscall)
41e65e1fc2SAl Viro {
424b588411SAKASHI Takahiro 	if (audit_is_compat(abi))
434b588411SAKASHI Takahiro 		return audit_classify_compat_syscall(abi, syscall);
444b588411SAKASHI Takahiro 
45e65e1fc2SAl Viro 	switch(syscall) {
46aaeb012fSChris Metcalf #ifdef __NR_open
47e65e1fc2SAl Viro 	case __NR_open:
48*42f355efSRichard Guy Briggs 		return AUDITSC_OPEN;
49aaeb012fSChris Metcalf #endif
50a83fbf63SAl Viro #ifdef __NR_openat
51e65e1fc2SAl Viro 	case __NR_openat:
52*42f355efSRichard Guy Briggs 		return AUDITSC_OPENAT;
53a83fbf63SAl Viro #endif
54e65e1fc2SAl Viro #ifdef __NR_socketcall
55e65e1fc2SAl Viro 	case __NR_socketcall:
56*42f355efSRichard Guy Briggs 		return AUDITSC_SOCKETCALL;
57e65e1fc2SAl Viro #endif
5851f39a1fSDavid Drysdale #ifdef __NR_execveat
5951f39a1fSDavid Drysdale 	case __NR_execveat:
6051f39a1fSDavid Drysdale #endif
61e65e1fc2SAl Viro 	case __NR_execve:
62*42f355efSRichard Guy Briggs 		return AUDITSC_EXECVE;
63e65e1fc2SAl Viro 	default:
64*42f355efSRichard Guy Briggs 		return AUDITSC_NATIVE;
65e65e1fc2SAl Viro 	}
66e65e1fc2SAl Viro }
67e65e1fc2SAl Viro 
68e65e1fc2SAl Viro static int __init audit_classes_init(void)
69e65e1fc2SAl Viro {
704b588411SAKASHI Takahiro #ifdef CONFIG_AUDIT_COMPAT_GENERIC
714b588411SAKASHI Takahiro 	audit_register_class(AUDIT_CLASS_WRITE_32, compat_write_class);
724b588411SAKASHI Takahiro 	audit_register_class(AUDIT_CLASS_READ_32, compat_read_class);
734b588411SAKASHI Takahiro 	audit_register_class(AUDIT_CLASS_DIR_WRITE_32, compat_dir_class);
744b588411SAKASHI Takahiro 	audit_register_class(AUDIT_CLASS_CHATTR_32, compat_chattr_class);
754b588411SAKASHI Takahiro 	audit_register_class(AUDIT_CLASS_SIGNAL_32, compat_signal_class);
764b588411SAKASHI Takahiro #endif
77e65e1fc2SAl Viro 	audit_register_class(AUDIT_CLASS_WRITE, write_class);
78e65e1fc2SAl Viro 	audit_register_class(AUDIT_CLASS_READ, read_class);
79e65e1fc2SAl Viro 	audit_register_class(AUDIT_CLASS_DIR_WRITE, dir_class);
80e65e1fc2SAl Viro 	audit_register_class(AUDIT_CLASS_CHATTR, chattr_class);
817f13da40SAmy Griffis 	audit_register_class(AUDIT_CLASS_SIGNAL, signal_class);
82e65e1fc2SAl Viro 	return 0;
83e65e1fc2SAl Viro }
84e65e1fc2SAl Viro 
85e65e1fc2SAl Viro __initcall(audit_classes_init);
86