blob: 15d06fcf0b500c323e938c08de5947e394121cb9 [file] [log] [blame]
Matt Helsley9f460802005-11-07 00:59:16 -08001/*
2 * cn_proc.c - process events connector
3 *
4 * Copyright (C) Matt Helsley, IBM Corp. 2005
5 * Based on cn_fork.c by Guillaume Thouvenin <guillaume.thouvenin@bull.net>
6 * Original copyright notice follows:
7 * Copyright (C) 2005 BULL SA.
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/module.h>
26#include <linux/kernel.h>
Matt Helsleycaf3c9d2006-01-09 20:52:40 -080027#include <linux/ktime.h>
Matt Helsley9f460802005-11-07 00:59:16 -080028#include <linux/init.h>
Matt Helsley1d31a4e2006-06-23 02:05:42 -070029#include <linux/connector.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/gfp.h>
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +030031#include <linux/ptrace.h>
Arun Sharma600634972011-07-26 16:09:06 -070032#include <linux/atomic.h>
Eric W. Biederman9582d902012-02-07 16:48:16 -080033#include <linux/pid_namespace.h>
Arun Sharma600634972011-07-26 16:09:06 -070034
Matt Helsley9f460802005-11-07 00:59:16 -080035#include <linux/cn_proc.h>
36
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -050037/*
38 * Size of a cn_msg followed by a proc_event structure. Since the
39 * sizeof struct cn_msg is a multiple of 4 bytes, but not 8 bytes, we
40 * add one 4-byte word to the size here, and then start the actual
41 * cn_msg structure 4 bytes into the stack buffer. The result is that
42 * the immediately following proc_event structure is aligned to 8 bytes.
43 */
44#define CN_PROC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event) + 4)
45
46/* See comment above; we test our assumption about sizeof struct cn_msg here. */
47static inline struct cn_msg *buffer_to_cn_msg(__u8 *buffer)
48{
49 BUILD_BUG_ON(sizeof(struct cn_msg) != 20);
50 return (struct cn_msg *)(buffer + 4);
51}
Matt Helsley9f460802005-11-07 00:59:16 -080052
53static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
54static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
55
David S. Millercc398c22006-01-08 01:03:34 -080056/* proc_event_counts is used as the sequence number of the netlink message */
Matt Helsley9f460802005-11-07 00:59:16 -080057static DEFINE_PER_CPU(__u32, proc_event_counts) = { 0 };
58
59static inline void get_seq(__u32 *ts, int *cpu)
60{
Christoph Lameter3ea9f682010-12-08 17:42:23 +010061 preempt_disable();
Valentin Ilief3c48ec2012-07-14 13:08:29 +000062 *ts = __this_cpu_inc_return(proc_event_counts) - 1;
Matt Helsley9f460802005-11-07 00:59:16 -080063 *cpu = smp_processor_id();
Christoph Lameter3ea9f682010-12-08 17:42:23 +010064 preempt_enable();
Matt Helsley9f460802005-11-07 00:59:16 -080065}
66
67void proc_fork_connector(struct task_struct *task)
68{
69 struct cn_msg *msg;
70 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -050071 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Oleg Nesterov9e8f90d2011-07-28 18:26:32 -070072 struct task_struct *parent;
Matt Helsley9f460802005-11-07 00:59:16 -080073
74 if (atomic_read(&proc_event_num_listeners) < 1)
75 return;
76
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -050077 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +000078 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +020079 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -080080 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +000081 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -080082 ev->what = PROC_EVENT_FORK;
Oleg Nesterov9e8f90d2011-07-28 18:26:32 -070083 rcu_read_lock();
84 parent = rcu_dereference(task->real_parent);
85 ev->event_data.fork.parent_pid = parent->pid;
86 ev->event_data.fork.parent_tgid = parent->tgid;
87 rcu_read_unlock();
Matt Helsley9f460802005-11-07 00:59:16 -080088 ev->event_data.fork.child_pid = task->pid;
89 ev->event_data.fork.child_tgid = task->tgid;
90
91 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
92 msg->ack = 0; /* not used */
93 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +020094 msg->flags = 0; /* not used */
Matt Helsley9f460802005-11-07 00:59:16 -080095 /* If cn_netlink_send() failed, the data is not sent */
David Friesac8f7332014-01-15 22:29:19 -060096 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Matt Helsley9f460802005-11-07 00:59:16 -080097}
98
99void proc_exec_connector(struct task_struct *task)
100{
101 struct cn_msg *msg;
102 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500103 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Matt Helsley9f460802005-11-07 00:59:16 -0800104
105 if (atomic_read(&proc_event_num_listeners) < 1)
106 return;
107
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500108 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000109 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200110 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -0800111 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000112 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800113 ev->what = PROC_EVENT_EXEC;
114 ev->event_data.exec.process_pid = task->pid;
115 ev->event_data.exec.process_tgid = task->tgid;
116
117 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
118 msg->ack = 0; /* not used */
119 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200120 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600121 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Matt Helsley9f460802005-11-07 00:59:16 -0800122}
123
124void proc_id_connector(struct task_struct *task, int which_id)
125{
126 struct cn_msg *msg;
127 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500128 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
David Howellsc69e8d92008-11-14 10:39:19 +1100129 const struct cred *cred;
Matt Helsley9f460802005-11-07 00:59:16 -0800130
131 if (atomic_read(&proc_event_num_listeners) < 1)
132 return;
133
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500134 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000135 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200136 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -0800137 ev->what = which_id;
138 ev->event_data.id.process_pid = task->pid;
139 ev->event_data.id.process_tgid = task->tgid;
David Howellsc69e8d92008-11-14 10:39:19 +1100140 rcu_read_lock();
141 cred = __task_cred(task);
Matt Helsley9f460802005-11-07 00:59:16 -0800142 if (which_id == PROC_EVENT_UID) {
Eric W. Biederman9582d902012-02-07 16:48:16 -0800143 ev->event_data.id.r.ruid = from_kuid_munged(&init_user_ns, cred->uid);
144 ev->event_data.id.e.euid = from_kuid_munged(&init_user_ns, cred->euid);
Matt Helsley9f460802005-11-07 00:59:16 -0800145 } else if (which_id == PROC_EVENT_GID) {
Eric W. Biederman9582d902012-02-07 16:48:16 -0800146 ev->event_data.id.r.rgid = from_kgid_munged(&init_user_ns, cred->gid);
147 ev->event_data.id.e.egid = from_kgid_munged(&init_user_ns, cred->egid);
David Howellsc69e8d92008-11-14 10:39:19 +1100148 } else {
149 rcu_read_unlock();
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000150 return;
David Howellsc69e8d92008-11-14 10:39:19 +1100151 }
152 rcu_read_unlock();
Matt Helsley9f460802005-11-07 00:59:16 -0800153 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000154 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800155
156 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
157 msg->ack = 0; /* not used */
158 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200159 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600160 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Matt Helsley9f460802005-11-07 00:59:16 -0800161}
162
Scott James Remnant02b51df2009-09-22 16:43:44 -0700163void proc_sid_connector(struct task_struct *task)
164{
165 struct cn_msg *msg;
166 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500167 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Scott James Remnant02b51df2009-09-22 16:43:44 -0700168
169 if (atomic_read(&proc_event_num_listeners) < 1)
170 return;
171
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500172 msg = buffer_to_cn_msg(buffer);
Scott James Remnant02b51df2009-09-22 16:43:44 -0700173 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200174 memset(&ev->event_data, 0, sizeof(ev->event_data));
Scott James Remnant02b51df2009-09-22 16:43:44 -0700175 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000176 ev->timestamp_ns = ktime_get_ns();
Scott James Remnant02b51df2009-09-22 16:43:44 -0700177 ev->what = PROC_EVENT_SID;
178 ev->event_data.sid.process_pid = task->pid;
179 ev->event_data.sid.process_tgid = task->tgid;
180
181 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
182 msg->ack = 0; /* not used */
183 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200184 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600185 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Scott James Remnant02b51df2009-09-22 16:43:44 -0700186}
187
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300188void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
189{
190 struct cn_msg *msg;
191 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500192 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300193
194 if (atomic_read(&proc_event_num_listeners) < 1)
195 return;
196
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500197 msg = buffer_to_cn_msg(buffer);
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300198 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200199 memset(&ev->event_data, 0, sizeof(ev->event_data));
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300200 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000201 ev->timestamp_ns = ktime_get_ns();
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300202 ev->what = PROC_EVENT_PTRACE;
203 ev->event_data.ptrace.process_pid = task->pid;
204 ev->event_data.ptrace.process_tgid = task->tgid;
205 if (ptrace_id == PTRACE_ATTACH) {
206 ev->event_data.ptrace.tracer_pid = current->pid;
207 ev->event_data.ptrace.tracer_tgid = current->tgid;
208 } else if (ptrace_id == PTRACE_DETACH) {
209 ev->event_data.ptrace.tracer_pid = 0;
210 ev->event_data.ptrace.tracer_tgid = 0;
211 } else
212 return;
213
214 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
215 msg->ack = 0; /* not used */
216 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200217 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600218 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300219}
220
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000221void proc_comm_connector(struct task_struct *task)
222{
223 struct cn_msg *msg;
224 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500225 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000226
227 if (atomic_read(&proc_event_num_listeners) < 1)
228 return;
229
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500230 msg = buffer_to_cn_msg(buffer);
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000231 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200232 memset(&ev->event_data, 0, sizeof(ev->event_data));
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000233 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000234 ev->timestamp_ns = ktime_get_ns();
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000235 ev->what = PROC_EVENT_COMM;
236 ev->event_data.comm.process_pid = task->pid;
237 ev->event_data.comm.process_tgid = task->tgid;
238 get_task_comm(ev->event_data.comm.comm, task);
239
240 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
241 msg->ack = 0; /* not used */
242 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200243 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600244 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000245}
246
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000247void proc_coredump_connector(struct task_struct *task)
248{
249 struct cn_msg *msg;
250 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500251 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000252
253 if (atomic_read(&proc_event_num_listeners) < 1)
254 return;
255
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500256 msg = buffer_to_cn_msg(buffer);
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000257 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200258 memset(&ev->event_data, 0, sizeof(ev->event_data));
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000259 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000260 ev->timestamp_ns = ktime_get_ns();
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000261 ev->what = PROC_EVENT_COREDUMP;
262 ev->event_data.coredump.process_pid = task->pid;
263 ev->event_data.coredump.process_tgid = task->tgid;
264
265 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
266 msg->ack = 0; /* not used */
267 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200268 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600269 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000270}
271
Matt Helsley9f460802005-11-07 00:59:16 -0800272void proc_exit_connector(struct task_struct *task)
273{
274 struct cn_msg *msg;
275 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500276 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Matt Helsley9f460802005-11-07 00:59:16 -0800277
278 if (atomic_read(&proc_event_num_listeners) < 1)
279 return;
280
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500281 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000282 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200283 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -0800284 get_seq(&msg->seq, &ev->cpu);
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000285 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800286 ev->what = PROC_EVENT_EXIT;
287 ev->event_data.exit.process_pid = task->pid;
288 ev->event_data.exit.process_tgid = task->tgid;
289 ev->event_data.exit.exit_code = task->exit_code;
290 ev->event_data.exit.exit_signal = task->exit_signal;
291
292 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
293 msg->ack = 0; /* not used */
294 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200295 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600296 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Matt Helsley9f460802005-11-07 00:59:16 -0800297}
298
299/*
300 * Send an acknowledgement message to userspace
301 *
302 * Use 0 for success, EFOO otherwise.
303 * Note: this is the negative of conventional kernel error
304 * values because it's not being returned via syscall return
305 * mechanisms.
306 */
307static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
308{
309 struct cn_msg *msg;
310 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500311 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Matt Helsley9f460802005-11-07 00:59:16 -0800312
313 if (atomic_read(&proc_event_num_listeners) < 1)
314 return;
315
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500316 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000317 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200318 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -0800319 msg->seq = rcvd_seq;
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000320 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800321 ev->cpu = -1;
322 ev->what = PROC_EVENT_NONE;
323 ev->event_data.ack.err = err;
324 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
325 msg->ack = rcvd_ack + 1;
326 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200327 msg->flags = 0; /* not used */
David Friesac8f7332014-01-15 22:29:19 -0600328 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL);
Matt Helsley9f460802005-11-07 00:59:16 -0800329}
330
331/**
332 * cn_proc_mcast_ctl
333 * @data: message sent from userspace via the connector
334 */
Stephen Boydf0b25932009-10-06 01:39:51 -0700335static void cn_proc_mcast_ctl(struct cn_msg *msg,
336 struct netlink_skb_parms *nsp)
Matt Helsley9f460802005-11-07 00:59:16 -0800337{
Matt Helsley9f460802005-11-07 00:59:16 -0800338 enum proc_cn_mcast_op *mc_op = NULL;
339 int err = 0;
340
341 if (msg->len != sizeof(*mc_op))
342 return;
343
Eric W. Biederman9582d902012-02-07 16:48:16 -0800344 /*
345 * Events are reported with respect to the initial pid
346 * and user namespaces so ignore requestors from
347 * other namespaces.
348 */
349 if ((current_user_ns() != &init_user_ns) ||
350 (task_active_pid_ns(current) != &init_pid_ns))
351 return;
352
Kees Cooke70ab972013-02-25 21:32:25 +0000353 /* Can only change if privileged. */
Eric W. Biederman90f62cf2014-04-23 14:29:27 -0700354 if (!__netlink_ns_capable(nsp, &init_user_ns, CAP_NET_ADMIN)) {
Kees Cooke70ab972013-02-25 21:32:25 +0000355 err = EPERM;
356 goto out;
357 }
358
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000359 mc_op = (enum proc_cn_mcast_op *)msg->data;
Matt Helsley9f460802005-11-07 00:59:16 -0800360 switch (*mc_op) {
361 case PROC_CN_MCAST_LISTEN:
362 atomic_inc(&proc_event_num_listeners);
363 break;
364 case PROC_CN_MCAST_IGNORE:
365 atomic_dec(&proc_event_num_listeners);
366 break;
367 default:
368 err = EINVAL;
369 break;
370 }
Kees Cooke70ab972013-02-25 21:32:25 +0000371
372out:
Matt Helsley9f460802005-11-07 00:59:16 -0800373 cn_proc_ack(err, msg->seq, msg->ack);
374}
375
376/*
377 * cn_proc_init - initialization entry point
378 *
379 * Adds the connector callback to the connector driver.
380 */
381static int __init cn_proc_init(void)
382{
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000383 int err = cn_add_callback(&cn_proc_event_id,
384 "cn_proc",
385 &cn_proc_mcast_ctl);
386 if (err) {
387 pr_warn("cn_proc failed to register\n");
Matt Helsley9f460802005-11-07 00:59:16 -0800388 return err;
389 }
390 return 0;
391}
392
393module_init(cn_proc_init);