audit: generic compat system call support
Subsystems (3)
RFC PATCH 1/1 audit: generic compat system call support
Arm64 supports 32-bit mode(AArch32) and 64-bit mode(AArch64). To enable audit support, we want to avoid duplicating lib/audit.c as other arch's do, and instead to use lib/audit.c and extend/re-work it in order to support compat system calls as well.
Changes are nothing fancy, just copying lib/audit.c and adding hooks for compat system calls as done in other arch's.
Once this patch is accepted, my aarch64 patch will be rebased on top of this.
(If you want, I can submit it immediately because it is already working.)
AKASHI Takahiro (1):
audit: Add generic compat syscall support
include/linux/audit.h | 3 +++ lib/Makefile | 3 +++ lib/audit.c | 10 ++++++++ lib/compat_audit.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.c
Signature · 1 line
1.7.9.5
RFC PATCH 1/1 audit: Add generic compat syscall support
lib/audit.c provides a generic definition for auditing system calls. lib/compat_audit.c similarly adds compat syscall support for bi-architectures (32/64-bit).
Each architecture must define audit_is_compat() in asm/audit.h.
--- include/linux/audit.h | 3 +++ lib/Makefile | 3 +++ lib/audit.c | 10 ++++++++ lib/compat_audit.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.c
include/linux/audit.h +3 -0
@@ -75,6 +75,9 @@ struct audit_field {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall); +#ifdef CONFIG_COMPAT +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif extern int audit_classify_arch (int arch);/* audit_names->type values */
lib/Makefile +3 -0
@@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
lib/audit.c +10 -0
@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {
@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif +switch (syscall) {#ifdef __NR_opencase __NR_open:
lib/compat_audit.c new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC PATCH v2 1/1 audit: Add generic compat syscall support
(v1 was created mistakenly. Please igore it.)
lib/audit.c provides a generic definition for auditing system calls. lib/compat_audit.c similarly adds compat syscall support for bi-architectures (32/64-bit).
Each architecture must define audit_is_compat() in asm/audit.h.
--- include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.c
include/linux/audit.h +9 -0
@@ -76,6 +76,15 @@ struct audit_field {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */
lib/Makefile +3 -0
@@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
lib/audit.c +17 -0
@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {
@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif +switch (syscall) {#ifdef __NR_opencase __NR_open:
@@ -57,6 +67,13 @@ int audit_classify_syscall(int abi, unsigned syscall)static int __init audit_classes_init (void ) { +#ifdef CONFIG_COMPAT +audit_register_class (AUDIT_CLASS_WRITE , compat_write_class); +audit_register_class (AUDIT_CLASS_READ , compat_read_class); +audit_register_class (AUDIT_CLASS_DIR_WRITE , compat_dir_class); +audit_register_class (AUDIT_CLASS_CHATTR , compat_chattr_class); +audit_register_class (AUDIT_CLASS_SIGNAL , compat_signal_class); +#endif audit_register_class (AUDIT_CLASS_WRITE , write_class);audit_register_class (AUDIT_CLASS_READ , read_class);audit_register_class (AUDIT_CLASS_DIR_WRITE , dir_class);
lib/compat_audit.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [RFC PATCH v2 1/1] audit: Add generic compat syscall support
Quoted 70 lines · AKASHI Takahiro
(v1 was created mistakenly. Please igore it.)
lib/audit.cprovides a generic definition for auditing system calls.lib/compat_audit.csimilarly adds compat syscall support for bi-architectures (32/64-bit).Each architecture must define
audit_is_compat()inasm/audit.h.Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.cinclude/linux/audit.h +9
-0@@ -76,6 +76,15 @@ struct audit_field {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */ lib/Makefile +3
-0@@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.olib/audit.c +4
-0@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ;
lib/audit.c static unsigned signal_class[] = { · line 46
Quoted 10 lines
lib/audit.c +5
-0+#endif return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif
Hmm, I'm not sure this is the right way to solve this problem. Whether something is compat or not depends on the task to which it is associated. If this is always the current task for the audit cases, then you can just use something like is_compat_task. Otherwise, I think we need to get a handle on the task_struct here. An arch-callback feels like the wrong approach to me.
Will
Re: [RFC PATCH v2 1/1] audit: Add generic compat syscall support
Will, I always thank you for your comments:
Quoted 75 lines · Will Deacon
Quoted 74 lines · AKASHI Takahiro
(v1 was created mistakenly. Please igore it.)
lib/audit.cprovides a generic definition for auditing system calls.lib/compat_audit.csimilarly adds compat syscall support for bi-architectures (32/64-bit).Each architecture must define
audit_is_compat()inasm/audit.h.Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+)create mode 100644
lib/compat_audit.cinclude/linux/audit.h +9
-0@@ -76,6 +76,15 @@ struct audit_field {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */ lib/Makefile +3
-0@@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.olib/audit.c +5
-0@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }
Quoted 12 lines
lib/audit.c static unsigned signal_class[] = { · line 46
Quoted 6 lines
lib/audit.c +4
-0int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif Hmm, I'm not sure this is the right way to solve this problem. Whether something is compat or not depends on the task to which it is associated. If this is always the current task for the audit cases, then you can just use something like
is_compat_task. Otherwise, I think we need to get a handle on thetask_structhere. An arch-callback feels like the wrong approach to me.
You are completely right. In my current (v3 prototype) implementation, "abi" argument, which can be AUDIT_ARCH_ARM(EB) or AUDIT_ARCH_AARCH64(EB), passed to audit_classify_syscall() is determined per-task using is_compat_thread() when audit_syscall_entry() is executed in syscall_trace().
(Obviously audit_is_compat() is true only in case of AUDIT_ARCH_ARM.)
V3 based on this patch is working for 32-bit and 64-bit userland. I can submit v3 patch if you want.
Thanks,
-Takahiro AKASHI
Quoted 2 lines
Will
Re: [RFC PATCH v2 1/1] audit: Add generic compat syscall support
Quoted 89 lines · AKASHI Takahiro
Quoted 75 lines · Will Deacon
Quoted 74 lines · AKASHI Takahiro
(v1 was created mistakenly. Please igore it.)
lib/audit.cprovides a generic definition for auditing system calls.lib/compat_audit.csimilarly adds compat syscall support for bi-architectures (32/64-bit).Each architecture must define
audit_is_compat()inasm/audit.h.Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.cinclude/linux/audit.h +9
-0@@ -76,6 +76,15 @@ struct audit_field {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */ lib/Makefile +3
-0@@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.olib/audit.c +5
-0@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }Quoted 12 lines
lib/audit.c static unsigned signal_class[] = { · line 46
Quoted 6 lines
lib/audit.c +4
-0int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif Hmm, I'm not sure this is the right way to solve this problem. Whether something is compat or not depends on the task to which it is associated. If this is always the current task for the audit cases, then you can just use something like
is_compat_task. Otherwise, I think we need to get a handle on thetask_structhere. An arch-callback feels like the wrong approach to me.
Quoted 8 lines
You are completely right. In my current (v3 prototype) implementation, "abi" argument, which can be
AUDIT_ARCH_ARM(EB)orAUDIT_ARCH_AARCH64(EB), passed toaudit_classify_syscall()is determined per-task usingis_compat_thread()whenaudit_syscall_entry()is executed insyscall_trace().
(Obviouslyaudit_is_compat()is true only in case ofAUDIT_ARCH_ARM.)V3 based on this patch is working for 32-bit and 64-bit userland. I can submit v3 patch if you want.
Yes, please. This is new territory to me, but I don't see any issues.
Quoted 4 lines
Thanks,
-Takahiro AKASHIQuoted 1 line
Will
- RGB
--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
PATCH v3 1/1 audit: generic compat system call support
In reply to AKASHI TakahiroArm64 supports 32-bit mode(AArch32) and 64-bit mode(AArch64). To enable audit on arm64, we want to use lib/audit.c and re-work it to support compat system calls as well without copying it under arch sub-directory.
So this patch is mandatory for my "system call audit support for arm64" patch. Please review it as well for better understandings.
This code was tested on armv8 fast model with 64-bit and 32-bit userland by using modified audit-test-code.
Changes v1 -> v2:
* Specify AUDIT_CLASS_XYZ_32 instead of AUDIT_CLASS_XYZ when registering compat syscalls (bug fix)
AKASHI Takahiro (1):
audit: Add generic compat syscall support
include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.c
Signature · 1 line
1.7.9.5
PATCH v3 1/1 audit: Add generic compat syscall support
lib/audit.c provides a generic definition for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by adding lib/compat_audit.c when CONFIG_COMPAT enabled.
Each architecture that wants to use this must define audit_is_compat() in asm/audit.h.
--- include/linux/audit.h | 9 +++++++++ lib/Makefile | 3 +++ lib/audit.c | 17 +++++++++++++++++ lib/compat_audit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 lib/compat_audit.c
include/linux/audit.h +9 -0
@@ -78,6 +78,15 @@ extern int is_audit_feature_set(int which);extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */
lib/Makefile +3 -0
@@ -93,6 +93,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
lib/audit.c +17 -0
@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {
@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif +switch (syscall) {#ifdef __NR_opencase __NR_open:
@@ -57,6 +67,13 @@ int audit_classify_syscall(int abi, unsigned syscall)static int __init audit_classes_init (void ) { +#ifdef CONFIG_COMPAT +audit_register_class (AUDIT_CLASS_WRITE_32 , compat_write_class); +audit_register_class (AUDIT_CLASS_READ_32 , compat_read_class); +audit_register_class (AUDIT_CLASS_DIR_WRITE_32 , compat_dir_class); +audit_register_class (AUDIT_CLASS_CHATTR_32 , compat_chattr_class); +audit_register_class (AUDIT_CLASS_SIGNAL_32 , compat_signal_class); +#endif audit_register_class (AUDIT_CLASS_WRITE , write_class);audit_register_class (AUDIT_CLASS_READ , read_class);audit_register_class (AUDIT_CLASS_DIR_WRITE , dir_class);
lib/compat_audit.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Catalin Marinas
maintainerPATCH v3 1/1 audit: Add generic compat syscall support
Quoted 8 lines · AKASHI Takahiro
lib/audit.cprovides a generic definition for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by addinglib/compat_audit.cwhenCONFIG_COMPATenabled.Each architecture that wants to use this must define
audit_is_compat()inasm/audit.h.Signed-off-by AKASHI Takahiro <[email protected]>
I'm not familiar with the audit subsystem but I have some (cosmetic) comments below.
Quoted 25 lines
include/linux/audit.h +9
-0@@ -78,6 +78,15 @@ extern int is_audit_feature_set(int which);extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif /* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */ lib/Makefile +0
-0
lib/Makefile obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o · line 98
Quoted 6 lines
lib/Makefile +3
-0@@ -93,6 +93,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif
You could use a CONFIG_AUDIT_COMPAT_GENERIC and simplify other #ifdefs as well.
Quoted 11 lines
lib/audit.c +1
-0@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {
lib/audit.c static unsigned signal_class[] = { · line 39
Quoted 9 lines
lib/audit.c +4
-0@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }
Here and in other places, just define a default audit_is_compat() functions which returns false when !CONFIG_COMPAT to avoid the #ifdefs.
lib/compat_audit.c line 4
Quoted 10 lines
lib/compat_audit.c new file +4
-0@@ -0,0 +1,51 @@ +#include <linux/init.h> +#include <linux/types.h> +/* FIXME: this might be architecture dependent */ +#include <asm/unistd_32.h>
It most likely is architecture dependent.
Quoted 11 lines
lib/compat_audit.c new file +11
-0+int audit_classify_compat_syscall (int abi,unsigned syscall) +{ +switch (syscall) { +#ifdef __NR_open +case __NR_open: +return 2 ; +#endif +#ifdef __NR_openat +case __NR_openat: +return 3 ; +#endif
lib/compat_audit.c line 51
Quoted 10 lines
lib/compat_audit.c new file +10
-0+#ifdef __NR_socketcall +case __NR_socketcall: +return 4 ; +#endif +case __NR_execve: +return 5 ; +default : +return 1 ; + } +}
BTW, since they aren't many, you could get the arch code to define __NR_compat_open etc. explicitly and use these. On arm64 we have a few of these defined to avoid name collision in signal handling code.
Signature · 1 line
Catalin
PATCH v3 1/1 audit: Add generic compat syscall support
Catalin and audit maintainers,
Quoted 31 lines · Catalin Marinas
Quoted 8 lines · AKASHI Takahiro
lib/audit.cprovides a generic definition for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by addinglib/compat_audit.cwhenCONFIG_COMPATenabled.Each architecture that wants to use this must define
audit_is_compat()inasm/audit.h.Signed-off-by AKASHI Takahiro <[email protected]>I'm not familiar with the audit subsystem but I have some (cosmetic) comments below.
Quoted 18 lines
include/linux/audit.h +9
-0@@ -78,6 +78,15 @@ extern int is_audit_feature_set(int which);extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +#if defined(CONFIG_AUDIT_GENERIC ) && defined(CONFIG_COMPAT ) +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif
Quoted 16 lines
lib/Makefile obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o · line 98
Quoted 13 lines
include/linux/audit.h +0
-0/* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */ lib/Makefile +3
-0@@ -93,6 +93,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endifYou could use a
CONFIG_AUDIT_COMPAT_GENERICand simplify other #ifdefs as well.
I will add the following in lib/Kconfig:
config AUDIT_COMPAT_GENERIC
depends on AUDIT_GENERIC & COMPAT
default y
Quoted 12 lines
Quoted 12 lines
lib/audit.c +1
-0@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {@@ -30,11 +31,20 @@ static unsigned signal_class[] = {
Quoted 11 lines
lib/audit.c static unsigned signal_class[] = { · line 39
Quoted 8 lines
lib/audit.c +4
-0int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }Here and in other places, just define a default
audit_is_compat()functions which returns false when !CONFIG_COMPAT to avoid the #ifdefs.
OK. With Richard's comment, the definition below will be added to uapi/linux/audit.h:
#ifdef CONFIG_COMPAT #define audit_is_compat(arch) (!!((arch) & __AUDIT_ARCH_64BIT)) #else #define audit_is_compat(arch) false #endif
Quoted 4 lines
Quoted 4 lines
lib/compat_audit.c new file +0
-1--- /dev/null
Quoted 8 lines
lib/compat_audit.c line 4
Quoted 6 lines
+++
b/lib/compat_audit.clib/compat_audit.c new file +4
-0@@ -0,0 +1,51 @@ +#include <linux/init.h> +#include <linux/types.h> +/* FIXME: this might be architecture dependent */ +#include <asm/unistd_32.h> It most likely is architecture dependent.
I'm wondering what name is the most appropriate in this case. Most archictures have __NR_xyz definitions in "unistd_32.h", but arm64 doesn't have it, instead "unistd32." which contains only __SYSCALL(xyz, NO). Confusing?
Quoted 17 lines
Quoted 17 lines
lib/compat_audit.c new file +17
-0+int audit_classify_compat_syscall (int abi,unsigned syscall) +{ +switch (syscall) { +#ifdef __NR_open +case __NR_open: +return 2 ; +#endif +#ifdef __NR_openat +case __NR_openat: +return 3 ; +#endif +#ifdef __NR_socketcall +case __NR_socketcall: +return 4 ; +#endif +case __NR_execve: +return 5 ;
Quoted 8 lines
lib/compat_audit.c line 51
Quoted 4 lines
lib/compat_audit.c new file +4
-0+default : +return 1 ; + } +}BTW, since they aren't many, you could get the arch code to define
__NR_compat_openetc. explicitly and use these. On arm64 we have a few of these defined to avoid name collision in signal handling code.
Again, most architecture have their own unistd32.h for compat system calls, and use __NR_open-like naming.
It's unlikely for these archs to migrate to "generic compat" auditing, but I believe that '__NR_open'-like naming is better because we may be able to avoid arch-specific changes even for future(?) syscall-related enhancements in audit.
But, anyway, it's up to audit maintainer's preference.
Thanks,
-Takahiro AKASHI
Catalin Marinas
maintainerPATCH v3 1/1 audit: Add generic compat syscall support
Quoted 17 lines · AKASHI Takahiro
Catalin and audit maintainers,
Quoted 13 lines · Catalin Marinas
lib/compat_audit.c line 4
Quoted 10 lines · AKASHI Takahiro
lib/compat_audit.c new file +4
-0@@ -0,0 +1,51 @@ +#include <linux/init.h> +#include <linux/types.h> +/* FIXME: this might be architecture dependent */ +#include <asm/unistd_32.h> It most likely is architecture dependent.
Quoted 4 lines
I'm wondering what name is the most appropriate in this case. Most archictures have
__NR_xyzdefinitions in "unistd_32.h", but arm64 doesn't have it, instead "unistd32." which contains only__SYSCALL(xyz, NO). Confusing?
I don't think we should introduce a new file (or at least it should be named something containing "audit" to make it clearer).
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
lib/compat_audit.c new file +17
-0+int audit_classify_compat_syscall (int abi,unsigned syscall) +{ +switch (syscall) { +#ifdef __NR_open +case __NR_open: +return 2 ; +#endif +#ifdef __NR_openat +case __NR_openat: +return 3 ; +#endif +#ifdef __NR_socketcall +case __NR_socketcall: +return 4 ; +#endif +case __NR_execve: +return 5 ;Quoted 8 lines
lib/compat_audit.c line 51
Quoted 4 lines
lib/compat_audit.c new file +4
-0+default : +return 1 ; + } +}BTW, since they aren't many, you could get the arch code to define
__NR_compat_openetc. explicitly and use these. On arm64 we have a few of these defined to avoid name collision in signal handling code.
Quoted 5 lines
Again, most architecture have their own
unistd32.hfor compat system calls, and use __NR_open-like naming.
It's unlikely for these archs to migrate to "generic compat" auditing, but I believe that '__NR_open'-like naming is better because we may be able to avoid arch-specific changes even for future(?) syscall-related enhancements in audit.
My preference is as above, a few __NR_compat_* (just those required by audit) defined in unistd.h but I'm not an audit maintainer.
Signature · 1 line
Catalin
Re: [PATCH v3] audit: Add generic compat syscall support
Catalin,
Let me correct myself,
Quoted 18 lines · Catalin Marinas
Quoted 17 lines · AKASHI Takahiro
Catalin and audit maintainers,
Quoted 13 lines · Catalin Marinas
lib/compat_audit.c line 4
Quoted 10 lines · AKASHI Takahiro
lib/compat_audit.c new file +4
-0@@ -0,0 +1,51 @@ +#include <linux/init.h> +#include <linux/types.h> +/* FIXME: this might be architecture dependent */ +#include <asm/unistd_32.h> It most likely is architecture dependent.
Quoted 39 lines
Quoted 4 lines
I'm wondering what name is the most appropriate in this case. Most archictures have
__NR_xyzdefinitions in "unistd_32.h", but arm64 doesn't have it, instead "unistd32." which contains only__SYSCALL(xyz, NO). Confusing?I don't think we should introduce a new file (or at least it should be named something containing "audit" to make it clearer).
Quoted 31 lines
Quoted 17 lines
Quoted 17 lines
lib/compat_audit.c new file +17
-0+int audit_classify_compat_syscall (int abi,unsigned syscall) +{ +switch (syscall) { +#ifdef __NR_open +case __NR_open: +return 2 ; +#endif +#ifdef __NR_openat +case __NR_openat: +return 3 ; +#endif +#ifdef __NR_socketcall +case __NR_socketcall: +return 4 ; +#endif +case __NR_execve: +return 5 ;Quoted 8 lines
lib/compat_audit.c line 51
Quoted 4 lines
lib/compat_audit.c new file +4
-0+default : +return 1 ; + } +}BTW, since they aren't many, you could get the arch code to define
__NR_compat_openetc. explicitly and use these. On arm64 we have a few of these defined to avoid name collision in signal handling code.Again, most architecture have their own
unistd32.hfor compat system calls, and use __NR_open-like naming.
It's unlikely for these archs to migrate to "generic compat" auditing, but I believe that '__NR_open'-like naming is better because we may be able to avoid arch-specific changes even for future(?) syscall-related enhancements in audit.
In my compat_audit.c, all the entries in audit classes are derived from asm-generic/audit_*.h, where __NR_xyz are used to list the system calls. So it is not possible to use __NR_compat_xyz as far as we re-use those generic files.
(Obviously we don't want to duplicate those header files, that is, audit_compat_*.h.)
I agree that we should not have similar but different files, like unist32.h and unistd_32.h, but it seems to be inevitable for our case. (That is the reason why I dynamically generate unistd_32.h)
As for arch-specific header file name, "audit_unistd32.h" can be fine, but people on other architectures might be unhappy with such a name since they can commonly use unistd32.h instead.
- Takahiro AKASHI
Quoted 3 lines
My preference is as above, a few __NR_compat_* (just those required by audit) defined in
unistd.hbut I'm not an audit maintainer.
Catalin Marinas
maintainerRe: [PATCH v3] audit: Add generic compat syscall support
Quoted 35 lines · AKASHI Takahiro
Quoted 28 lines · Catalin Marinas
Quoted 27 lines · AKASHI Takahiro
Quoted 25 lines · Catalin Marinas
Quoted 11 lines
(quoted diff) +11
-0+int audit_classify_compat_syscall(int abi, unsigned syscall) +{ + switch (syscall) { +#ifdef __NR_open + case __NR_open: + return 2; +#endif +#ifdef __NR_openat + case __NR_openat: + return 3; +#endifReview
Quoted 10 lines
(quoted diff) +10
-0+#ifdef __NR_socketcall + case __NR_socketcall: + return 4; +#endif + case __NR_execve: + return 5; + default: + return 1; + } +}BTW, since they aren't many, you could get the arch code to define
__NR_compat_openetc. explicitly and use these. On arm64 we have a few of these defined to avoid name collision in signal handling code.Quoted 5 lines
Quoted 5 lines
Again, most architecture have their own
unistd32.hfor compat system calls, and use __NR_open-like naming.
It's unlikely for these archs to migrate to "generic compat" auditing, but I believe that '__NR_open'-like naming is better because we may be able to avoid arch-specific changes even for future(?) syscall-related enhancements in audit.
Quoted 4 lines
In my
compat_audit.c, all the entries in audit classes are derived fromasm-generic/audit_*.h, where__NR_xyzare used to list the system calls. So it is not possible to use__NR_compat_xyzas far as we re-use those generic files.
(Obviously we don't want to duplicate those header files, that is, audit_compat_*.h.)
Ah, I missed the other __NR_* uses in the generic audit_*.h files. Below is an attempt to add compat __NR_* definitions to arm64 unistd32.h. There are other ways of doing this and still avoid collision with the native ones but I thought that's the easiest. Note that these are not uapi headers, so they are just for the kernel. Compile-tested only (and please check, maybe my vim macros and regexp got something wrong):
(and in the process I found two new AArch32 syscalls which I'll add to the compat layer)
---------------8<----------------
Quoted 1 line
From
462506af19400ab4000be827321a130ca2bdade2Mon Sep 17 00:00:00 2001
From: Catalin Marinas <[email protected]>
Date: Thu, 30 Jan 2014 17:56:56 +0000
Subject: [PATCH] arm64: Add __NR_* definitions for compat syscalls
This patch adds __NR_* definitions to asm/unistd32.h, moves the __NR_compat_* definitions to asm/unistd.h and removes all the explicit unistd32.h includes apart from the one building the compat syscall table. The aim is to have the compat __NR_* definitions available but without colliding with the native syscall definitions.
--- arch/arm64/include/asm/unistd.h | 17 + arch/arm64/include/asm/unistd32.h | 1154 ++++++++++++++++++++++++------------- arch/arm64/kernel/entry.S | 1 - arch/arm64/kernel/kuser32.S | 2 +- arch/arm64/kernel/signal32.c | 2 +- arch/arm64/kernel/sys_compat.c | 2 +- 6 files changed, 778 insertions(+), 400 deletions(-)
arch/arm64/include/asm/unistd.h +17 -0
@@ -25,6 +25,23 @@#define __ARCH_WANT_COMPAT_SYS_SENDFILE#define __ARCH_WANT_SYS_FORK#define __ARCH_WANT_SYS_VFORK + +/* +* Compat syscall numbers used by the AArch64 kernel. +*/ +#define __NR_compat_restart_syscall 0 +#define __NR_compat_sigreturn 119 +#define __NR_compat_rt_sigreturn 173 + +/* +* The following SVCs are ARM private. +*/ +#define __ARM_NR_COMPAT_BASE 0x0f0000 +#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2) +#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5) + +#define __NR_compat_syscalls 379#endif +#define __ARCH_WANT_SYS_CLONE#include <uapi/asm/unistd.h>
arch/arm64/include/asm/unistd32.h +758 -396
1,157 lines not on this page · raw message
arch/arm64/kernel/entry.S +0 -1
@@ -27,7 +27,6 @@ #include <asm/esr.h> #include <asm/thread_info.h> #include <asm/unistd.h> -#include <asm/unistd32.h> /* * Bad Abort numbers
arch/arm64/kernel/kuser32.S +1 -1
@@ -28,7 +28,7 @@ * See Documentation/arm/kernel_user_helpers.txt for formal definitions. */ -#include <asm/unistd32.h> +#include <asm/unistd.h> .align 5 .globl __kuser_helper_start
arch/arm64/kernel/signal32.c +1 -1
@@ -26,7 +26,7 @@#include <asm/fpsimd.h> #include <asm/signal32.h> #include <asm/uaccess.h> -#include <asm/unistd32.h> +#include <asm/unistd.h> struct compat_sigcontext {/* We always set these two fields to 0 */
arch/arm64/kernel/sys_compat.c +1 -1
@@ -26,7 +26,7 @@#include <linux/uaccess.h> #include <asm/cacheflush.h> -#include <asm/unistd32.h> +#include <asm/unistd.h> static inline void do_compat_cache_op (unsigned long start,unsigned long end,int flags)
v4 cover audit: generic compat system call support
In reply to AKASHI TakahiroArm64 supports 32-bit mode(AArch32) and 64-bit mode(AArch64). To enable audit on arm64, we want to use lib/audit.c and re-work it to support compat system calls as well without copying it under arch sub-directory.
Since this patch is implemented in much the same way as on existing bi-architectures (ie. ppc, s390, sparc and x86), it's not difficult for them to utilize this generic code instead of their own implementation.
The code was tested on armv8 fast model with 64-bit and 32-bit userland by using modified audit-test-code. As this patch is mandatory for my "system call audit support for arm64" patch, please review it as well for better understandings.
Changes v2 -> v3:
* Specify AUDIT_CLASS_XYZ_32 instead of AUDIT_CLASS_XYZ when registering compat syscalls (bug fix)
Changes v3 -> v4:
* Add CONFIG_AUDIT_COMPAT_GENERIC to compile in compat_audit.c
* Re-define audit_is_compat() in generic way in order to eliminate necessity of asm/audit.h.
AKASHI Takahiro (1):
audit: Add generic compat syscall support
include/linux/audit.h | 8 +++++++ include/uapi/linux/audit.h | 6 ++++++ lib/Kconfig | 5 +++++ lib/Makefile | 1 + lib/audit.c | 15 ++++++++++++- lib/compat_audit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 lib/compat_audit.c
Signature · 1 line
1.7.9.5
PATCH v4 1/1 audit: Add generic compat syscall support
lib/audit.c provides a generic definition for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by adding lib/compat_audit.c.
What is required to support this feature are:
* add asm/unistd32.h for compat system call names
* enable CONFIG_AUDIT_COMPAT_GENERIC
--- include/linux/audit.h | 8 +++++++ include/uapi/linux/audit.h | 6 ++++++ lib/Kconfig | 5 +++++ lib/Makefile | 1 + lib/audit.c | 15 ++++++++++++- lib/compat_audit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 lib/compat_audit.c
include/linux/audit.h +8 -0
@@ -78,6 +78,14 @@ extern int is_audit_feature_set(int which);extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +/* only for compat system calls */ +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int __weak audit_classify_compat_syscall (int abi,unsigned syscall);/* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */
include/uapi/linux/audit.h +6 -0
@@ -355,6 +355,12 @@ enum {#define AUDIT_ARCH_SPARC64 (EM_SPARCV9|__AUDIT_ARCH_64BIT)#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#ifdef CONFIG_COMPAT +#define audit_is_compat (arch) (!((arch) & __AUDIT_ARCH_64BIT)) +#else +#define audit_is_compat (arch) false +#endif +#define AUDIT_PERM_EXEC 1#define AUDIT_PERM_WRITE 2#define AUDIT_PERM_READ 4
lib/Kconfig +5 -0
@@ -182,6 +182,11 @@ config AUDIT_GENERIC depends on AUDIT && !AUDIT_ARCH default y +config AUDIT_COMPAT_GENERIC + bool + depends on AUDIT_GENERIC && COMPAT + default y + config RANDOM32_SELFTEST bool "PRNG perform self test on init" default n
lib/Makefile +1 -0
@@ -93,6 +93,7 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
lib/audit.c +14 -1
@@ -30,11 +30,17 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { -return 0 ; +if (audit_is_compat (arch)) +return 1 ; +else +return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +switch (syscall) {#ifdef __NR_opencase __NR_open:
@@ -57,6 +63,13 @@ int audit_classify_syscall(int abi, unsigned syscall)static int __init audit_classes_init (void ) { +#ifdef CONFIG_AUDIT_COMPAT_GENERIC +audit_register_class (AUDIT_CLASS_WRITE_32 , compat_write_class); +audit_register_class (AUDIT_CLASS_READ_32 , compat_read_class); +audit_register_class (AUDIT_CLASS_DIR_WRITE_32 , compat_dir_class); +audit_register_class (AUDIT_CLASS_CHATTR_32 , compat_chattr_class); +audit_register_class (AUDIT_CLASS_SIGNAL_32 , compat_signal_class); +#endif audit_register_class (AUDIT_CLASS_WRITE , write_class);audit_register_class (AUDIT_CLASS_READ , read_class);audit_register_class (AUDIT_CLASS_DIR_WRITE , dir_class);
lib/compat_audit.c new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Arm64 supports 32-bit mode(AArch32) and 64-bit mode(AArch64). To enable audit on arm64, we want to use lib/audit.c and re-work it to support compat system calls as well without copying it under arch sub-directory.
Since this patch is implemented in much the same way as on existing bi-architectures (ie. ppc, s390, sparc and x86), it's not difficult for them to utilize this generic code instead of their own implementation.
The code was tested on armv8 fast model with 64-bit and 32-bit userland by using modified audit-test-code. As this patch is mandatory for my "system call audit support for arm64" patch, please review it as well for better understandings.
Changes v4 -> v5:
* Add CONFIG_AUDIT_ARCH_COMPAT_GENERIC. Its purpose is to avoid compling compat_audit.c unintentionally. Some architectures may enable AUDIT, COMPAT and then AUDIT_GENERIC if !AUDIT_ARCH, but not really need compat_audit.c.
(mips is the case, but mips doesn't really support AUDITSYSCALL though.)
Changes v3 -> v4:
* Add CONFIG_AUDIT_COMPAT_GENERIC to compile in compat_audit.c
* Re-define audit_is_compat() in generic way in order to eliminate necessity of asm/audit.h.
Changes v2 -> v3:
* Specify AUDIT_CLASS_XYZ_32 instead of AUDIT_CLASS_XYZ when registering compat syscalls (bug fix)
AKASHI Takahiro (1):
audit: Add generic compat syscall support
include/linux/audit.h | 8 ++++++++ include/uapi/linux/audit.h | 6 ++++++ lib/Kconfig | 9 +++++++++ lib/Makefile | 1 + lib/audit.c | 15 +++++++++++++- lib/compat_audit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 lib/compat_audit.c
Signature · 1 line
1.8.3.2
[PATCH_v5] audit: Add generic compat syscall support
lib/audit.c provides a generic function for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by adding lib/compat_audit.c.
What is required to support this feature are:
* add asm/unistd32.h for compat system call names
* select CONFIG_AUDIT_ARCH_COMPAT_GENERIC
--- include/linux/audit.h | 8 ++++++++ include/uapi/linux/audit.h | 6 ++++++ lib/Kconfig | 9 +++++++++ lib/Makefile | 1 + lib/audit.c | 15 +++++++++++++- lib/compat_audit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 lib/compat_audit.c
include/linux/audit.h +8 -0
@@ -78,6 +78,14 @@ extern int is_audit_feature_set(int which);extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +/* only for compat system calls */ +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int __weak audit_classify_compat_syscall (int abi,unsigned syscall);/* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */
include/uapi/linux/audit.h +6 -0
@@ -361,6 +361,12 @@ enum {#define AUDIT_ARCH_SPARC64 (EM_SPARCV9|__AUDIT_ARCH_64BIT)#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#ifdef CONFIG_COMPAT +#define audit_is_compat (arch) (!((arch) & __AUDIT_ARCH_64BIT)) +#else +#define audit_is_compat (arch) false +#endif +#define AUDIT_PERM_EXEC 1#define AUDIT_PERM_WRITE 2#define AUDIT_PERM_READ 4
lib/Kconfig +9 -0
@@ -182,6 +182,15 @@ config AUDIT_GENERIC depends on AUDIT && !AUDIT_ARCH default y +config AUDIT_ARCH_COMPAT_GENERIC + bool + default n + +config AUDIT_COMPAT_GENERIC + bool + depends on AUDIT_GENERIC && AUDIT_ARCH_COMPAT_GENERIC && COMPAT + default y + config RANDOM32_SELFTEST bool "PRNG perform self test on init" default n
lib/Makefile +1 -0
@@ -96,6 +96,7 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
lib/audit.c +14 -1
@@ -30,11 +30,17 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { -return 0 ; +if (audit_is_compat (arch)) +return 1 ; +else +return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +switch (syscall) {#ifdef __NR_opencase __NR_open:
@@ -57,6 +63,13 @@ int audit_classify_syscall(int abi, unsigned syscall)static int __init audit_classes_init (void ) { +#ifdef CONFIG_AUDIT_COMPAT_GENERIC +audit_register_class (AUDIT_CLASS_WRITE_32 , compat_write_class); +audit_register_class (AUDIT_CLASS_READ_32 , compat_read_class); +audit_register_class (AUDIT_CLASS_DIR_WRITE_32 , compat_dir_class); +audit_register_class (AUDIT_CLASS_CHATTR_32 , compat_chattr_class); +audit_register_class (AUDIT_CLASS_SIGNAL_32 , compat_signal_class); +#endif audit_register_class (AUDIT_CLASS_WRITE , write_class);audit_register_class (AUDIT_CLASS_READ , read_class);audit_register_class (AUDIT_CLASS_DIR_WRITE , dir_class);
lib/compat_audit.c new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH_v5] audit: Add generic compat syscall support
Quoted 8 lines · AKASHI Takahiro
lib/audit.cprovides a generic function for auditing system calls. This patch extends it for compat syscall support on bi-architectures (32/64-bit) by addinglib/compat_audit.c.
What is required to support this feature are:
* addasm/unistd32.hfor compat system call names
* selectCONFIG_AUDIT_ARCH_COMPAT_GENERICSigned-off-by AKASHI Takahiro <[email protected]>
Quoted 174 lines
--- include/linux/audit.h | 8 ++++++++ include/uapi/linux/audit.h | 6 ++++++ lib/Kconfig | 9 +++++++++ lib/Makefile | 1 + lib/audit.c | 15 +++++++++++++- lib/compat_audit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 lib/compat_audit.cinclude/linux/audit.h +8
-0@@ -78,6 +78,14 @@ extern int is_audit_feature_set(int which);extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall);extern int audit_classify_arch (int arch); +/* only for compat system calls */ +extern unsigned compat_write_class[]; +extern unsigned compat_read_class[]; +extern unsigned compat_dir_class[]; +extern unsigned compat_chattr_class[]; +extern unsigned compat_signal_class[]; + +extern int __weak audit_classify_compat_syscall (int abi,unsigned syscall);/* audit_names->type values */ #define AUDIT_TYPE_UNKNOWN 0/* we don't know yet */ include/uapi/linux/audit.h +6
-0@@ -361,6 +361,12 @@ enum {#define AUDIT_ARCH_SPARC64 (EM_SPARCV9|__AUDIT_ARCH_64BIT)#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) +#ifdef CONFIG_COMPAT +#define audit_is_compat (arch) (!((arch) & __AUDIT_ARCH_64BIT)) +#else +#define audit_is_compat (arch) false +#endif +#define AUDIT_PERM_EXEC 1#define AUDIT_PERM_WRITE 2#define AUDIT_PERM_READ 4lib/Kconfig +9
-0@@ -182,6 +182,15 @@ config AUDIT_GENERIC depends on AUDIT && !AUDIT_ARCH default y +config AUDIT_ARCH_COMPAT_GENERIC + bool + default n + +config AUDIT_COMPAT_GENERIC + bool + depends on AUDIT_GENERIC && AUDIT_ARCH_COMPAT_GENERIC && COMPAT + default y + config RANDOM32_SELFTEST bool "PRNG perform self test on init" default nlib/Makefile +1
-0@@ -96,6 +96,7 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.olib/audit.c +14
-1@@ -30,11 +30,17 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { -return 0 ; +if (audit_is_compat (arch)) +return 1 ; +else +return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +switch (syscall) {#ifdef __NR_opencase __NR_open:@@ -57,6 +63,13 @@ int audit_classify_syscall(int abi, unsigned syscall)static int __init audit_classes_init (void ) { +#ifdef CONFIG_AUDIT_COMPAT_GENERIC +audit_register_class (AUDIT_CLASS_WRITE_32 , compat_write_class); +audit_register_class (AUDIT_CLASS_READ_32 , compat_read_class); +audit_register_class (AUDIT_CLASS_DIR_WRITE_32 , compat_dir_class); +audit_register_class (AUDIT_CLASS_CHATTR_32 , compat_chattr_class); +audit_register_class (AUDIT_CLASS_SIGNAL_32 , compat_signal_class); +#endif audit_register_class (AUDIT_CLASS_WRITE , write_class);audit_register_class (AUDIT_CLASS_READ , read_class);audit_register_class (AUDIT_CLASS_DIR_WRITE , dir_class);lib/compat_audit.c new file +50
-0@@ -0,0 +1,50 @@ +#include <linux/init.h> +#include <linux/types.h> +#include <asm/unistd32.h> + +unsigned compat_dir_class[] = { +#include <asm-generic/audit_dir_write.h> +~0U +}; + +unsigned compat_read_class[] = { +#include <asm-generic/audit_read.h> +~0U +}; + +unsigned compat_write_class[] = { +#include <asm-generic/audit_write.h> +~0U +}; + +unsigned compat_chattr_class[] = { +#include <asm-generic/audit_change_attr.h> +~0U +}; + +unsigned compat_signal_class[] = { +#include <asm-generic/audit_signal.h> +~0U +}; + +int audit_classify_compat_syscall (int abi,unsigned syscall) +{ +switch (syscall) { +#ifdef __NR_open +case __NR_open: +return 2 ; +#endif +#ifdef __NR_openat +case __NR_openat: +return 3 ; +#endif +#ifdef __NR_socketcall +case __NR_socketcall: +return 4 ; +#endif +case __NR_execve: +return 5 ; +default : +return 1 ; + } +}Signature · 1 line
1.8.3.2
- RGB
--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Re: [RFC PATCH] audit: Add generic compat syscall support
In reply to AKASHI TakahiroTo: Eric, Al
Could you please give me your comments on my patch below? I don't think this patch breaks anything on existing architectures which support audit.
If you don't prefer the way, I'm going to keep the code arm64-specific to support audit on AArch64(arm64) as in my old patch series.:
https://www.redhat.com/archives/linux-audit/2013-November/msg00040.html
Thank you,
-Takahiro AKASHI
Quoted 147 lines · AKASHI Takahiro
lib/audit.cprovides a generic definition for auditing system calls.lib/compat_audit.csimilarly adds compat syscall support for bi-architectures (32/64-bit).Each architecture must define
audit_is_compat()inasm/audit.h.Signed-off-by AKASHI Takahiro <[email protected]>--- include/linux/audit.h | 3 +++ lib/Makefile | 3 +++ lib/audit.c | 10 ++++++++ lib/compat_audit.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+)create mode 100644
lib/compat_audit.cinclude/linux/audit.h +3
-0@@ -75,6 +75,9 @@ struct audit_field {extern int __init audit_register_class (int class,unsigned *list);extern int audit_classify_syscall (int abi,unsigned syscall); +#ifdef CONFIG_COMPAT +extern int audit_classify_compat_syscall (int abi,unsigned syscall); +#endif extern int audit_classify_arch (int arch);/* audit_names->type values */ lib/Makefile +3
-0@@ -96,6 +96,9 @@ obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o +ifeq ($(CONFIG_COMPAT),y) +obj-$(CONFIG_AUDIT_GENERIC) += compat_audit.o +endif obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.olib/audit.c +10
-0@@ -1,6 +1,7 @@#include <linux/init.h> #include <linux/types.h> #include <linux/audit.h> +#include <asm/audit.h> #include <asm/unistd.h> static unsigned dir_class[] = {@@ -30,11 +31,20 @@ static unsigned signal_class[] = {int audit_classify_arch (int arch) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (arch)) +return 1 ; +#endif return 0 ; }int audit_classify_syscall (int abi,unsigned syscall) { +#ifdef CONFIG_COMPAT +if (audit_is_compat (abi)) +return audit_classify_compat_syscall (abi, syscall); +#endif +switch (syscall) {#ifdef __NR_opencase __NR_open:lib/compat_audit.c new file +64
-0@@ -0,0 +1,64 @@ +#include <linux/init.h> +#include <linux/types.h> +#include <linux/audit.h> +/* FIXME: this might be architecture dependent */ +#include <asm/unistd_32.h> + +static unsigned compat_dir_class[] = { +#include <asm-generic/audit_dir_write.h> +~0U +}; + +static unsigned compat_read_class[] = { +#include <asm-generic/audit_read.h> +~0U +}; + +static unsigned compat_write_class[] = { +#include <asm-generic/audit_write.h> +~0U +}; + +static unsigned compat_chattr_class[] = { +#include <asm-generic/audit_change_attr.h> +~0U +}; + +static unsigned compat_signal_class[] = { +#include <asm-generic/audit_signal.h> +~0U +}; + +int audit_classify_compat_syscall (int abi,unsigned syscall) +{ +switch (syscall) { +#ifdef __NR_open +case __NR_open: +return 2 ; +#endif +#ifdef __NR_openat +case __NR_openat: +return 3 ; +#endif +#ifdef __NR_socketcall +case __NR_socketcall: +return 4 ; +#endif +case __NR_execve: +return 5 ; +default : +return 1 ; + } +} + +static int __init audit_compat_classes_init (void ) +{ +audit_register_class (AUDIT_CLASS_WRITE , compat_write_class); +audit_register_class (AUDIT_CLASS_READ , compat_read_class); +audit_register_class (AUDIT_CLASS_DIR_WRITE , compat_dir_class); +audit_register_class (AUDIT_CLASS_CHATTR , compat_chattr_class); +audit_register_class (AUDIT_CLASS_SIGNAL , compat_signal_class); +return 0 ; +} + +__initcall (audit_compat_classes_init);