Convert avc_audit to use lsm_audit.h
Subsystems (2)
PATCH 1/1 Convert avc_audit to use lsm_audit.h
Convert avc_audit in security/selinux/avc.c to use lsm_audit.h, for better maintainability and for less code duplication.
- changed selinux to use common_audit_data instead of avc_audit_data
- eliminated code in avc.c and used code from lsm_audit.h instead.
---
This patch depends on my earlier set of 3 (moving of function, making lsm_priv anonymous, ifdefs)
security/Makefile | 4 - security/selinux/avc.c | 215 +++++++++-------------------------- security/selinux/hooks.c | 142 ++++++++++++----------- security/selinux/include/avc.h | 47 -------- security/selinux/include/netlabel.h | 4 - security/selinux/include/xfrm.h | 8 + security/selinux/netlabel.c | 2 security/selinux/xfrm.c | 4 - 8 files changed, 140 insertions(+), 286 deletions(-)
security/Makefile +1 -3
@@ -16,9 +16,7 @@ obj-$(CONFIG_SECURITYFS) += inode.o # Must precede capability.o in order to stack properly. obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o -ifeq ($(CONFIG_AUDIT),y) -obj-$(CONFIG_SECURITY_SMACK) += lsm_audit.o -endif +obj-$(CONFIG_AUDIT) += lsm_audit.o obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
security/selinux/avc.c +56 -159
246 lines not on this page · raw message
security/selinux/hooks.c +71 -71
536 lines not on this page · raw message
security/selinux/include/avc.h +3 -44
71 lines not on this page · raw message
security/selinux/include/netlabel.h +2 -2
@@ -59,7 +59,7 @@ int selinux_netlbl_socket_post_create(struct sock *sk, u16 family);int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb,u16 family, -struct avc_audit_data *ad); +struct common_audit_data *ad);int selinux_netlbl_socket_setsockopt (struct socket *sock,int level,int optname);
@@ -129,7 +129,7 @@ static inline int selinux_netlbl_socket_post_create(struct sock *sk,static inline int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb,u16 family, -struct avc_audit_data *ad) +struct common_audit_data *ad) {return 0 ; }
security/selinux/include/xfrm.h +4 -4
@@ -41,9 +41,9 @@ static inline int selinux_xfrm_enabled(void) }int selinux_xfrm_sock_rcv_skb (u32 sid,struct sk_buff *skb, -struct avc_audit_data *ad); +struct common_audit_data *ad);int selinux_xfrm_postroute_last (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad,u8 proto); +struct common_audit_data *ad,u8 proto);int selinux_xfrm_decode_session (struct sk_buff *skb,u32 *sid,int ckall);static inline void selinux_xfrm_notify_policyload (void )
@@ -57,13 +57,13 @@ static inline int selinux_xfrm_enabled(void) }static inline int selinux_xfrm_sock_rcv_skb (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad) +struct common_audit_data *ad) {return 0 ; }static inline int selinux_xfrm_postroute_last (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad,u8 proto) +struct common_audit_data *ad,u8 proto) {return 0 ; }
security/selinux/netlabel.c +1 -1
@@ -342,7 +342,7 @@ int selinux_netlbl_socket_post_create(struct sock *sk, u16 family)int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb,u16 family, -struct avc_audit_data *ad) +struct common_audit_data *ad) {int rc;u32 nlbl_sid;
security/selinux/xfrm.c +2 -2
@@ -401,7 +401,7 @@ int selinux_xfrm_state_delete(struct xfrm_state *x)* gone thru the IPSec process. */ int selinux_xfrm_sock_rcv_skb (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad) +struct common_audit_data *ad) {int i, rc =0 ;struct sec_path *sp;
@@ -442,7 +442,7 @@ int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,* checked in the selinux_xfrm_state_pol_flow_match hook above. */ int selinux_xfrm_postroute_last (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad,u8 proto) +struct common_audit_data *ad,u8 proto) {struct dst_entry *dst;int rc =0 ;
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines · Thomas Liu
Convert
avc_auditinsecurity/selinux/avc.cto uselsm_audit.h, for better maintainability and for less code duplication.- changed selinux to use
common_audit_datainstead ofavc_audit_data
- eliminated code inavc.cand used code fromlsm_audit.hinstead.Signed-off-by Thomas Liu <[email protected]>---
First I didn't verify that the formatting didn't change. Did you generate and avc before and after this patch to make sure the audit record emitted is exactly the same?
Quoted 23 lines
security/selinux/avc.c +2
-2@@ -492,7 +492,7 @@ out:return node; } -static inline void avc_print_ipv6_addr (struct audit_buffer *ab, +static inline void print_ipv6_addr (struct audit_buffer *ab,struct in6_addr *addr,__be16 port,char *name1,char *name2) {@@ -502,7 +502,7 @@ static inline void avc_print_ipv6_addr(struct audit_buffer *ab,audit_log_format (ab," %s=%d" , name2,ntohs (port)); } -static inline void avc_print_ipv4_addr (struct audit_buffer *ab,__be32 addr, +static inline void print_ipv4_addr (struct audit_buffer *ab,__be32 addr,__be16 port,char *name1,char *name2) {if (addr)
security/selinux/avc.c static inline void avc_print_ipv4_addr(struct audit_buffer *ab, __be32 addr, · line 512
Quoted 1 line
security/selinux/avc.c +0
-0@@ -512,6 +512,52 @@ static inline void avc_print_ipv4_addr(struct audit_buffer *ab, __be32 addr, }
Didn't you get a build warning about these functions being declared but not used? Maybe that doesn't happen with inlines? Are they used? Shouldn't these be removed as well? Are their others?
-Eric
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/1 SELinux: Convert avc_audit to use lsm_audit.h
Convert avc_audit in security/selinux/avc.c to use lsm_audit.h, for better maintainability and for less code duplication.
- changed selinux to use common_audit_data instead of avc_audit_data
- eliminated code in avc.c and used code from lsm_audit.h instead.
I have tested to make sure that the avcs look the same before and after this patch.
---
This patch depends on my earlier set of 3 (moving of function, making lsm_priv anonymous, ifdefs)
security/Makefile | 4 - security/selinux/avc.c | 218 ++++++++--------------------------- security/selinux/hooks.c | 142 +++++++++++------------ security/selinux/include/avc.h | 49 +------- security/selinux/include/netlabel.h | 4 - security/selinux/include/xfrm.h | 8 + security/selinux/netlabel.c | 2 security/selinux/xfrm.c | 4 - 8 files changed, 134 insertions(+), 297 deletions(-)
security/Makefile +1 -3
@@ -16,9 +16,7 @@ obj-$(CONFIG_SECURITYFS) += inode.o # Must precede capability.o in order to stack properly. obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o -ifeq ($(CONFIG_AUDIT),y) -obj-$(CONFIG_SECURITY_SMACK) += lsm_audit.o -endif +obj-$(CONFIG_AUDIT) += lsm_audit.o obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
security/selinux/avc.c +48 -170
241 lines not on this page · raw message
security/selinux/hooks.c +71 -71
536 lines not on this page · raw message
security/selinux/include/avc.h +5 -44
73 lines not on this page · raw message
security/selinux/include/netlabel.h +2 -2
@@ -59,7 +59,7 @@ int selinux_netlbl_socket_post_create(struct sock *sk, u16 family);int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb,u16 family, -struct avc_audit_data *ad); +struct common_audit_data *ad);int selinux_netlbl_socket_setsockopt (struct socket *sock,int level,int optname);
@@ -129,7 +129,7 @@ static inline int selinux_netlbl_socket_post_create(struct sock *sk,static inline int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb,u16 family, -struct avc_audit_data *ad) +struct common_audit_data *ad) {return 0 ; }
security/selinux/include/xfrm.h +4 -4
@@ -41,9 +41,9 @@ static inline int selinux_xfrm_enabled(void) }int selinux_xfrm_sock_rcv_skb (u32 sid,struct sk_buff *skb, -struct avc_audit_data *ad); +struct common_audit_data *ad);int selinux_xfrm_postroute_last (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad,u8 proto); +struct common_audit_data *ad,u8 proto);int selinux_xfrm_decode_session (struct sk_buff *skb,u32 *sid,int ckall);static inline void selinux_xfrm_notify_policyload (void )
@@ -57,13 +57,13 @@ static inline int selinux_xfrm_enabled(void) }static inline int selinux_xfrm_sock_rcv_skb (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad) +struct common_audit_data *ad) {return 0 ; }static inline int selinux_xfrm_postroute_last (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad,u8 proto) +struct common_audit_data *ad,u8 proto) {return 0 ; }
security/selinux/netlabel.c +1 -1
@@ -342,7 +342,7 @@ int selinux_netlbl_socket_post_create(struct sock *sk, u16 family)int selinux_netlbl_sock_rcv_skb (struct sk_security_struct *sksec,struct sk_buff *skb,u16 family, -struct avc_audit_data *ad) +struct common_audit_data *ad) {int rc;u32 nlbl_sid;
security/selinux/xfrm.c +2 -2
@@ -401,7 +401,7 @@ int selinux_xfrm_state_delete(struct xfrm_state *x)* gone thru the IPSec process. */ int selinux_xfrm_sock_rcv_skb (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad) +struct common_audit_data *ad) {int i, rc =0 ;struct sec_path *sp;
@@ -442,7 +442,7 @@ int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,* checked in the selinux_xfrm_state_pol_flow_match hook above. */ int selinux_xfrm_postroute_last (u32 isec_sid,struct sk_buff *skb, -struct avc_audit_data *ad,u8 proto) +struct common_audit_data *ad,u8 proto) {struct dst_entry *dst;int rc =0 ;
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH -v2] SELinux: Convert avc_audit to use lsm_audit.h
Quoted 11 lines · Thomas Liu
Convert
avc_auditinsecurity/selinux/avc.cto uselsm_audit.h, for better maintainability and for less code duplication.- changed selinux to use
common_audit_datainstead ofavc_audit_data
- eliminated code inavc.cand used code fromlsm_audit.hinstead.I have tested to make sure that the avcs look the same before and after this patch.
Signed-off-by Thomas Liu <[email protected]>
common_audit_data was a terrible structure name, I should have paid attention to that when it went into the kernel. Not your fault.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
James Morris
maintainerRe: [PATCH -v2] SELinux: Convert avc_audit to use lsm_audit.h
In reply to Thomas LiuQuoted 11 lines · Thomas Liu
Convert
avc_auditinsecurity/selinux/avc.cto uselsm_audit.h, for better maintainability and for less code duplication.- changed selinux to use
common_audit_datainstead ofavc_audit_data
- eliminated code inavc.cand used code fromlsm_audit.hinstead.I have tested to make sure that the avcs look the same before and after this patch.
Signed-off-by Thomas Liu <[email protected]>
Applied togit://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next
Signature · 7 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
James Morris
maintainerRe: [PATCH -v2] SELinux: Convert avc_audit to use lsm_audit.h
Quoted 9 lines · James Morris
Quoted 7 lines · Thomas Liu
Convert
avc_auditinsecurity/selinux/avc.cto uselsm_audit.h, for better maintainability and for less code duplication.- changed selinux to use
common_audit_datainstead ofavc_audit_data
- eliminated code inavc.cand used code fromlsm_audit.hinstead.
Quoted 8 lines
Quoted 4 lines
I have tested to make sure that the avcs look the same before and after this patch.
Signed-off-by Thomas Liu <[email protected]>Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next
I've had to revert this; it oopes my system during boot with what looks like a stack overflow (see below).
[ 0.026792] ACPI: Core revision 20090521 [ 0.035699] BUG: unable to handle kernel NULL pointer dereference at 0000000000000060 [ 0.035994] IP: [<ffffffff811918f8>] avc_audit+0x8/0x30 [ 0.035994] PGD 0 [ 0.035994] Thread overran stack, or stack corrupted [ 0.035994] Oops: 0002 [#1] PREEMPT SMP [ 0.035994] last sysfs file: [ 0.035994] CPU 0 [ 0.035994] Modules linked in: [ 0.035994] Pid: 0, comm: swapper Not tainted 2.6.31-rc1 #41 PowerEdge T105 [ 0.035994] RIP: 0010:[<ffffffff811918f8>] [<ffffffff811918f8>] avc_audit+0x8/0x30 [ 0.035994] RSP: 0018:ffffffff81675c38 EFLAGS: 00010292 [ 0.035994] RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000001 [ 0.035994] RDX: 0000000000000002 RSI: 0000000000000001 RDI: 0000000000000000 [ 0.035994] RBP: ffffffff81675c38 R08: ffffffff81675c68 R09: 0000000000000000 [ 0.035994] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000001 [ 0.035994] R13: 0000000000000001 R14: ffffffff81675c68 R15: 0000000000000002 [ 0.035994] FS: 0000000000000000(0000) GS:ffff880028054000(0000) knlGS:0000000000000000 [ 0.035994] CS: 0010 DS: 0018 ES: 0018 CR0: 000000008005003b [ 0.035994] CR2: 0000000000000060 CR3: 0000000001001000 CR4: 00000000000006f0 [ 0.035994] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 0.035994] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 [ 0.035994] Process swapper (pid: 0, threadinfo ffffffff81674000, task ffffffff815b8020) [ 0.035994] Stack: [ 0.035994] ffffffff81675cb8 ffffffff811922b2 0000000000000000 0000000000000000 [ 0.035994] <0> ffffffff81675c78 0000000000000000 00000000ffffffff 00000000ffffffff [ 0.035994] <0> ffffffff81675c88 ffffffff8107e61d ffffffff81675cb8 0000000000000001 [ 0.035994] Call Trace: [ 0.035994] [<ffffffff811922b2>] avc_has_perm+0x62/0x80 [ 0.035994] [<ffffffff8107e61d>] ? trace_hardirqs_on+0xd/0x10 [ 0.035994] [<ffffffff81194880>] current_has_perm+0x60/0x70 [ 0.035994] [<ffffffff81194947>] selinux_task_create+0x17/0x20 [ 0.035994] [<ffffffff8118d0b1>] security_task_create+0x11/0x20 [ 0.035994] [<ffffffff8104fdf1>] copy_process+0x71/0x15d0 [ 0.035994] [<ffffffff8107f8db>] ? __lock_acquire+0x3db/0x1af0 [ 0.035994] [<ffffffff810513d2>] do_fork+0x82/0x450 [ 0.035994] [<ffffffff813eb455>] ? _spin_unlock_irqrestore+0x65/0x80 [ 0.035994] [<ffffffff8107e5bd>] ? trace_hardirqs_on_caller+0x15d/0x1b0 [ 0.035994] [<ffffffff81014092>] kernel_thread+0x82/0xe0 [ 0.035994] [<ffffffff8167d5d0>] ? kernel_init+0x0/0x1c3 [ 0.035994] [<ffffffff810140f0>] ? child_rip+0x0/0x20 [ 0.035994] [<ffffffff813d51c7>] ? rest_init+0x17/0x80 [ 0.035994] [<ffffffff8167dd96>] start_kernel+0x3cd/0x3d8 [ 0.035994] [<ffffffff8167d33a>] x86_64_start_reservations+0x125/0x129 [ 0.035994] [<ffffffff8167d436>] x86_64_start_kernel+0xf8/0x107 [ 0.035994] Code: 00 00 f6 80 38 e0 ff ff 08 75 07 48 83 c4 08 5b c9 c3 e8 7c 72 25 00 eb f2 66 2e 0f 1f 84 00 00 00 00 00 55 48 89 e5 48 8b 7d 10 <4c> 89 47 60 66 89 57 50 89 4f 54 48 c7 47 70 20 19 19 81 48 c7 [ 0.035994] RIP [<ffffffff811918f8>] avc_audit+0x8/0x30 [ 0.035994] RSP <ffffffff81675c38> [ 0.035994] CR2: 0000000000000060 [ 0.036002] ---[ end trace 4eaa2a86a8e2da22 ]--- [ 0.037003] Kernel panic - not syncing: Attempted to kill the idle task! [ 0.038003] Pid: 0, comm: swapper Tainted: G D 2.6.31-rc1 #41 [ 0.039001] Call Trace: [ 0.040004] [<ffffffff813e7a07>] panic+0x7d/0x139 [ 0.041003] [<ffffffff810565ba>] do_exit+0x76a/0x800 [ 0.042003] [<ffffffff813ecd14>] oops_end+0xa4/0xf0 [ 0.043002] [<ffffffff81035dba>] no_context+0xea/0x260 [ 0.044003] [<ffffffff81036075>] __bad_area_nosemaphore+0x145/0x1f0 [ 0.044996] [<ffffffff8107f8db>] ? __lock_acquire+0x3db/0x1af0 [ 0.045996] [<ffffffff8107f8db>] ? __lock_acquire+0x3db/0x1af0 [ 0.047003] [<ffffffff81101505>] ? kmem_cache_alloc+0xf5/0x1c0 [ 0.048002] [<ffffffff8107e5bd>] ? trace_hardirqs_on_caller+0x15d/0x1b0 [ 0.049001] [<ffffffff813ee861>] ? do_page_fault+0x221/0x3a0 [ 0.049996] [<ffffffff8103612e>] bad_area_nosemaphore+0xe/0x10 [ 0.050995] [<ffffffff813ee927>] do_page_fault+0x2e7/0x3a0 [ 0.052002] [<ffffffff813ebef5>] page_fault+0x25/0x30 [ 0.052995] [<ffffffff811918f8>] ? avc_audit+0x8/0x30 [ 0.053995] [<ffffffff811922b2>] avc_has_perm+0x62/0x80 [ 0.054995] [<ffffffff8107e61d>] ? trace_hardirqs_on+0xd/0x10 [ 0.056001] [<ffffffff81194880>] current_has_perm+0x60/0x70 [ 0.056995] [<ffffffff81194947>] selinux_task_create+0x17/0x20 [ 0.057994] [<ffffffff8118d0b1>] security_task_create+0x11/0x20 [ 0.058994] [<ffffffff8104fdf1>] copy_process+0x71/0x15d0 [ 0.060000] [<ffffffff8107f8db>] ? __lock_acquire+0x3db/0x1af0 [ 0.060994] [<ffffffff810513d2>] do_fork+0x82/0x450 [ 0.061994] [<ffffffff813eb455>] ? _spin_unlock_irqrestore+0x65/0x80 [ 0.062994] [<ffffffff8107e5bd>] ? trace_hardirqs_on_caller+0x15d/0x1b0 [ 0.064000] [<ffffffff81014092>] kernel_thread+0x82/0xe0 [ 0.064994] [<ffffffff8167d5d0>] ? kernel_init+0x0/0x1c3 [ 0.065993] [<ffffffff810140f0>] ? child_rip+0x0/0x20 [ 0.066997] [<ffffffff813d51c7>] ? rest_init+0x17/0x80 [ 0.067999] [<ffffffff8167dd96>] start_kernel+0x3cd/0x3d8 [ 0.068993] [<ffffffff8167d33a>] x86_64_start_reservations+0x125/0x129 [ 0.069993] [<ffffffff8167d436>] x86_64_start_kernel+0xf8/0x107
Press any key to enter the menu
Signature · 7 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH -v2] SELinux: Convert avc_audit to use lsm_audit.h
In reply to Thomas LiuQuoted 19 lines · Thomas Liu
Convert
avc_auditinsecurity/selinux/avc.cto uselsm_audit.h, for better maintainability and for less code duplication.- changed selinux to use
common_audit_datainstead ofavc_audit_data
- eliminated code inavc.cand used code fromlsm_audit.hinstead.I have tested to make sure that the avcs look the same before and after this patch.
security/selinux/avc.c +0
-8-if (a->u.net.netif >0 ) { -struct net_device *dev; - -/* NOTE: we always use init's namespace */ - dev =dev_get_by_index (&init_net, - a->u.net.netif); -if (dev) { - audit_log_format(ab, " netif=%s",
security/selinux/avc.c static inline void avc_print_ipv4_addr(struct audit_buffer *ab, __be32 addr, · line 691
Quoted 10 lines
security/selinux/avc.c +0
-10- dev->name); -dev_put (dev); - } - } -break ; - } - } -audit_log_format (ab," " ); -avc_dump_query (ab, ssid, tsid, tclass); -audit_log_end (ab);
hmmmm, forgot ssid and tsid....
Although that doesn't give away the panic to me right offhand....
security/selinux/avc.c static inline void avc_print_ipv4_addr(struct audit_buffer *ab, __be32 addr, · line 570
Quoted 7 lines
security/selinux/avc.c +6
-0+ a->selinux_audit_data.avd = avd; + a->selinux_audit_data.tclass = tclass; + a->selinux_audit_data.requested = requested; + a->lsm_pre_audit = avc_audit_pre_callback; + a->lsm_post_audit = avc_audit_post_callback; +common_lsm_audit (a); }
Are you certain you tested this Tomas and weren't just running your old kernel both times?
-Eric
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.