spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / security / selinux / netlink.c
blob161e01a6c7eff099c166cbc919723fd0ab5e6982
1 /*
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/netlink.h>
20 #include <linux/selinux_netlink.h>
21 #include <net/net_namespace.h>
23 #include "security.h"
25 static struct sock *selnl;
27 static int selnl_msglen(int msgtype)
29 int ret = 0;
31 switch (msgtype) {
32 case SELNL_MSG_SETENFORCE:
33 ret = sizeof(struct selnl_msg_setenforce);
34 break;
36 case SELNL_MSG_POLICYLOAD:
37 ret = sizeof(struct selnl_msg_policyload);
38 break;
40 default:
41 BUG();
43 return ret;
46 static void selnl_add_payload(struct nlmsghdr *nlh, int len, int msgtype, void *data)
48 switch (msgtype) {
49 case SELNL_MSG_SETENFORCE: {
50 struct selnl_msg_setenforce *msg = NLMSG_DATA(nlh);
52 memset(msg, 0, len);
53 msg->val = *((int *)data);
54 break;
57 case SELNL_MSG_POLICYLOAD: {
58 struct selnl_msg_policyload *msg = NLMSG_DATA(nlh);
60 memset(msg, 0, len);
61 msg->seqno = *((u32 *)data);
62 break;
65 default:
66 BUG();
70 static void selnl_notify(int msgtype, void *data)
72 int len;
73 sk_buff_data_t tmp;
74 struct sk_buff *skb;
75 struct nlmsghdr *nlh;
77 len = selnl_msglen(msgtype);
79 skb = alloc_skb(NLMSG_SPACE(len), GFP_USER);
80 if (!skb)
81 goto oom;
83 tmp = skb->tail;
84 nlh = NLMSG_PUT(skb, 0, 0, msgtype, len);
85 selnl_add_payload(nlh, len, msgtype, data);
86 nlh->nlmsg_len = skb->tail - tmp;
87 NETLINK_CB(skb).dst_group = SELNLGRP_AVC;
88 netlink_broadcast(selnl, skb, 0, SELNLGRP_AVC, GFP_USER);
89 out:
90 return;
92 nlmsg_failure:
93 kfree_skb(skb);
94 oom:
95 printk(KERN_ERR "SELinux: OOM in %s\n", __func__);
96 goto out;
99 void selnl_notify_setenforce(int val)
101 selnl_notify(SELNL_MSG_SETENFORCE, &val);
104 void selnl_notify_policyload(u32 seqno)
106 selnl_notify(SELNL_MSG_POLICYLOAD, &seqno);
109 static int __init selnl_init(void)
111 selnl = netlink_kernel_create(&init_net, NETLINK_SELINUX,
112 SELNLGRP_MAX, NULL, NULL, THIS_MODULE);
113 if (selnl == NULL)
114 panic("SELinux: Cannot create netlink socket.");
115 netlink_set_nonroot(NETLINK_SELINUX, NL_NONROOT_RECV);
116 return 0;
119 __initcall(selnl_init);