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/export.h>
18 #include <linux/skbuff.h>
19 #include <linux/selinux_netlink.h>
20 #include <net/net_namespace.h>
21 #include <net/netlink.h>
25 static struct sock
*selnl
;
27 static int selnl_msglen(int msgtype
)
32 case SELNL_MSG_SETENFORCE
:
33 ret
= sizeof(struct selnl_msg_setenforce
);
36 case SELNL_MSG_POLICYLOAD
:
37 ret
= sizeof(struct selnl_msg_policyload
);
46 static void selnl_add_payload(struct nlmsghdr
*nlh
, int len
, int msgtype
, void *data
)
49 case SELNL_MSG_SETENFORCE
: {
50 struct selnl_msg_setenforce
*msg
= nlmsg_data(nlh
);
53 msg
->val
= *((int *)data
);
57 case SELNL_MSG_POLICYLOAD
: {
58 struct selnl_msg_policyload
*msg
= nlmsg_data(nlh
);
61 msg
->seqno
= *((u32
*)data
);
70 static void selnl_notify(int msgtype
, void *data
)
77 len
= selnl_msglen(msgtype
);
79 skb
= nlmsg_new(len
, GFP_USER
);
84 nlh
= nlmsg_put(skb
, 0, 0, msgtype
, len
, 0);
87 selnl_add_payload(nlh
, len
, msgtype
, data
);
88 nlh
->nlmsg_len
= skb
->tail
- tmp
;
89 NETLINK_CB(skb
).dst_group
= SELNLGRP_AVC
;
90 netlink_broadcast(selnl
, skb
, 0, SELNLGRP_AVC
, GFP_USER
);
97 printk(KERN_ERR
"SELinux: OOM in %s\n", __func__
);
101 void selnl_notify_setenforce(int val
)
103 selnl_notify(SELNL_MSG_SETENFORCE
, &val
);
106 void selnl_notify_policyload(u32 seqno
)
108 selnl_notify(SELNL_MSG_POLICYLOAD
, &seqno
);
111 static int __init
selnl_init(void)
113 struct netlink_kernel_cfg cfg
= {
114 .groups
= SELNLGRP_MAX
,
115 .flags
= NL_CFG_F_NONROOT_RECV
,
118 selnl
= netlink_kernel_create(&init_net
, NETLINK_SELINUX
, &cfg
);
120 panic("SELinux: Cannot create netlink socket.");
124 __initcall(selnl_init
);