2 * Netlink event notifications for SELinux.
4 * Author: James Morris <jmorris@redhat.com>
6 * Copyright (C) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/types.h>
14 #include <linux/slab.h>
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/skbuff.h>
18 #include <linux/netlink.h>
19 #include <linux/selinux_netlink.h>
20 #include <net/net_namespace.h>
24 static struct sock
*selnl
;
26 static int selnl_msglen(int msgtype
)
31 case SELNL_MSG_SETENFORCE
:
32 ret
= sizeof(struct selnl_msg_setenforce
);
35 case SELNL_MSG_POLICYLOAD
:
36 ret
= sizeof(struct selnl_msg_policyload
);
45 static void selnl_add_payload(struct nlmsghdr
*nlh
, int len
, int msgtype
, void *data
)
48 case SELNL_MSG_SETENFORCE
: {
49 struct selnl_msg_setenforce
*msg
= NLMSG_DATA(nlh
);
52 msg
->val
= *((int *)data
);
56 case SELNL_MSG_POLICYLOAD
: {
57 struct selnl_msg_policyload
*msg
= NLMSG_DATA(nlh
);
60 msg
->seqno
= *((u32
*)data
);
69 static void selnl_notify(int msgtype
, void *data
)
76 len
= selnl_msglen(msgtype
);
78 skb
= alloc_skb(NLMSG_SPACE(len
), GFP_USER
);
83 nlh
= NLMSG_PUT(skb
, 0, 0, msgtype
, len
);
84 selnl_add_payload(nlh
, len
, msgtype
, data
);
85 nlh
->nlmsg_len
= skb
->tail
- tmp
;
86 NETLINK_CB(skb
).dst_group
= SELNLGRP_AVC
;
87 netlink_broadcast(selnl
, skb
, 0, SELNLGRP_AVC
, GFP_USER
);
94 printk(KERN_ERR
"SELinux: OOM in %s\n", __func__
);
98 void selnl_notify_setenforce(int val
)
100 selnl_notify(SELNL_MSG_SETENFORCE
, &val
);
103 void selnl_notify_policyload(u32 seqno
)
105 selnl_notify(SELNL_MSG_POLICYLOAD
, &seqno
);
108 static int __init
selnl_init(void)
110 selnl
= netlink_kernel_create(&init_net
, NETLINK_SELINUX
,
111 SELNLGRP_MAX
, NULL
, NULL
, THIS_MODULE
);
113 panic("SELinux: Cannot create netlink socket.");
114 netlink_set_nonroot(NETLINK_SELINUX
, NL_NONROOT_RECV
);
118 __initcall(selnl_init
);