blob: 646ad385e490432441514bfc818950822ce44631 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Matt Helsley9f460802005-11-07 00:59:16 -08002/*
3 * cn_proc.c - process events connector
4 *
5 * Copyright (C) Matt Helsley, IBM Corp. 2005
6 * Based on cn_fork.c by Guillaume Thouvenin <guillaume.thouvenin@bull.net>
7 * Original copyright notice follows:
8 * Copyright (C) 2005 BULL SA.
Matt Helsley9f460802005-11-07 00:59:16 -08009 */
10
Matt Helsley9f460802005-11-07 00:59:16 -080011#include <linux/kernel.h>
Matt Helsleycaf3c9d2006-01-09 20:52:40 -080012#include <linux/ktime.h>
Matt Helsley9f460802005-11-07 00:59:16 -080013#include <linux/init.h>
Matt Helsley1d31a4e2006-06-23 02:05:42 -070014#include <linux/connector.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +030016#include <linux/ptrace.h>
Arun Sharma600634972011-07-26 16:09:06 -070017#include <linux/atomic.h>
Eric W. Biederman9582d902012-02-07 16:48:16 -080018#include <linux/pid_namespace.h>
Arun Sharma600634972011-07-26 16:09:06 -070019
Matt Helsley9f460802005-11-07 00:59:16 -080020#include <linux/cn_proc.h>
Mike Galbraith3e92fd72020-05-27 22:11:17 +020021#include <linux/local_lock.h>
Matt Helsley9f460802005-11-07 00:59:16 -080022
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -050023/*
24 * Size of a cn_msg followed by a proc_event structure. Since the
25 * sizeof struct cn_msg is a multiple of 4 bytes, but not 8 bytes, we
26 * add one 4-byte word to the size here, and then start the actual
27 * cn_msg structure 4 bytes into the stack buffer. The result is that
28 * the immediately following proc_event structure is aligned to 8 bytes.
29 */
30#define CN_PROC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event) + 4)
31
32/* See comment above; we test our assumption about sizeof struct cn_msg here. */
33static inline struct cn_msg *buffer_to_cn_msg(__u8 *buffer)
34{
35 BUILD_BUG_ON(sizeof(struct cn_msg) != 20);
36 return (struct cn_msg *)(buffer + 4);
37}
Matt Helsley9f460802005-11-07 00:59:16 -080038
39static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
40static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
41
Mike Galbraith3e92fd72020-05-27 22:11:17 +020042/* local_event.count is used as the sequence number of the netlink message */
43struct local_event {
44 local_lock_t lock;
45 __u32 count;
46};
47static DEFINE_PER_CPU(struct local_event, local_event) = {
48 .lock = INIT_LOCAL_LOCK(lock),
49};
Matt Helsley9f460802005-11-07 00:59:16 -080050
Aaron Campbellab8ed952016-06-24 10:05:32 -030051static inline void send_msg(struct cn_msg *msg)
Matt Helsley9f460802005-11-07 00:59:16 -080052{
Mike Galbraith3e92fd72020-05-27 22:11:17 +020053 local_lock(&local_event.lock);
Aaron Campbellab8ed952016-06-24 10:05:32 -030054
Mike Galbraith3e92fd72020-05-27 22:11:17 +020055 msg->seq = __this_cpu_inc_return(local_event.count) - 1;
Aaron Campbellab8ed952016-06-24 10:05:32 -030056 ((struct proc_event *)msg->data)->cpu = smp_processor_id();
57
58 /*
Mike Galbraith3e92fd72020-05-27 22:11:17 +020059 * local_lock() disables preemption during send to ensure the messages
60 * are ordered according to their sequence numbers.
Aaron Campbellab8ed952016-06-24 10:05:32 -030061 *
62 * If cn_netlink_send() fails, the data is not sent.
63 */
64 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_NOWAIT);
65
Mike Galbraith3e92fd72020-05-27 22:11:17 +020066 local_unlock(&local_event.lock);
Matt Helsley9f460802005-11-07 00:59:16 -080067}
68
69void proc_fork_connector(struct task_struct *task)
70{
71 struct cn_msg *msg;
72 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -050073 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Oleg Nesterov9e8f90d2011-07-28 18:26:32 -070074 struct task_struct *parent;
Matt Helsley9f460802005-11-07 00:59:16 -080075
76 if (atomic_read(&proc_event_num_listeners) < 1)
77 return;
78
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -050079 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +000080 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +020081 memset(&ev->event_data, 0, sizeof(ev->event_data));
Thomas Gleixner9e93f212014-07-16 21:04:40 +000082 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -080083 ev->what = PROC_EVENT_FORK;
Oleg Nesterov9e8f90d2011-07-28 18:26:32 -070084 rcu_read_lock();
85 parent = rcu_dereference(task->real_parent);
86 ev->event_data.fork.parent_pid = parent->pid;
87 ev->event_data.fork.parent_tgid = parent->tgid;
88 rcu_read_unlock();
Matt Helsley9f460802005-11-07 00:59:16 -080089 ev->event_data.fork.child_pid = task->pid;
90 ev->event_data.fork.child_tgid = task->tgid;
91
92 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
93 msg->ack = 0; /* not used */
94 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +020095 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -030096 send_msg(msg);
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));
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000111 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800112 ev->what = PROC_EVENT_EXEC;
113 ev->event_data.exec.process_pid = task->pid;
114 ev->event_data.exec.process_tgid = task->tgid;
115
116 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
117 msg->ack = 0; /* not used */
118 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200119 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300120 send_msg(msg);
Matt Helsley9f460802005-11-07 00:59:16 -0800121}
122
123void proc_id_connector(struct task_struct *task, int which_id)
124{
125 struct cn_msg *msg;
126 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500127 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
David Howellsc69e8d92008-11-14 10:39:19 +1100128 const struct cred *cred;
Matt Helsley9f460802005-11-07 00:59:16 -0800129
130 if (atomic_read(&proc_event_num_listeners) < 1)
131 return;
132
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500133 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000134 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200135 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -0800136 ev->what = which_id;
137 ev->event_data.id.process_pid = task->pid;
138 ev->event_data.id.process_tgid = task->tgid;
David Howellsc69e8d92008-11-14 10:39:19 +1100139 rcu_read_lock();
140 cred = __task_cred(task);
Matt Helsley9f460802005-11-07 00:59:16 -0800141 if (which_id == PROC_EVENT_UID) {
Eric W. Biederman9582d902012-02-07 16:48:16 -0800142 ev->event_data.id.r.ruid = from_kuid_munged(&init_user_ns, cred->uid);
143 ev->event_data.id.e.euid = from_kuid_munged(&init_user_ns, cred->euid);
Matt Helsley9f460802005-11-07 00:59:16 -0800144 } else if (which_id == PROC_EVENT_GID) {
Eric W. Biederman9582d902012-02-07 16:48:16 -0800145 ev->event_data.id.r.rgid = from_kgid_munged(&init_user_ns, cred->gid);
146 ev->event_data.id.e.egid = from_kgid_munged(&init_user_ns, cred->egid);
David Howellsc69e8d92008-11-14 10:39:19 +1100147 } else {
148 rcu_read_unlock();
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000149 return;
David Howellsc69e8d92008-11-14 10:39:19 +1100150 }
151 rcu_read_unlock();
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000152 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800153
154 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
155 msg->ack = 0; /* not used */
156 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200157 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300158 send_msg(msg);
Matt Helsley9f460802005-11-07 00:59:16 -0800159}
160
Scott James Remnant02b51df2009-09-22 16:43:44 -0700161void proc_sid_connector(struct task_struct *task)
162{
163 struct cn_msg *msg;
164 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500165 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Scott James Remnant02b51df2009-09-22 16:43:44 -0700166
167 if (atomic_read(&proc_event_num_listeners) < 1)
168 return;
169
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500170 msg = buffer_to_cn_msg(buffer);
Scott James Remnant02b51df2009-09-22 16:43:44 -0700171 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200172 memset(&ev->event_data, 0, sizeof(ev->event_data));
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000173 ev->timestamp_ns = ktime_get_ns();
Scott James Remnant02b51df2009-09-22 16:43:44 -0700174 ev->what = PROC_EVENT_SID;
175 ev->event_data.sid.process_pid = task->pid;
176 ev->event_data.sid.process_tgid = task->tgid;
177
178 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
179 msg->ack = 0; /* not used */
180 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200181 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300182 send_msg(msg);
Scott James Remnant02b51df2009-09-22 16:43:44 -0700183}
184
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300185void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
186{
187 struct cn_msg *msg;
188 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500189 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300190
191 if (atomic_read(&proc_event_num_listeners) < 1)
192 return;
193
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500194 msg = buffer_to_cn_msg(buffer);
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300195 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200196 memset(&ev->event_data, 0, sizeof(ev->event_data));
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000197 ev->timestamp_ns = ktime_get_ns();
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300198 ev->what = PROC_EVENT_PTRACE;
199 ev->event_data.ptrace.process_pid = task->pid;
200 ev->event_data.ptrace.process_tgid = task->tgid;
201 if (ptrace_id == PTRACE_ATTACH) {
202 ev->event_data.ptrace.tracer_pid = current->pid;
203 ev->event_data.ptrace.tracer_tgid = current->tgid;
204 } else if (ptrace_id == PTRACE_DETACH) {
205 ev->event_data.ptrace.tracer_pid = 0;
206 ev->event_data.ptrace.tracer_tgid = 0;
207 } else
208 return;
209
210 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
211 msg->ack = 0; /* not used */
212 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200213 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300214 send_msg(msg);
Vladimir Zapolskiyf701e5b2011-07-15 20:45:18 +0300215}
216
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000217void proc_comm_connector(struct task_struct *task)
218{
219 struct cn_msg *msg;
220 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500221 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000222
223 if (atomic_read(&proc_event_num_listeners) < 1)
224 return;
225
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500226 msg = buffer_to_cn_msg(buffer);
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000227 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200228 memset(&ev->event_data, 0, sizeof(ev->event_data));
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000229 ev->timestamp_ns = ktime_get_ns();
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000230 ev->what = PROC_EVENT_COMM;
231 ev->event_data.comm.process_pid = task->pid;
232 ev->event_data.comm.process_tgid = task->tgid;
233 get_task_comm(ev->event_data.comm.comm, task);
234
235 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
236 msg->ack = 0; /* not used */
237 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200238 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300239 send_msg(msg);
Vladimir Zapolskiyf786ecb2011-09-21 09:26:44 +0000240}
241
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000242void proc_coredump_connector(struct task_struct *task)
243{
244 struct cn_msg *msg;
245 struct proc_event *ev;
Li RongQing6d2b0f02019-03-06 14:46:27 +0800246 struct task_struct *parent;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500247 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000248
249 if (atomic_read(&proc_event_num_listeners) < 1)
250 return;
251
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500252 msg = buffer_to_cn_msg(buffer);
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000253 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200254 memset(&ev->event_data, 0, sizeof(ev->event_data));
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000255 ev->timestamp_ns = ktime_get_ns();
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000256 ev->what = PROC_EVENT_COREDUMP;
257 ev->event_data.coredump.process_pid = task->pid;
258 ev->event_data.coredump.process_tgid = task->tgid;
Li RongQing6d2b0f02019-03-06 14:46:27 +0800259
260 rcu_read_lock();
261 if (pid_alive(task)) {
262 parent = rcu_dereference(task->real_parent);
263 ev->event_data.coredump.parent_pid = parent->pid;
264 ev->event_data.coredump.parent_tgid = parent->tgid;
265 }
266 rcu_read_unlock();
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000267
268 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
269 msg->ack = 0; /* not used */
270 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200271 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300272 send_msg(msg);
Jesper Derehag2b5faa42013-03-19 20:50:05 +0000273}
274
Matt Helsley9f460802005-11-07 00:59:16 -0800275void proc_exit_connector(struct task_struct *task)
276{
277 struct cn_msg *msg;
278 struct proc_event *ev;
Li RongQing6d2b0f02019-03-06 14:46:27 +0800279 struct task_struct *parent;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500280 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Matt Helsley9f460802005-11-07 00:59:16 -0800281
282 if (atomic_read(&proc_event_num_listeners) < 1)
283 return;
284
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500285 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000286 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200287 memset(&ev->event_data, 0, sizeof(ev->event_data));
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000288 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800289 ev->what = PROC_EVENT_EXIT;
290 ev->event_data.exit.process_pid = task->pid;
291 ev->event_data.exit.process_tgid = task->tgid;
292 ev->event_data.exit.exit_code = task->exit_code;
293 ev->event_data.exit.exit_signal = task->exit_signal;
Li RongQing6d2b0f02019-03-06 14:46:27 +0800294
295 rcu_read_lock();
296 if (pid_alive(task)) {
297 parent = rcu_dereference(task->real_parent);
298 ev->event_data.exit.parent_pid = parent->pid;
299 ev->event_data.exit.parent_tgid = parent->tgid;
300 }
301 rcu_read_unlock();
Matt Helsley9f460802005-11-07 00:59:16 -0800302
303 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
304 msg->ack = 0; /* not used */
305 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200306 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300307 send_msg(msg);
Matt Helsley9f460802005-11-07 00:59:16 -0800308}
309
310/*
311 * Send an acknowledgement message to userspace
312 *
313 * Use 0 for success, EFOO otherwise.
314 * Note: this is the negative of conventional kernel error
315 * values because it's not being returned via syscall return
316 * mechanisms.
317 */
318static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
319{
320 struct cn_msg *msg;
321 struct proc_event *ev;
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500322 __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
Matt Helsley9f460802005-11-07 00:59:16 -0800323
324 if (atomic_read(&proc_event_num_listeners) < 1)
325 return;
326
Chris Metcalf1ca1a4c2013-11-14 12:09:21 -0500327 msg = buffer_to_cn_msg(buffer);
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000328 ev = (struct proc_event *)msg->data;
Mathias Krausee727ca82013-09-30 22:03:06 +0200329 memset(&ev->event_data, 0, sizeof(ev->event_data));
Matt Helsley9f460802005-11-07 00:59:16 -0800330 msg->seq = rcvd_seq;
Thomas Gleixner9e93f212014-07-16 21:04:40 +0000331 ev->timestamp_ns = ktime_get_ns();
Matt Helsley9f460802005-11-07 00:59:16 -0800332 ev->cpu = -1;
333 ev->what = PROC_EVENT_NONE;
334 ev->event_data.ack.err = err;
335 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
336 msg->ack = rcvd_ack + 1;
337 msg->len = sizeof(*ev);
Mathias Krausee727ca82013-09-30 22:03:06 +0200338 msg->flags = 0; /* not used */
Aaron Campbellab8ed952016-06-24 10:05:32 -0300339 send_msg(msg);
Matt Helsley9f460802005-11-07 00:59:16 -0800340}
341
342/**
343 * cn_proc_mcast_ctl
344 * @data: message sent from userspace via the connector
345 */
Stephen Boydf0b25932009-10-06 01:39:51 -0700346static void cn_proc_mcast_ctl(struct cn_msg *msg,
347 struct netlink_skb_parms *nsp)
Matt Helsley9f460802005-11-07 00:59:16 -0800348{
Matt Helsley9f460802005-11-07 00:59:16 -0800349 enum proc_cn_mcast_op *mc_op = NULL;
350 int err = 0;
351
352 if (msg->len != sizeof(*mc_op))
353 return;
354
Eric W. Biederman9582d902012-02-07 16:48:16 -0800355 /*
356 * Events are reported with respect to the initial pid
357 * and user namespaces so ignore requestors from
358 * other namespaces.
359 */
360 if ((current_user_ns() != &init_user_ns) ||
361 (task_active_pid_ns(current) != &init_pid_ns))
362 return;
363
Kees Cooke70ab972013-02-25 21:32:25 +0000364 /* Can only change if privileged. */
Eric W. Biederman90f62cf2014-04-23 14:29:27 -0700365 if (!__netlink_ns_capable(nsp, &init_user_ns, CAP_NET_ADMIN)) {
Kees Cooke70ab972013-02-25 21:32:25 +0000366 err = EPERM;
367 goto out;
368 }
369
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000370 mc_op = (enum proc_cn_mcast_op *)msg->data;
Matt Helsley9f460802005-11-07 00:59:16 -0800371 switch (*mc_op) {
372 case PROC_CN_MCAST_LISTEN:
373 atomic_inc(&proc_event_num_listeners);
374 break;
375 case PROC_CN_MCAST_IGNORE:
376 atomic_dec(&proc_event_num_listeners);
377 break;
378 default:
379 err = EINVAL;
380 break;
381 }
Kees Cooke70ab972013-02-25 21:32:25 +0000382
383out:
Matt Helsley9f460802005-11-07 00:59:16 -0800384 cn_proc_ack(err, msg->seq, msg->ack);
385}
386
387/*
388 * cn_proc_init - initialization entry point
389 *
390 * Adds the connector callback to the connector driver.
391 */
392static int __init cn_proc_init(void)
393{
Valentin Ilief3c48ec2012-07-14 13:08:29 +0000394 int err = cn_add_callback(&cn_proc_event_id,
395 "cn_proc",
396 &cn_proc_mcast_ctl);
397 if (err) {
398 pr_warn("cn_proc failed to register\n");
Matt Helsley9f460802005-11-07 00:59:16 -0800399 return err;
400 }
401 return 0;
402}
Paul Gortmaker8297f2d2016-07-04 17:50:58 -0400403device_initcall(cn_proc_init);