diff --git a/1002-anolis-audit-3.0-add-loongarch-support.patch b/1002-anolis-audit-3.0-add-loongarch-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..3a39e357a9661ca8aa069ff7690837d1e9eac2fc --- /dev/null +++ b/1002-anolis-audit-3.0-add-loongarch-support.patch @@ -0,0 +1,495 @@ +diff -ruN audit-3.0/lib/libaudit.c audit-3.0-loongarch/lib/libaudit.c +--- audit-3.0/lib/libaudit.c 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/lib/libaudit.c 2021-06-18 19:07:40.633423270 +0800 +@@ -1382,6 +1382,7 @@ + case MACH_86_64: /* fallthrough */ + case MACH_PPC64: /* fallthrough */ + case MACH_S390X: /* fallthrough */ ++ case MACH_LOONGARCH64: /* fallthrough */ + break; + case MACH_PPC64LE: /* 64 bit only */ + if (bits && bits != __AUDIT_ARCH_64BIT) +@@ -1838,10 +1838,10 @@ + int audit_detect_machine(void) + { + struct utsname uts; +- if (uname(&uts) == 0) +-// strcpy(uts.machine, "x86_64"); +- return audit_name_to_machine(uts.machine); +- return -1; ++ if (uname(&uts) == -1) ++ return -1; ++ ++ return audit_name_to_machine(uts.machine); + } + + #ifndef NO_TABLES +diff -ruN audit-3.0/lib/libaudit.h audit-3.0-loongarch/lib/libaudit.h +--- audit-3.0/lib/libaudit.h 2021-06-18 19:11:11.425423270 +0800 ++++ audit-3.0-loongarch/lib/libaudit.h 2021-06-18 19:11:05.309423270 +0800 +@@ -455,6 +455,14 @@ + #define EM_AARCH64 183 + #endif + ++#ifndef AUDIT_ARCH_LOONGARCH64 ++#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) ++#endif ++ ++#ifndef EM_LOONGARCH64 ++#define EM_LOONGARCH64 258 ++#endif ++ + #ifndef AUDIT_ARCH_AARCH64 + #define AUDIT_ARCH_AARCH64 (EM_AARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) + #endif +@@ -554,7 +562,8 @@ + MACH_ALPHA, // Deprecated but has to stay + MACH_ARM, + MACH_AARCH64, +- MACH_PPC64LE ++ MACH_PPC64LE, ++ MACH_LOONGARCH64 + } machine_t; + + /* These are the valid audit failure tunable enum values */ +diff -ruN audit-3.0/lib/lookup_table.c audit-3.0-loongarch/lib/lookup_table.c +--- audit-3.0/lib/lookup_table.c 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/lib/lookup_table.c 2021-06-18 19:07:40.633423270 +0800 +@@ -46,6 +46,7 @@ + #include "s390_tables.h" + #include "s390x_tables.h" + #include "x86_64_tables.h" ++#include "loongarch64_tables.h" + #include "errtabs.h" + #include "fstypetabs.h" + #include "ftypetabs.h" +@@ -70,6 +71,7 @@ + { MACH_PPC, AUDIT_ARCH_PPC }, + { MACH_S390X, AUDIT_ARCH_S390X }, + { MACH_S390, AUDIT_ARCH_S390 }, ++ { MACH_LOONGARCH64, AUDIT_ARCH_LOONGARCH64 }, + #ifdef WITH_ARM + { MACH_ARM, AUDIT_ARCH_ARM }, + #endif +@@ -123,6 +125,9 @@ + case MACH_S390: + found = s390_syscall_s2i(sc, &res); + break; ++ case MACH_LOONGARCH64: ++ found = loongarch64_syscall_s2i(sc, &res); ++ break; + #ifdef WITH_ARM + case MACH_ARM: + found = arm_syscall_s2i(sc, &res); +@@ -159,6 +164,8 @@ + return s390x_syscall_i2s(sc); + case MACH_S390: + return s390_syscall_i2s(sc); ++ case MACH_LOONGARCH64: ++ return loongarch64_syscall_i2s(sc); + #ifdef WITH_ARM + case MACH_ARM: + return arm_syscall_i2s(sc); +diff -ruN audit-3.0/lib/loongarch64_table.h audit-3.0-loongarch/lib/loongarch64_table.h +--- audit-3.0/lib/loongarch64_table.h 1970-01-01 08:00:00.000000000 +0800 ++++ audit-3.0-loongarch/lib/loongarch64_table.h 2021-06-18 19:07:40.633423270 +0800 +@@ -0,0 +1,282 @@ ++/* loongarch64_table.h */ ++ ++_S(0, "io_setup") ++_S(1, "io_destroy") ++_S(2, "io_submit") ++_S(3, "io_cancel") ++_S(4, "io_getevents") ++_S(5, "setxattr") ++_S(6, "lsetxattr") ++_S(7, "fsetxattr") ++_S(8, "getxattr") ++_S(9, "lgetxattr") ++_S(10, "fgetxattr") ++_S(11, "listxattr") ++_S(12, "llistxattr") ++_S(13, "flistxattr") ++_S(14, "removexattr") ++_S(15, "lremovexattr") ++_S(16, "fremovexattr") ++_S(17, "getcwd") ++_S(18, "lookup_dcookie") ++_S(19, "eventfd2") ++_S(20, "epoll_create1") ++_S(21, "epoll_ctl") ++_S(22, "epoll_pwait") ++_S(23, "dup") ++_S(24, "dup3") ++_S(25, "fcntl") ++_S(26, "inotify_init1") ++_S(27, "inotify_add_watch") ++_S(28, "inotify_rm_watch") ++_S(29, "ioctl") ++_S(30, "ioprio_set") ++_S(31, "ioprio_get") ++_S(32, "flock") ++_S(33, "mknodat") ++_S(34, "mkdirat") ++_S(35, "unlinkat") ++_S(36, "symlinkat") ++_S(37, "linkat") ++_S(38, "renameat") ++_S(39, "umount2") ++_S(40, "mount") ++_S(41, "pivot_root") ++_S(42, "nfsservctl") ++_S(43, "statfs") ++_S(44, "fstatfs") ++_S(45, "truncate") ++_S(46, "ftruncate") ++_S(47, "fallocate") ++_S(48, "faccessat") ++_S(49, "chdir") ++_S(50, "fchdir") ++_S(51, "chroot") ++_S(52, "fchmod") ++_S(53, "fchmodat") ++_S(54, "fchownat") ++_S(55, "fchown") ++_S(56, "openat") ++_S(57, "close") ++_S(58, "vhangup") ++_S(59, "pipe2") ++_S(60, "quotactl") ++_S(61, "getdents64") ++_S(62, "lseek") ++_S(63, "read") ++_S(64, "write") ++_S(65, "readv") ++_S(66, "writev") ++_S(67, "pread64") ++_S(68, "pwrite64") ++_S(69, "preadv") ++_S(70, "pwritev") ++_S(71, "sendfile") ++_S(72, "pselect6") ++_S(73, "ppoll") ++_S(74, "signalfd4") ++_S(75, "vmsplice") ++_S(76, "splice") ++_S(77, "tee") ++_S(78, "readlinkat") ++_S(79, "newfstatat") ++_S(80, "newfstat") ++_S(81, "sync") ++_S(82, "fsync") ++_S(83, "fdatasync") ++_S(84, "sync_file_range") ++_S(85, "timerfd_create") ++_S(86, "timerfd_settime") ++_S(87, "timerfd_gettime") ++_S(88, "utimensat") ++_S(89, "acct") ++_S(90, "capget") ++_S(91, "capset") ++_S(92, "personality") ++_S(93, "exit") ++_S(94, "exit_group") ++_S(95, "waitid") ++_S(96, "set_tid_address") ++_S(97, "unshare") ++_S(98, "futex") ++_S(99, "set_robust_list") ++_S(100, "get_robust_list") ++_S(101, "nanosleep") ++_S(102, "getitimer") ++_S(103, "setitimer") ++_S(104, "kexec_load") ++_S(105, "init_module") ++_S(106, "delete_module") ++_S(107, "timer_create") ++_S(108, "timer_gettime") ++_S(109, "timer_getoverrun") ++_S(110, "timer_settime") ++_S(111, "timer_delete") ++_S(112, "clock_settime") ++_S(113, "clock_gettime") ++_S(114, "clock_getres") ++_S(115, "clock_nanosleep") ++_S(116, "syslog") ++_S(117, "ptrace") ++_S(118, "sched_setparam") ++_S(119, "sched_setscheduler") ++_S(120, "sched_getscheduler") ++_S(121, "sched_getparam") ++_S(122, "sched_setaffinity") ++_S(123, "sched_getaffinity") ++_S(124, "sched_yield") ++_S(125, "sched_get_priority_max") ++_S(126, "sched_get_priority_min") ++_S(127, "sched_rr_get_interval") ++_S(128, "restart_syscall") ++_S(129, "kill") ++_S(130, "tkill") ++_S(131, "tgkill") ++_S(132, "sigaltstack") ++_S(133, "rt_sigsuspend") ++_S(134, "rt_sigaction") ++_S(135, "rt_sigprocmask") ++_S(136, "rt_sigpending") ++_S(137, "rt_sigtimedwait") ++_S(138, "rt_sigqueueinfo") ++_S(139, "rt_sigreturn") ++_S(140, "setpriority") ++_S(141, "getpriority") ++_S(142, "reboot") ++_S(143, "setregid") ++_S(144, "setgid") ++_S(145, "setreuid") ++_S(146, "setuid") ++_S(147, "setresuid") ++_S(148, "getresuid") ++_S(149, "setresgid") ++_S(150, "getresgid") ++_S(151, "setfsuid") ++_S(152, "setfsgid") ++_S(153, "times") ++_S(154, "setpgid") ++_S(155, "getpgid") ++_S(156, "getsid") ++_S(157, "setsid") ++_S(158, "getgroups") ++_S(159, "setgroups") ++_S(160, "uname") ++_S(161, "sethostname") ++_S(162, "setdomainname") ++_S(163, "getrlimit") ++_S(164, "setrlimit") ++_S(165, "getrusage") ++_S(166, "umask") ++_S(167, "prctl") ++_S(168, "getcpu") ++_S(169, "gettimeofday") ++_S(170, "settimeofday") ++_S(171, "adjtimex") ++_S(172, "getpid") ++_S(173, "getppid") ++_S(174, "getuid") ++_S(175, "geteuid") ++_S(176, "getgid") ++_S(177, "getegid") ++_S(178, "gettid") ++_S(179, "sysinfo") ++_S(180, "mq_open") ++_S(181, "mq_unlink") ++_S(182, "mq_timedsend") ++_S(183, "mq_timedreceive") ++_S(184, "mq_notify") ++_S(185, "mq_getsetattr") ++_S(186, "msgget") ++_S(187, "msgctl") ++_S(188, "msgrcv") ++_S(189, "msgsnd") ++_S(190, "semget") ++_S(191, "semctl") ++_S(192, "semtimedop") ++_S(193, "semop") ++_S(194, "shmget") ++_S(195, "shmctl") ++_S(196, "shmat") ++_S(197, "shmdt") ++_S(198, "socket") ++_S(199, "socketpair") ++_S(200, "bind") ++_S(201, "listen") ++_S(202, "accept") ++_S(203, "connect") ++_S(204, "getsockname") ++_S(205, "getpeername") ++_S(206, "sendto") ++_S(207, "recvfrom") ++_S(208, "setsockopt") ++_S(209, "getsockopt") ++_S(210, "shutdown") ++_S(211, "sendmsg") ++_S(212, "recvmsg") ++_S(213, "readahead") ++_S(214, "brk") ++_S(215, "munmap") ++_S(216, "mremap") ++_S(217, "add_key") ++_S(218, "request_key") ++_S(219, "keyctl") ++_S(220, "clone") ++_S(221, "execve") ++_S(222, "mmap") ++_S(223, "fadvise64") ++_S(224, "swapon") ++_S(225, "swapoff") ++_S(226, "mprotect") ++_S(227, "msync") ++_S(228, "mlock") ++_S(229, "munlock") ++_S(230, "mlockall") ++_S(231, "munlockall") ++_S(232, "mincore") ++_S(233, "madvise") ++_S(234, "remap_file_pages") ++_S(235, "mbind") ++_S(236, "get_mempolicy") ++_S(237, "set_mempolicy") ++_S(238, "migrate_pages") ++_S(239, "move_pages") ++_S(240, "rt_tgsigqueueinfo") ++_S(241, "perf_event_open") ++_S(242, "accept4") ++_S(243, "recvmmsg") ++_S(244, "arch_specific_syscall") ++_S(260, "wait4") ++_S(261, "prlimit64") ++_S(262, "fanotify_init") ++_S(263, "fanotify_mark") ++_S(264, "name_to_handle_at") ++_S(265, "open_by_handle_at") ++_S(266, "clock_adjtime") ++_S(267, "syncfs") ++_S(268, "setns") ++_S(269, "sendmmsg") ++_S(270, "process_vm_readv") ++_S(271, "process_vm_writev") ++_S(272, "kcmp") ++_S(273, "finit_module") ++_S(274, "sched_setattr") ++_S(275, "sched_getattr") ++_S(276, "renameat2") ++_S(277, "seccomp") ++_S(278, "getrandom") ++_S(279, "memfd_create") ++_S(280, "bpf") ++_S(281, "execveat") ++_S(282, "userfaultfd") ++_S(283, "membarrier") ++_S(284, "mlock2") ++_S(285, "copy_file_range") ++_S(286, "preadv2") ++_S(287, "pwritev2") ++_S(288, "pkey_mprotect") ++_S(289, "pkey_alloc") ++_S(290, "pkey_free") ++_S(291, "statx") ++_S(292, "io_pgetevents") ++_S(293, "rseq") ++_S(294, "syscalls") +diff -ruN audit-3.0/lib/machinetab.h audit-3.0-loongarch/lib/machinetab.h +--- audit-3.0/lib/machinetab.h 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/lib/machinetab.h 2021-06-18 19:07:40.633423270 +0800 +@@ -41,3 +41,4 @@ + #ifdef WITH_AARCH64 + _S(MACH_AARCH64, "aarch64" ) + #endif ++_S(MACH_LOONGARCH64, "loongarch64" ) +diff -ruN audit-3.0/lib/Makefile.am audit-3.0-loongarch/lib/Makefile.am +--- audit-3.0/lib/Makefile.am 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/lib/Makefile.am 2021-06-18 19:07:40.633423270 +0800 +@@ -46,7 +46,8 @@ + BUILT_SOURCES = actiontabs.h errtabs.h fieldtabs.h flagtabs.h \ + fstypetabs.h ftypetabs.h i386_tables.h machinetabs.h \ + msg_typetabs.h optabs.h ppc_tables.h s390_tables.h \ +- s390x_tables.h x86_64_tables.h ++ s390x_tables.h x86_64_tables.h \ ++ loongarch64_tables.h + if USE_ARM + BUILT_SOURCES += arm_tables.h + endif +@@ -57,7 +58,8 @@ + gen_flagtabs_h gen_fstypetabs_h gen_ftypetabs_h gen_i386_tables_h \ + gen_machinetabs_h gen_msg_typetabs_h \ + gen_optabs_h gen_ppc_tables_h gen_s390_tables_h \ +- gen_s390x_tables_h gen_x86_64_tables_h ++ gen_s390x_tables_h gen_x86_64_tables_h \ ++ gen_loongarch64_tables_h + if USE_ARM + noinst_PROGRAMS += gen_arm_tables_h + endif +@@ -107,6 +109,19 @@ + ./gen_aarch64_tables_h --lowercase --i2s --s2i aarch64_syscall > $@ + endif + ++gen_loongarch64_tables_h_SOURCES = gen_tables.c gen_tables.h loongarch64_table.h ++gen_loongarch64_tables_h_CFLAGS = '-DTABLE_H="loongarch64_table.h"' ++$(gen_loongarch64_tables_h_OBJECTS): CC=$(CC_FOR_BUILD) ++$(gen_loongarch64_tables_h_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD) ++$(gen_loongarch64_tables_h_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD) ++$(gen_loongarch64_tables_h_OBJECTS): LDFLAGS=$(LDFLAGS_FOR_BUILD) ++gen_loongarch64_tables_h$(BUILD_EXEEXT): CC=$(CC_FOR_BUILD) ++gen_loongarch64_tables_h$(BUILD_EXEEXT): CFLAGS=$(CFLAGS_FOR_BUILD) ++gen_loongarch64_tables_h$(BUILD_EXEEXT): CPPFLAGS=$(CPPFLAGS_FOR_BUILD) ++gen_loongarch64_tables_h$(BUILD_EXEEXT): LDFLAGS=$(LDFLAGS_FOR_BUILD) ++loongarch64_tables.h: gen_loongarch64_tables_h Makefile ++ ./gen_loongarch64_tables_h --lowercase --i2s --s2i loongarch64_syscall > $@ ++ + gen_errtabs_h_SOURCES = gen_tables.c gen_tables.h errtab.h + gen_errtabs_h_CFLAGS = '-DTABLE_H="errtab.h"' + $(gen_errtabs_h_OBJECTS): CC=$(CC_FOR_BUILD) +diff -ruN audit-3.0/lib/syscall-update.txt audit-3.0-loongarch/lib/syscall-update.txt +--- audit-3.0/lib/syscall-update.txt 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/lib/syscall-update.txt 2021-06-18 19:07:40.633423270 +0800 +@@ -3,6 +3,7 @@ + arch/arm/tools/syscall.tbl + arch/arm/include/uapi/asm/unistd.h + arch/powerpc/include/uapi/asm/unistd.h ++usr/include/asm-generic/unistd.h (loongarch64) + arch/s390/kernel/syscalls/syscall.tbl + arch/x86/entry/syscalls/syscall_32.tbl + arch/x86/entry/syscalls/syscall_64.tbl +diff -ruN audit-3.0/lib/test/lookup_test.c audit-3.0-loongarch/lib/test/lookup_test.c +--- audit-3.0/lib/test/lookup_test.c 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/lib/test/lookup_test.c 2021-06-18 19:07:57.197423270 +0800 +@@ -219,6 +219,23 @@ + } + + static void ++test_loongarch64_table(void) ++{ ++ static const struct entry t[] = { ++#include "../loongarch64_table.h" ++ }; ++ ++ printf("Testing loongarch64_table...\n"); ++#define I2S(I) audit_syscall_to_name((I), MACH_LOONGARCH64) ++#define S2I(S) audit_name_to_syscall((S), MACH_LOONGARCH64) ++ TEST_I2S(0); ++ TEST_S2I(-1); ++#undef I2S ++#undef S2I ++} ++ ++ ++static void + test_x86_64_table(void) + { + static const struct entry t[] = { +@@ -391,6 +408,7 @@ + test_aarch64_table(); + #endif + test_i386_table(); ++ test_loongarch64_table(); + test_ppc_table(); + test_s390_table(); + test_s390x_table(); +diff -ruN audit-3.0/src/libev/ev.c audit-3.0-loongarch/src/libev/ev.c +--- audit-3.0/src/libev/ev.c 2019-11-05 03:55:44.000000000 +0800 ++++ audit-3.0-loongarch/src/libev/ev.c 2021-06-18 19:07:50.333423270 +0800 +@@ -696,6 +696,8 @@ + /* GNU/Linux emulates sync on mips1 architectures, so we force its use */ + /* anybody else who still uses mips1 is supposed to send in their version, with detection code. */ + #define ECB_MEMORY_FENCE __asm__ __volatile__ (".set mips2; sync; .set mips0" : : : "memory") ++ #elif defined __loongarch__ ++ #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dbar 0" : : : "memory") + #elif defined __alpha__ + #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") + #elif defined __hppa__ +@@ -1309,6 +1311,7 @@ + || defined __alpha__ \ + || defined __hppa__ \ + || defined __ia64__ \ ++ || defined __loongarch__ \ + || defined __m68k__ \ + || defined __m88k__ \ + || defined __sh__ \ diff --git a/audit.spec b/audit.spec index 057f841122381b6ac2520519d0779ea1ba23b0ff..6c3c4d5ff9da25852c78721a71c68ee92385da2c 100644 --- a/audit.spec +++ b/audit.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.1 +%define anolis_release .0.2 %{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} Summary: User space tools for kernel auditing @@ -15,6 +15,7 @@ Patch3: audit-3.0-bpf-record.patch # Begin: Anolis customized patches Patch1001: 1001-audit-fix-gcc10-compile.patch +Patch1002: 1002-anolis-audit-3.0-add-loongarch-support.patch # End: Anolis customized patches BuildRequires: gcc swig @@ -94,6 +95,8 @@ Management Facility) database, through an IBM Tivoli Directory Server %patch2 -p1 %patch3 -p1 %patch1001 -p1 +%patch1002 -p1 + cp %{SOURCE1} . %build @@ -258,6 +261,9 @@ fi %attr(750,root,root) /sbin/audispd-zos-remote %changelog +* Tue Jan 25 2022 Liwei Ge - 3.0-0.17.20191104git1c2f876.0.2 +- Support loongarch64 platform + * Thu Dec 09 2021 Weitao Zhou 3-0.17.20191104git1c2f876.0.1 - use extern in header files when declaring global variables for compatible gcc10 build