blob: 381eecffe516a42101c5b622fad4d92d07fab455 [file] [log] [blame]
Casey Schauflere114e472008-02-04 22:29:50 -08001/*
2 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 2.
7 *
8 * Authors:
9 * Casey Schaufler <casey@schaufler-ca.com>
10 * Ahmed S. Darwish <darwish.07@gmail.com>
11 *
12 * Special thanks to the authors of selinuxfs.
13 *
14 * Karl MacMillan <kmacmillan@tresys.com>
15 * James Morris <jmorris@redhat.com>
16 *
17 */
18
19#include <linux/kernel.h>
20#include <linux/vmalloc.h>
21#include <linux/security.h>
22#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Casey Schaufler6d3dc072008-12-31 12:54:12 -050024#include <net/net_namespace.h>
Casey Schauflere114e472008-02-04 22:29:50 -080025#include <net/netlabel.h>
26#include <net/cipso_ipv4.h>
27#include <linux/seq_file.h>
28#include <linux/ctype.h>
Casey Schaufler4bc87e62008-02-15 15:24:25 -080029#include <linux/audit.h>
Casey Schauflere114e472008-02-04 22:29:50 -080030#include "smack.h"
31
32/*
33 * smackfs pseudo filesystem.
34 */
35
36enum smk_inos {
37 SMK_ROOT_INO = 2,
38 SMK_LOAD = 3, /* load policy */
39 SMK_CIPSO = 4, /* load label -> CIPSO mapping */
40 SMK_DOI = 5, /* CIPSO DOI */
41 SMK_DIRECT = 6, /* CIPSO level indicating direct label */
42 SMK_AMBIENT = 7, /* internet ambient label */
Casey Schaufler6d3dc072008-12-31 12:54:12 -050043 SMK_NETLBLADDR = 8, /* single label hosts */
Casey Schaufler15446232008-07-30 15:37:11 -070044 SMK_ONLYCAP = 9, /* the only "capable" label */
Etienne Bassetecfcc532009-04-08 20:40:06 +020045 SMK_LOGGING = 10, /* logging */
Casey Schaufler7898e1f2011-01-17 08:05:27 -080046 SMK_LOAD_SELF = 11, /* task specific rules */
Jarkko Sakkinen828716c2011-09-08 10:12:01 +030047 SMK_ACCESSES = 12, /* access policy */
Casey Schauflere114e472008-02-04 22:29:50 -080048};
49
50/*
51 * List locks
52 */
53static DEFINE_MUTEX(smack_list_lock);
54static DEFINE_MUTEX(smack_cipso_lock);
Casey Schaufler4bc87e62008-02-15 15:24:25 -080055static DEFINE_MUTEX(smack_ambient_lock);
Casey Schaufler6d3dc072008-12-31 12:54:12 -050056static DEFINE_MUTEX(smk_netlbladdr_lock);
Casey Schauflere114e472008-02-04 22:29:50 -080057
58/*
59 * This is the "ambient" label for network traffic.
60 * If it isn't somehow marked, use this.
61 * It can be reset via smackfs/ambient
62 */
63char *smack_net_ambient = smack_known_floor.smk_known;
64
65/*
Casey Schauflere114e472008-02-04 22:29:50 -080066 * This is the level in a CIPSO header that indicates a
67 * smack label is contained directly in the category set.
68 * It can be reset via smackfs/direct
69 */
70int smack_cipso_direct = SMACK_CIPSO_DIRECT_DEFAULT;
71
Casey Schaufler15446232008-07-30 15:37:11 -070072/*
73 * Unless a process is running with this label even
74 * having CAP_MAC_OVERRIDE isn't enough to grant
75 * privilege to violate MAC policy. If no label is
76 * designated (the NULL case) capabilities apply to
77 * everyone. It is expected that the hat (^) label
78 * will be used if any label is used.
79 */
80char *smack_onlycap;
81
Casey Schaufler6d3dc072008-12-31 12:54:12 -050082/*
83 * Certain IP addresses may be designated as single label hosts.
84 * Packets are sent there unlabeled, but only from tasks that
85 * can write to the specified label.
86 */
Etienne Basset7198e2e2009-03-24 20:53:24 +010087
88LIST_HEAD(smk_netlbladdr_list);
Casey Schaufler272cd7a2011-09-20 12:24:36 -070089
90/*
91 * Rule lists are maintained for each label.
92 * This master list is just for reading /smack/load.
93 */
94struct smack_master_list {
95 struct list_head list;
96 struct smack_rule *smk_rule;
97};
98
Etienne Basset7198e2e2009-03-24 20:53:24 +010099LIST_HEAD(smack_rule_list);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500100
Casey Schauflere114e472008-02-04 22:29:50 -0800101static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
Casey Schauflere114e472008-02-04 22:29:50 -0800102
Etienne Basset43031542009-03-27 17:11:01 -0400103const char *smack_cipso_option = SMACK_CIPSO_OPTION;
104
105
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700106#define SEQ_READ_FINISHED ((loff_t)-1)
Casey Schauflere114e472008-02-04 22:29:50 -0800107
108/*
Casey Schauflere114e472008-02-04 22:29:50 -0800109 * Values for parsing cipso rules
110 * SMK_DIGITLEN: Length of a digit field in a rule.
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700111 * SMK_CIPSOMIN: Minimum possible cipso rule length.
112 * SMK_CIPSOMAX: Maximum possible cipso rule length.
Casey Schauflere114e472008-02-04 22:29:50 -0800113 */
114#define SMK_DIGITLEN 4
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700115#define SMK_CIPSOMIN (SMK_LABELLEN + 2 * SMK_DIGITLEN)
116#define SMK_CIPSOMAX (SMK_CIPSOMIN + SMACK_CIPSO_MAXCATNUM * SMK_DIGITLEN)
117
118/*
119 * Values for parsing MAC rules
120 * SMK_ACCESS: Maximum possible combination of access permissions
121 * SMK_ACCESSLEN: Maximum length for a rule access field
122 * SMK_LOADLEN: Smack rule length
123 */
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200124#define SMK_OACCESS "rwxa"
125#define SMK_ACCESS "rwxat"
126#define SMK_OACCESSLEN (sizeof(SMK_OACCESS) - 1)
127#define SMK_ACCESSLEN (sizeof(SMK_ACCESS) - 1)
128#define SMK_OLOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_OACCESSLEN)
129#define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN)
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700130
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500131/**
132 * smk_netlabel_audit_set - fill a netlbl_audit struct
133 * @nap: structure to fill
134 */
135static void smk_netlabel_audit_set(struct netlbl_audit *nap)
136{
137 nap->loginuid = audit_get_loginuid(current);
138 nap->sessionid = audit_get_sessionid(current);
Casey Schaufler676dac42010-12-02 06:43:39 -0800139 nap->secid = smack_to_secid(smk_of_current());
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500140}
141
142/*
143 * Values for parsing single label host rules
144 * "1.2.3.4 X"
145 * "192.168.138.129/32 abcdefghijklmnopqrstuvw"
146 */
147#define SMK_NETLBLADDRMIN 9
148#define SMK_NETLBLADDRMAX 42
Casey Schauflere114e472008-02-04 22:29:50 -0800149
Casey Schauflere114e472008-02-04 22:29:50 -0800150/**
151 * smk_set_access - add a rule to the rule list
152 * @srp: the new rule to add
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800153 * @rule_list: the list of rules
154 * @rule_lock: the rule list lock
Casey Schauflere114e472008-02-04 22:29:50 -0800155 *
156 * Looks through the current subject/object/access list for
157 * the subject/object pair and replaces the access that was
158 * there. If the pair isn't found add it with the specified
159 * access.
Sergio Luis81ea7142008-12-22 01:16:15 -0300160 *
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800161 * Returns 1 if a rule was found to exist already, 0 if it is new
Sergio Luis81ea7142008-12-22 01:16:15 -0300162 * Returns 0 if nothing goes wrong or -ENOMEM if it fails
163 * during the allocation of the new pair to add.
Casey Schauflere114e472008-02-04 22:29:50 -0800164 */
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800165static int smk_set_access(struct smack_rule *srp, struct list_head *rule_list,
166 struct mutex *rule_lock)
Casey Schauflere114e472008-02-04 22:29:50 -0800167{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100168 struct smack_rule *sp;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800169 int found = 0;
Casey Schauflere114e472008-02-04 22:29:50 -0800170
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800171 mutex_lock(rule_lock);
172
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700173 /*
174 * Because the object label is less likely to match
175 * than the subject label check it first
176 */
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800177 list_for_each_entry_rcu(sp, rule_list, list) {
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700178 if (sp->smk_object == srp->smk_object &&
179 sp->smk_subject == srp->smk_subject) {
Etienne Basset7198e2e2009-03-24 20:53:24 +0100180 found = 1;
181 sp->smk_access = srp->smk_access;
Casey Schauflere114e472008-02-04 22:29:50 -0800182 break;
183 }
Casey Schauflere114e472008-02-04 22:29:50 -0800184 }
Etienne Basset7198e2e2009-03-24 20:53:24 +0100185 if (found == 0)
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800186 list_add_rcu(&srp->list, rule_list);
Casey Schauflere114e472008-02-04 22:29:50 -0800187
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800188 mutex_unlock(rule_lock);
Casey Schauflere114e472008-02-04 22:29:50 -0800189
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800190 return found;
Casey Schauflere114e472008-02-04 22:29:50 -0800191}
192
193/**
Jarkko Sakkinen828716c2011-09-08 10:12:01 +0300194 * smk_parse_rule - parse subject, object and access type
195 * @data: string to be parsed whose size is SMK_LOADLEN
196 * @rule: parsed entities are stored in here
197 */
198static int smk_parse_rule(const char *data, struct smack_rule *rule)
199{
200 rule->smk_subject = smk_import(data, 0);
201 if (rule->smk_subject == NULL)
202 return -1;
203
204 rule->smk_object = smk_import(data + SMK_LABELLEN, 0);
205 if (rule->smk_object == NULL)
206 return -1;
207
208 rule->smk_access = 0;
209
210 switch (data[SMK_LABELLEN + SMK_LABELLEN]) {
211 case '-':
212 break;
213 case 'r':
214 case 'R':
215 rule->smk_access |= MAY_READ;
216 break;
217 default:
218 return -1;
219 }
220
221 switch (data[SMK_LABELLEN + SMK_LABELLEN + 1]) {
222 case '-':
223 break;
224 case 'w':
225 case 'W':
226 rule->smk_access |= MAY_WRITE;
227 break;
228 default:
229 return -1;
230 }
231
232 switch (data[SMK_LABELLEN + SMK_LABELLEN + 2]) {
233 case '-':
234 break;
235 case 'x':
236 case 'X':
237 rule->smk_access |= MAY_EXEC;
238 break;
239 default:
240 return -1;
241 }
242
243 switch (data[SMK_LABELLEN + SMK_LABELLEN + 3]) {
244 case '-':
245 break;
246 case 'a':
247 case 'A':
248 rule->smk_access |= MAY_APPEND;
249 break;
250 default:
251 return -1;
252 }
253
254 switch (data[SMK_LABELLEN + SMK_LABELLEN + 4]) {
255 case '-':
256 break;
257 case 't':
258 case 'T':
259 rule->smk_access |= MAY_TRANSMUTE;
260 break;
261 default:
262 return -1;
263 }
264
265 return 0;
266}
267
268/**
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800269 * smk_write_load_list - write() for any /smack/load
Randy Dunlap251a2a92009-02-18 11:42:33 -0800270 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -0800271 * @buf: where to get the data from
272 * @count: bytes sent
273 * @ppos: where to start - must be 0
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800274 * @rule_list: the list of rules to write to
275 * @rule_lock: lock for the rule list
Casey Schauflere114e472008-02-04 22:29:50 -0800276 *
277 * Get one smack access rule from above.
278 * The format is exactly:
279 * char subject[SMK_LABELLEN]
280 * char object[SMK_LABELLEN]
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700281 * char access[SMK_ACCESSLEN]
Casey Schauflere114e472008-02-04 22:29:50 -0800282 *
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700283 * writes must be SMK_LABELLEN+SMK_LABELLEN+SMK_ACCESSLEN bytes.
Casey Schauflere114e472008-02-04 22:29:50 -0800284 */
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800285static ssize_t smk_write_load_list(struct file *file, const char __user *buf,
286 size_t count, loff_t *ppos,
287 struct list_head *rule_list,
288 struct mutex *rule_lock)
Casey Schauflere114e472008-02-04 22:29:50 -0800289{
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700290 struct smack_master_list *smlp;
291 struct smack_known *skp;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100292 struct smack_rule *rule;
Casey Schauflere114e472008-02-04 22:29:50 -0800293 char *data;
294 int rc = -EINVAL;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700295 int load = 0;
Casey Schauflere114e472008-02-04 22:29:50 -0800296
297 /*
Casey Schauflere114e472008-02-04 22:29:50 -0800298 * No partial writes.
299 * Enough data must be present.
300 */
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200301 if (*ppos != 0)
302 return -EINVAL;
303 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300304 * Minor hack for backward compatibility
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200305 */
306 if (count < (SMK_OLOADLEN) || count > SMK_LOADLEN)
Casey Schauflere114e472008-02-04 22:29:50 -0800307 return -EINVAL;
308
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200309 data = kzalloc(SMK_LOADLEN, GFP_KERNEL);
Casey Schauflere114e472008-02-04 22:29:50 -0800310 if (data == NULL)
311 return -ENOMEM;
312
313 if (copy_from_user(data, buf, count) != 0) {
314 rc = -EFAULT;
315 goto out;
316 }
317
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200318 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300319 * More on the minor hack for backward compatibility
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200320 */
321 if (count == (SMK_OLOADLEN))
322 data[SMK_OLOADLEN] = '-';
323
Etienne Basset7198e2e2009-03-24 20:53:24 +0100324 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
325 if (rule == NULL) {
326 rc = -ENOMEM;
Casey Schauflere114e472008-02-04 22:29:50 -0800327 goto out;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100328 }
Casey Schauflere114e472008-02-04 22:29:50 -0800329
Jarkko Sakkinen828716c2011-09-08 10:12:01 +0300330 if (smk_parse_rule(data, rule))
Etienne Basset7198e2e2009-03-24 20:53:24 +0100331 goto out_free_rule;
Casey Schauflere114e472008-02-04 22:29:50 -0800332
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700333 if (rule_list == NULL) {
334 load = 1;
335 skp = smk_find_entry(rule->smk_subject);
336 rule_list = &skp->smk_rules;
337 rule_lock = &skp->smk_rules_lock;
338 }
339
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800340 rc = count;
341 /*
342 * smk_set_access returns true if there was already a rule
343 * for the subject/object pair, and false if it was new.
344 */
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700345 if (!smk_set_access(rule, rule_list, rule_lock)) {
346 smlp = kzalloc(sizeof(*smlp), GFP_KERNEL);
347 if (smlp != NULL) {
348 smlp->smk_rule = rule;
349 list_add_rcu(&smlp->list, &smack_rule_list);
350 } else
351 rc = -ENOMEM;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800352 goto out;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700353 }
Casey Schauflere114e472008-02-04 22:29:50 -0800354
Etienne Basset7198e2e2009-03-24 20:53:24 +0100355out_free_rule:
356 kfree(rule);
Casey Schauflere114e472008-02-04 22:29:50 -0800357out:
358 kfree(data);
359 return rc;
360}
361
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800362
363/*
364 * Seq_file read operations for /smack/load
365 */
366
367static void *load_seq_start(struct seq_file *s, loff_t *pos)
368{
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700369 struct list_head *list;
370
371 /*
372 * This is 0 the first time through.
373 */
374 if (s->index == 0)
375 s->private = &smack_rule_list;
376
377 if (s->private == NULL)
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800378 return NULL;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700379
380 list = s->private;
381 if (list_empty(list))
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800382 return NULL;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700383
384 if (s->index == 0)
385 return list->next;
386 return list;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800387}
388
389static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
390{
391 struct list_head *list = v;
392
393 if (list_is_last(list, &smack_rule_list)) {
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700394 s->private = NULL;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800395 return NULL;
396 }
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700397 s->private = list->next;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800398 return list->next;
399}
400
401static int load_seq_show(struct seq_file *s, void *v)
402{
403 struct list_head *list = v;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700404 struct smack_master_list *smlp =
405 list_entry(list, struct smack_master_list, list);
406 struct smack_rule *srp = smlp->smk_rule;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800407
408 seq_printf(s, "%s %s", (char *)srp->smk_subject,
409 (char *)srp->smk_object);
410
411 seq_putc(s, ' ');
412
413 if (srp->smk_access & MAY_READ)
414 seq_putc(s, 'r');
415 if (srp->smk_access & MAY_WRITE)
416 seq_putc(s, 'w');
417 if (srp->smk_access & MAY_EXEC)
418 seq_putc(s, 'x');
419 if (srp->smk_access & MAY_APPEND)
420 seq_putc(s, 'a');
421 if (srp->smk_access & MAY_TRANSMUTE)
422 seq_putc(s, 't');
423 if (srp->smk_access == 0)
424 seq_putc(s, '-');
425
426 seq_putc(s, '\n');
427
428 return 0;
429}
430
431static void load_seq_stop(struct seq_file *s, void *v)
432{
433 /* No-op */
434}
435
436static const struct seq_operations load_seq_ops = {
437 .start = load_seq_start,
438 .next = load_seq_next,
439 .show = load_seq_show,
440 .stop = load_seq_stop,
441};
442
443/**
444 * smk_open_load - open() for /smack/load
445 * @inode: inode structure representing file
446 * @file: "load" file pointer
447 *
448 * For reading, use load_seq_* seq_file reading operations.
449 */
450static int smk_open_load(struct inode *inode, struct file *file)
451{
452 return seq_open(file, &load_seq_ops);
453}
454
455/**
456 * smk_write_load - write() for /smack/load
457 * @file: file pointer, not actually used
458 * @buf: where to get the data from
459 * @count: bytes sent
460 * @ppos: where to start - must be 0
461 *
462 */
463static ssize_t smk_write_load(struct file *file, const char __user *buf,
464 size_t count, loff_t *ppos)
465{
466
467 /*
468 * Must have privilege.
469 * No partial writes.
470 * Enough data must be present.
471 */
472 if (!capable(CAP_MAC_ADMIN))
473 return -EPERM;
474
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700475 return smk_write_load_list(file, buf, count, ppos, NULL, NULL);
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800476}
477
Casey Schauflere114e472008-02-04 22:29:50 -0800478static const struct file_operations smk_load_ops = {
479 .open = smk_open_load,
480 .read = seq_read,
481 .llseek = seq_lseek,
482 .write = smk_write_load,
Ahmed S. Darwishcb622bbb2008-03-24 12:29:49 -0700483 .release = seq_release,
Casey Schauflere114e472008-02-04 22:29:50 -0800484};
485
486/**
487 * smk_cipso_doi - initialize the CIPSO domain
488 */
Casey Schaufler30aa4fa2008-04-28 02:13:43 -0700489static void smk_cipso_doi(void)
Casey Schauflere114e472008-02-04 22:29:50 -0800490{
491 int rc;
492 struct cipso_v4_doi *doip;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500493 struct netlbl_audit nai;
Casey Schauflere114e472008-02-04 22:29:50 -0800494
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500495 smk_netlabel_audit_set(&nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800496
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500497 rc = netlbl_cfg_map_del(NULL, PF_INET, NULL, NULL, &nai);
Casey Schauflere114e472008-02-04 22:29:50 -0800498 if (rc != 0)
499 printk(KERN_WARNING "%s:%d remove rc = %d\n",
500 __func__, __LINE__, rc);
501
502 doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
503 if (doip == NULL)
504 panic("smack: Failed to initialize cipso DOI.\n");
505 doip->map.std = NULL;
506 doip->doi = smk_cipso_doi_value;
507 doip->type = CIPSO_V4_MAP_PASS;
508 doip->tags[0] = CIPSO_V4_TAG_RBITMAP;
509 for (rc = 1; rc < CIPSO_V4_TAG_MAXCNT; rc++)
510 doip->tags[rc] = CIPSO_V4_TAG_INVALID;
511
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500512 rc = netlbl_cfg_cipsov4_add(doip, &nai);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400513 if (rc != 0) {
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500514 printk(KERN_WARNING "%s:%d cipso add rc = %d\n",
Casey Schauflere114e472008-02-04 22:29:50 -0800515 __func__, __LINE__, rc);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400516 kfree(doip);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500517 return;
518 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500519 rc = netlbl_cfg_cipsov4_map_add(doip->doi, NULL, NULL, NULL, &nai);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500520 if (rc != 0) {
521 printk(KERN_WARNING "%s:%d map add rc = %d\n",
522 __func__, __LINE__, rc);
523 kfree(doip);
524 return;
Paul Mooreb1edeb12008-10-10 10:16:31 -0400525 }
Casey Schauflere114e472008-02-04 22:29:50 -0800526}
527
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800528/**
529 * smk_unlbl_ambient - initialize the unlabeled domain
Randy Dunlap251a2a92009-02-18 11:42:33 -0800530 * @oldambient: previous domain string
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800531 */
Casey Schaufler30aa4fa2008-04-28 02:13:43 -0700532static void smk_unlbl_ambient(char *oldambient)
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800533{
534 int rc;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500535 struct netlbl_audit nai;
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800536
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500537 smk_netlabel_audit_set(&nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800538
539 if (oldambient != NULL) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500540 rc = netlbl_cfg_map_del(oldambient, PF_INET, NULL, NULL, &nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800541 if (rc != 0)
542 printk(KERN_WARNING "%s:%d remove rc = %d\n",
543 __func__, __LINE__, rc);
544 }
545
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500546 rc = netlbl_cfg_unlbl_map_add(smack_net_ambient, PF_INET,
547 NULL, NULL, &nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800548 if (rc != 0)
549 printk(KERN_WARNING "%s:%d add rc = %d\n",
550 __func__, __LINE__, rc);
551}
552
Casey Schauflere114e472008-02-04 22:29:50 -0800553/*
554 * Seq_file read operations for /smack/cipso
555 */
556
557static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
558{
559 if (*pos == SEQ_READ_FINISHED)
560 return NULL;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100561 if (list_empty(&smack_known_list))
562 return NULL;
Casey Schauflere114e472008-02-04 22:29:50 -0800563
Etienne Basset7198e2e2009-03-24 20:53:24 +0100564 return smack_known_list.next;
Casey Schauflere114e472008-02-04 22:29:50 -0800565}
566
567static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
568{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100569 struct list_head *list = v;
Casey Schauflere114e472008-02-04 22:29:50 -0800570
571 /*
Etienne Basset7198e2e2009-03-24 20:53:24 +0100572 * labels with no associated cipso value wont be printed
573 * in cipso_seq_show
Casey Schauflere114e472008-02-04 22:29:50 -0800574 */
Etienne Basset7198e2e2009-03-24 20:53:24 +0100575 if (list_is_last(list, &smack_known_list)) {
Casey Schauflere114e472008-02-04 22:29:50 -0800576 *pos = SEQ_READ_FINISHED;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100577 return NULL;
578 }
Casey Schauflere114e472008-02-04 22:29:50 -0800579
Etienne Basset7198e2e2009-03-24 20:53:24 +0100580 return list->next;
Casey Schauflere114e472008-02-04 22:29:50 -0800581}
582
583/*
584 * Print cipso labels in format:
585 * label level[/cat[,cat]]
586 */
587static int cipso_seq_show(struct seq_file *s, void *v)
588{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100589 struct list_head *list = v;
590 struct smack_known *skp =
591 list_entry(list, struct smack_known, list);
Casey Schauflere114e472008-02-04 22:29:50 -0800592 struct smack_cipso *scp = skp->smk_cipso;
593 char *cbp;
594 char sep = '/';
595 int cat = 1;
596 int i;
597 unsigned char m;
598
599 if (scp == NULL)
600 return 0;
601
602 seq_printf(s, "%s %3d", (char *)&skp->smk_known, scp->smk_level);
603
604 cbp = scp->smk_catset;
605 for (i = 0; i < SMK_LABELLEN; i++)
606 for (m = 0x80; m != 0; m >>= 1) {
607 if (m & cbp[i]) {
608 seq_printf(s, "%c%d", sep, cat);
609 sep = ',';
610 }
611 cat++;
612 }
613
614 seq_putc(s, '\n');
615
616 return 0;
617}
618
619static void cipso_seq_stop(struct seq_file *s, void *v)
620{
621 /* No-op */
622}
623
James Morris88e9d342009-09-22 16:43:43 -0700624static const struct seq_operations cipso_seq_ops = {
Casey Schauflere114e472008-02-04 22:29:50 -0800625 .start = cipso_seq_start,
626 .stop = cipso_seq_stop,
627 .next = cipso_seq_next,
628 .show = cipso_seq_show,
629};
630
631/**
632 * smk_open_cipso - open() for /smack/cipso
633 * @inode: inode structure representing file
634 * @file: "cipso" file pointer
635 *
636 * Connect our cipso_seq_* operations with /smack/cipso
637 * file_operations
638 */
639static int smk_open_cipso(struct inode *inode, struct file *file)
640{
641 return seq_open(file, &cipso_seq_ops);
642}
643
644/**
645 * smk_write_cipso - write() for /smack/cipso
Randy Dunlap251a2a92009-02-18 11:42:33 -0800646 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -0800647 * @buf: where to get the data from
648 * @count: bytes sent
649 * @ppos: where to start
650 *
651 * Accepts only one cipso rule per write call.
652 * Returns number of bytes written or error code, as appropriate
653 */
654static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
655 size_t count, loff_t *ppos)
656{
657 struct smack_known *skp;
658 struct smack_cipso *scp = NULL;
659 char mapcatset[SMK_LABELLEN];
660 int maplevel;
661 int cat;
662 int catlen;
663 ssize_t rc = -EINVAL;
664 char *data = NULL;
665 char *rule;
666 int ret;
667 int i;
668
669 /*
670 * Must have privilege.
671 * No partial writes.
672 * Enough data must be present.
673 */
674 if (!capable(CAP_MAC_ADMIN))
675 return -EPERM;
676 if (*ppos != 0)
677 return -EINVAL;
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700678 if (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX)
Casey Schauflere114e472008-02-04 22:29:50 -0800679 return -EINVAL;
680
681 data = kzalloc(count + 1, GFP_KERNEL);
682 if (data == NULL)
683 return -ENOMEM;
684
685 if (copy_from_user(data, buf, count) != 0) {
686 rc = -EFAULT;
687 goto unlockedout;
688 }
689
Etienne Basset43031542009-03-27 17:11:01 -0400690 /* labels cannot begin with a '-' */
691 if (data[0] == '-') {
692 rc = -EINVAL;
693 goto unlockedout;
694 }
Casey Schauflere114e472008-02-04 22:29:50 -0800695 data[count] = '\0';
696 rule = data;
697 /*
698 * Only allow one writer at a time. Writes should be
699 * quite rare and small in any case.
700 */
701 mutex_lock(&smack_cipso_lock);
702
703 skp = smk_import_entry(rule, 0);
704 if (skp == NULL)
705 goto out;
706
Fernando Carrijoc19a28e2009-01-07 18:09:08 -0800707 rule += SMK_LABELLEN;
Casey Schauflere114e472008-02-04 22:29:50 -0800708 ret = sscanf(rule, "%d", &maplevel);
709 if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
710 goto out;
711
712 rule += SMK_DIGITLEN;
713 ret = sscanf(rule, "%d", &catlen);
714 if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
715 goto out;
716
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700717 if (count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
Casey Schauflere114e472008-02-04 22:29:50 -0800718 goto out;
719
720 memset(mapcatset, 0, sizeof(mapcatset));
721
722 for (i = 0; i < catlen; i++) {
723 rule += SMK_DIGITLEN;
724 ret = sscanf(rule, "%d", &cat);
725 if (ret != 1 || cat > SMACK_CIPSO_MAXCATVAL)
726 goto out;
727
728 smack_catset_bit(cat, mapcatset);
729 }
730
731 if (skp->smk_cipso == NULL) {
732 scp = kzalloc(sizeof(struct smack_cipso), GFP_KERNEL);
733 if (scp == NULL) {
734 rc = -ENOMEM;
735 goto out;
736 }
737 }
738
739 spin_lock_bh(&skp->smk_cipsolock);
740
741 if (scp == NULL)
742 scp = skp->smk_cipso;
743 else
744 skp->smk_cipso = scp;
745
746 scp->smk_level = maplevel;
747 memcpy(scp->smk_catset, mapcatset, sizeof(mapcatset));
748
749 spin_unlock_bh(&skp->smk_cipsolock);
750
751 rc = count;
752out:
753 mutex_unlock(&smack_cipso_lock);
754unlockedout:
755 kfree(data);
756 return rc;
757}
758
759static const struct file_operations smk_cipso_ops = {
760 .open = smk_open_cipso,
761 .read = seq_read,
762 .llseek = seq_lseek,
763 .write = smk_write_cipso,
764 .release = seq_release,
765};
766
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500767/*
768 * Seq_file read operations for /smack/netlabel
769 */
770
771static void *netlbladdr_seq_start(struct seq_file *s, loff_t *pos)
772{
773 if (*pos == SEQ_READ_FINISHED)
774 return NULL;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100775 if (list_empty(&smk_netlbladdr_list))
776 return NULL;
777 return smk_netlbladdr_list.next;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500778}
779
780static void *netlbladdr_seq_next(struct seq_file *s, void *v, loff_t *pos)
781{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100782 struct list_head *list = v;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500783
Etienne Basset7198e2e2009-03-24 20:53:24 +0100784 if (list_is_last(list, &smk_netlbladdr_list)) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500785 *pos = SEQ_READ_FINISHED;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100786 return NULL;
787 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500788
Etienne Basset7198e2e2009-03-24 20:53:24 +0100789 return list->next;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500790}
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500791#define BEBITS (sizeof(__be32) * 8)
792
793/*
794 * Print host/label pairs
795 */
796static int netlbladdr_seq_show(struct seq_file *s, void *v)
797{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100798 struct list_head *list = v;
799 struct smk_netlbladdr *skp =
800 list_entry(list, struct smk_netlbladdr, list);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500801 unsigned char *hp = (char *) &skp->smk_host.sin_addr.s_addr;
etienne113a0e42009-03-04 07:33:51 +0100802 int maskn;
803 u32 temp_mask = be32_to_cpu(skp->smk_mask.s_addr);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500804
etienne113a0e42009-03-04 07:33:51 +0100805 for (maskn = 0; temp_mask; temp_mask <<= 1, maskn++);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500806
807 seq_printf(s, "%u.%u.%u.%u/%d %s\n",
808 hp[0], hp[1], hp[2], hp[3], maskn, skp->smk_label);
809
810 return 0;
811}
812
813static void netlbladdr_seq_stop(struct seq_file *s, void *v)
814{
815 /* No-op */
816}
817
James Morris88e9d342009-09-22 16:43:43 -0700818static const struct seq_operations netlbladdr_seq_ops = {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500819 .start = netlbladdr_seq_start,
820 .stop = netlbladdr_seq_stop,
821 .next = netlbladdr_seq_next,
822 .show = netlbladdr_seq_show,
823};
824
825/**
826 * smk_open_netlbladdr - open() for /smack/netlabel
827 * @inode: inode structure representing file
828 * @file: "netlabel" file pointer
829 *
830 * Connect our netlbladdr_seq_* operations with /smack/netlabel
831 * file_operations
832 */
833static int smk_open_netlbladdr(struct inode *inode, struct file *file)
834{
835 return seq_open(file, &netlbladdr_seq_ops);
836}
837
838/**
etienne113a0e42009-03-04 07:33:51 +0100839 * smk_netlbladdr_insert
840 * @new : netlabel to insert
841 *
842 * This helper insert netlabel in the smack_netlbladdrs list
843 * sorted by netmask length (longest to smallest)
Etienne Basset7198e2e2009-03-24 20:53:24 +0100844 * locked by &smk_netlbladdr_lock in smk_write_netlbladdr
845 *
etienne113a0e42009-03-04 07:33:51 +0100846 */
847static void smk_netlbladdr_insert(struct smk_netlbladdr *new)
848{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100849 struct smk_netlbladdr *m, *m_next;
etienne113a0e42009-03-04 07:33:51 +0100850
Etienne Basset7198e2e2009-03-24 20:53:24 +0100851 if (list_empty(&smk_netlbladdr_list)) {
852 list_add_rcu(&new->list, &smk_netlbladdr_list);
etienne113a0e42009-03-04 07:33:51 +0100853 return;
854 }
855
Jiri Pirko05725f72009-04-14 20:17:16 +0200856 m = list_entry_rcu(smk_netlbladdr_list.next,
857 struct smk_netlbladdr, list);
Etienne Basset7198e2e2009-03-24 20:53:24 +0100858
etienne113a0e42009-03-04 07:33:51 +0100859 /* the comparison '>' is a bit hacky, but works */
Etienne Basset7198e2e2009-03-24 20:53:24 +0100860 if (new->smk_mask.s_addr > m->smk_mask.s_addr) {
861 list_add_rcu(&new->list, &smk_netlbladdr_list);
etienne113a0e42009-03-04 07:33:51 +0100862 return;
863 }
Etienne Basset7198e2e2009-03-24 20:53:24 +0100864
865 list_for_each_entry_rcu(m, &smk_netlbladdr_list, list) {
866 if (list_is_last(&m->list, &smk_netlbladdr_list)) {
867 list_add_rcu(&new->list, &m->list);
etienne113a0e42009-03-04 07:33:51 +0100868 return;
869 }
Jiri Pirko05725f72009-04-14 20:17:16 +0200870 m_next = list_entry_rcu(m->list.next,
871 struct smk_netlbladdr, list);
Etienne Basset7198e2e2009-03-24 20:53:24 +0100872 if (new->smk_mask.s_addr > m_next->smk_mask.s_addr) {
873 list_add_rcu(&new->list, &m->list);
etienne113a0e42009-03-04 07:33:51 +0100874 return;
875 }
876 }
877}
878
879
880/**
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500881 * smk_write_netlbladdr - write() for /smack/netlabel
Randy Dunlap251a2a92009-02-18 11:42:33 -0800882 * @file: file pointer, not actually used
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500883 * @buf: where to get the data from
884 * @count: bytes sent
885 * @ppos: where to start
886 *
887 * Accepts only one netlbladdr per write call.
888 * Returns number of bytes written or error code, as appropriate
889 */
890static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
891 size_t count, loff_t *ppos)
892{
893 struct smk_netlbladdr *skp;
894 struct sockaddr_in newname;
895 char smack[SMK_LABELLEN];
896 char *sp;
Roel Kluin6470c072009-05-21 18:42:54 +0200897 char data[SMK_NETLBLADDRMAX + 1];
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500898 char *host = (char *)&newname.sin_addr.s_addr;
899 int rc;
900 struct netlbl_audit audit_info;
901 struct in_addr mask;
902 unsigned int m;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100903 int found;
etienne113a0e42009-03-04 07:33:51 +0100904 u32 mask_bits = (1<<31);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500905 __be32 nsa;
etienne113a0e42009-03-04 07:33:51 +0100906 u32 temp_mask;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500907
908 /*
909 * Must have privilege.
910 * No partial writes.
911 * Enough data must be present.
912 * "<addr/mask, as a.b.c.d/e><space><label>"
913 * "<addr, as a.b.c.d><space><label>"
914 */
915 if (!capable(CAP_MAC_ADMIN))
916 return -EPERM;
917 if (*ppos != 0)
918 return -EINVAL;
919 if (count < SMK_NETLBLADDRMIN || count > SMK_NETLBLADDRMAX)
920 return -EINVAL;
921 if (copy_from_user(data, buf, count) != 0)
922 return -EFAULT;
923
924 data[count] = '\0';
925
926 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd/%d %s",
927 &host[0], &host[1], &host[2], &host[3], &m, smack);
928 if (rc != 6) {
929 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd %s",
930 &host[0], &host[1], &host[2], &host[3], smack);
931 if (rc != 5)
932 return -EINVAL;
933 m = BEBITS;
934 }
935 if (m > BEBITS)
936 return -EINVAL;
937
Etienne Basset43031542009-03-27 17:11:01 -0400938 /* if smack begins with '-', its an option, don't import it */
939 if (smack[0] != '-') {
940 sp = smk_import(smack, 0);
941 if (sp == NULL)
942 return -EINVAL;
943 } else {
944 /* check known options */
945 if (strcmp(smack, smack_cipso_option) == 0)
946 sp = (char *)smack_cipso_option;
947 else
948 return -EINVAL;
949 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500950
etienne113a0e42009-03-04 07:33:51 +0100951 for (temp_mask = 0; m > 0; m--) {
952 temp_mask |= mask_bits;
953 mask_bits >>= 1;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500954 }
etienne113a0e42009-03-04 07:33:51 +0100955 mask.s_addr = cpu_to_be32(temp_mask);
956
957 newname.sin_addr.s_addr &= mask.s_addr;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500958 /*
959 * Only allow one writer at a time. Writes should be
960 * quite rare and small in any case.
961 */
962 mutex_lock(&smk_netlbladdr_lock);
963
964 nsa = newname.sin_addr.s_addr;
etienne113a0e42009-03-04 07:33:51 +0100965 /* try to find if the prefix is already in the list */
Etienne Basset7198e2e2009-03-24 20:53:24 +0100966 found = 0;
967 list_for_each_entry_rcu(skp, &smk_netlbladdr_list, list) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500968 if (skp->smk_host.sin_addr.s_addr == nsa &&
Etienne Basset7198e2e2009-03-24 20:53:24 +0100969 skp->smk_mask.s_addr == mask.s_addr) {
970 found = 1;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500971 break;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100972 }
973 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500974 smk_netlabel_audit_set(&audit_info);
975
Etienne Basset7198e2e2009-03-24 20:53:24 +0100976 if (found == 0) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500977 skp = kzalloc(sizeof(*skp), GFP_KERNEL);
978 if (skp == NULL)
979 rc = -ENOMEM;
980 else {
981 rc = 0;
982 skp->smk_host.sin_addr.s_addr = newname.sin_addr.s_addr;
983 skp->smk_mask.s_addr = mask.s_addr;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500984 skp->smk_label = sp;
etienne113a0e42009-03-04 07:33:51 +0100985 smk_netlbladdr_insert(skp);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500986 }
987 } else {
Etienne Basset43031542009-03-27 17:11:01 -0400988 /* we delete the unlabeled entry, only if the previous label
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300989 * wasn't the special CIPSO option */
Etienne Basset43031542009-03-27 17:11:01 -0400990 if (skp->smk_label != smack_cipso_option)
991 rc = netlbl_cfg_unlbl_static_del(&init_net, NULL,
992 &skp->smk_host.sin_addr, &skp->smk_mask,
993 PF_INET, &audit_info);
994 else
995 rc = 0;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500996 skp->smk_label = sp;
997 }
998
999 /*
1000 * Now tell netlabel about the single label nature of
1001 * this host so that incoming packets get labeled.
Etienne Basset43031542009-03-27 17:11:01 -04001002 * but only if we didn't get the special CIPSO option
Casey Schaufler6d3dc072008-12-31 12:54:12 -05001003 */
Etienne Basset43031542009-03-27 17:11:01 -04001004 if (rc == 0 && sp != smack_cipso_option)
Casey Schaufler6d3dc072008-12-31 12:54:12 -05001005 rc = netlbl_cfg_unlbl_static_add(&init_net, NULL,
1006 &skp->smk_host.sin_addr, &skp->smk_mask, PF_INET,
1007 smack_to_secid(skp->smk_label), &audit_info);
1008
1009 if (rc == 0)
1010 rc = count;
1011
1012 mutex_unlock(&smk_netlbladdr_lock);
1013
1014 return rc;
1015}
1016
1017static const struct file_operations smk_netlbladdr_ops = {
1018 .open = smk_open_netlbladdr,
1019 .read = seq_read,
1020 .llseek = seq_lseek,
1021 .write = smk_write_netlbladdr,
1022 .release = seq_release,
1023};
1024
Casey Schauflere114e472008-02-04 22:29:50 -08001025/**
1026 * smk_read_doi - read() for /smack/doi
1027 * @filp: file pointer, not actually used
1028 * @buf: where to put the result
1029 * @count: maximum to send along
1030 * @ppos: where to start
1031 *
1032 * Returns number of bytes read or error code, as appropriate
1033 */
1034static ssize_t smk_read_doi(struct file *filp, char __user *buf,
1035 size_t count, loff_t *ppos)
1036{
1037 char temp[80];
1038 ssize_t rc;
1039
1040 if (*ppos != 0)
1041 return 0;
1042
1043 sprintf(temp, "%d", smk_cipso_doi_value);
1044 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1045
1046 return rc;
1047}
1048
1049/**
1050 * smk_write_doi - write() for /smack/doi
Randy Dunlap251a2a92009-02-18 11:42:33 -08001051 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -08001052 * @buf: where to get the data from
1053 * @count: bytes sent
1054 * @ppos: where to start
1055 *
1056 * Returns number of bytes written or error code, as appropriate
1057 */
1058static ssize_t smk_write_doi(struct file *file, const char __user *buf,
1059 size_t count, loff_t *ppos)
1060{
1061 char temp[80];
1062 int i;
1063
1064 if (!capable(CAP_MAC_ADMIN))
1065 return -EPERM;
1066
1067 if (count >= sizeof(temp) || count == 0)
1068 return -EINVAL;
1069
1070 if (copy_from_user(temp, buf, count) != 0)
1071 return -EFAULT;
1072
1073 temp[count] = '\0';
1074
1075 if (sscanf(temp, "%d", &i) != 1)
1076 return -EINVAL;
1077
1078 smk_cipso_doi_value = i;
1079
1080 smk_cipso_doi();
1081
1082 return count;
1083}
1084
1085static const struct file_operations smk_doi_ops = {
1086 .read = smk_read_doi,
1087 .write = smk_write_doi,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001088 .llseek = default_llseek,
Casey Schauflere114e472008-02-04 22:29:50 -08001089};
1090
1091/**
1092 * smk_read_direct - read() for /smack/direct
1093 * @filp: file pointer, not actually used
1094 * @buf: where to put the result
1095 * @count: maximum to send along
1096 * @ppos: where to start
1097 *
1098 * Returns number of bytes read or error code, as appropriate
1099 */
1100static ssize_t smk_read_direct(struct file *filp, char __user *buf,
1101 size_t count, loff_t *ppos)
1102{
1103 char temp[80];
1104 ssize_t rc;
1105
1106 if (*ppos != 0)
1107 return 0;
1108
1109 sprintf(temp, "%d", smack_cipso_direct);
1110 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1111
1112 return rc;
1113}
1114
1115/**
1116 * smk_write_direct - write() for /smack/direct
Randy Dunlap251a2a92009-02-18 11:42:33 -08001117 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -08001118 * @buf: where to get the data from
1119 * @count: bytes sent
1120 * @ppos: where to start
1121 *
1122 * Returns number of bytes written or error code, as appropriate
1123 */
1124static ssize_t smk_write_direct(struct file *file, const char __user *buf,
1125 size_t count, loff_t *ppos)
1126{
1127 char temp[80];
1128 int i;
1129
1130 if (!capable(CAP_MAC_ADMIN))
1131 return -EPERM;
1132
1133 if (count >= sizeof(temp) || count == 0)
1134 return -EINVAL;
1135
1136 if (copy_from_user(temp, buf, count) != 0)
1137 return -EFAULT;
1138
1139 temp[count] = '\0';
1140
1141 if (sscanf(temp, "%d", &i) != 1)
1142 return -EINVAL;
1143
1144 smack_cipso_direct = i;
1145
1146 return count;
1147}
1148
1149static const struct file_operations smk_direct_ops = {
1150 .read = smk_read_direct,
1151 .write = smk_write_direct,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001152 .llseek = default_llseek,
Casey Schauflere114e472008-02-04 22:29:50 -08001153};
1154
1155/**
1156 * smk_read_ambient - read() for /smack/ambient
1157 * @filp: file pointer, not actually used
1158 * @buf: where to put the result
1159 * @cn: maximum to send along
1160 * @ppos: where to start
1161 *
1162 * Returns number of bytes read or error code, as appropriate
1163 */
1164static ssize_t smk_read_ambient(struct file *filp, char __user *buf,
1165 size_t cn, loff_t *ppos)
1166{
1167 ssize_t rc;
Casey Schauflere114e472008-02-04 22:29:50 -08001168 int asize;
1169
1170 if (*ppos != 0)
1171 return 0;
1172 /*
1173 * Being careful to avoid a problem in the case where
1174 * smack_net_ambient gets changed in midstream.
Casey Schauflere114e472008-02-04 22:29:50 -08001175 */
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001176 mutex_lock(&smack_ambient_lock);
Casey Schauflere114e472008-02-04 22:29:50 -08001177
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001178 asize = strlen(smack_net_ambient) + 1;
Casey Schauflere114e472008-02-04 22:29:50 -08001179
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001180 if (cn >= asize)
1181 rc = simple_read_from_buffer(buf, cn, ppos,
1182 smack_net_ambient, asize);
1183 else
1184 rc = -EINVAL;
1185
1186 mutex_unlock(&smack_ambient_lock);
Casey Schauflere114e472008-02-04 22:29:50 -08001187
1188 return rc;
1189}
1190
1191/**
1192 * smk_write_ambient - write() for /smack/ambient
Randy Dunlap251a2a92009-02-18 11:42:33 -08001193 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -08001194 * @buf: where to get the data from
1195 * @count: bytes sent
1196 * @ppos: where to start
1197 *
1198 * Returns number of bytes written or error code, as appropriate
1199 */
1200static ssize_t smk_write_ambient(struct file *file, const char __user *buf,
1201 size_t count, loff_t *ppos)
1202{
1203 char in[SMK_LABELLEN];
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001204 char *oldambient;
Casey Schauflere114e472008-02-04 22:29:50 -08001205 char *smack;
1206
1207 if (!capable(CAP_MAC_ADMIN))
1208 return -EPERM;
1209
1210 if (count >= SMK_LABELLEN)
1211 return -EINVAL;
1212
1213 if (copy_from_user(in, buf, count) != 0)
1214 return -EFAULT;
1215
1216 smack = smk_import(in, count);
1217 if (smack == NULL)
1218 return -EINVAL;
1219
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001220 mutex_lock(&smack_ambient_lock);
1221
1222 oldambient = smack_net_ambient;
Casey Schauflere114e472008-02-04 22:29:50 -08001223 smack_net_ambient = smack;
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001224 smk_unlbl_ambient(oldambient);
1225
1226 mutex_unlock(&smack_ambient_lock);
Casey Schauflere114e472008-02-04 22:29:50 -08001227
1228 return count;
1229}
1230
1231static const struct file_operations smk_ambient_ops = {
1232 .read = smk_read_ambient,
1233 .write = smk_write_ambient,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001234 .llseek = default_llseek,
Casey Schauflere114e472008-02-04 22:29:50 -08001235};
1236
Casey Schaufler15446232008-07-30 15:37:11 -07001237/**
1238 * smk_read_onlycap - read() for /smack/onlycap
1239 * @filp: file pointer, not actually used
1240 * @buf: where to put the result
1241 * @cn: maximum to send along
1242 * @ppos: where to start
1243 *
1244 * Returns number of bytes read or error code, as appropriate
1245 */
1246static ssize_t smk_read_onlycap(struct file *filp, char __user *buf,
1247 size_t cn, loff_t *ppos)
1248{
1249 char *smack = "";
1250 ssize_t rc = -EINVAL;
1251 int asize;
1252
1253 if (*ppos != 0)
1254 return 0;
1255
1256 if (smack_onlycap != NULL)
1257 smack = smack_onlycap;
1258
1259 asize = strlen(smack) + 1;
1260
1261 if (cn >= asize)
1262 rc = simple_read_from_buffer(buf, cn, ppos, smack, asize);
1263
1264 return rc;
1265}
1266
1267/**
1268 * smk_write_onlycap - write() for /smack/onlycap
Randy Dunlap251a2a92009-02-18 11:42:33 -08001269 * @file: file pointer, not actually used
Casey Schaufler15446232008-07-30 15:37:11 -07001270 * @buf: where to get the data from
1271 * @count: bytes sent
1272 * @ppos: where to start
1273 *
1274 * Returns number of bytes written or error code, as appropriate
1275 */
1276static ssize_t smk_write_onlycap(struct file *file, const char __user *buf,
1277 size_t count, loff_t *ppos)
1278{
1279 char in[SMK_LABELLEN];
Casey Schaufler676dac42010-12-02 06:43:39 -08001280 char *sp = smk_of_task(current->cred->security);
Casey Schaufler15446232008-07-30 15:37:11 -07001281
1282 if (!capable(CAP_MAC_ADMIN))
1283 return -EPERM;
1284
1285 /*
1286 * This can be done using smk_access() but is done
1287 * explicitly for clarity. The smk_access() implementation
1288 * would use smk_access(smack_onlycap, MAY_WRITE)
1289 */
1290 if (smack_onlycap != NULL && smack_onlycap != sp)
1291 return -EPERM;
1292
1293 if (count >= SMK_LABELLEN)
1294 return -EINVAL;
1295
1296 if (copy_from_user(in, buf, count) != 0)
1297 return -EFAULT;
1298
1299 /*
1300 * Should the null string be passed in unset the onlycap value.
1301 * This seems like something to be careful with as usually
1302 * smk_import only expects to return NULL for errors. It
1303 * is usually the case that a nullstring or "\n" would be
1304 * bad to pass to smk_import but in fact this is useful here.
1305 */
1306 smack_onlycap = smk_import(in, count);
1307
1308 return count;
1309}
1310
1311static const struct file_operations smk_onlycap_ops = {
1312 .read = smk_read_onlycap,
1313 .write = smk_write_onlycap,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001314 .llseek = default_llseek,
Casey Schaufler15446232008-07-30 15:37:11 -07001315};
1316
Casey Schauflere114e472008-02-04 22:29:50 -08001317/**
Etienne Bassetecfcc532009-04-08 20:40:06 +02001318 * smk_read_logging - read() for /smack/logging
1319 * @filp: file pointer, not actually used
1320 * @buf: where to put the result
1321 * @cn: maximum to send along
1322 * @ppos: where to start
1323 *
1324 * Returns number of bytes read or error code, as appropriate
1325 */
1326static ssize_t smk_read_logging(struct file *filp, char __user *buf,
1327 size_t count, loff_t *ppos)
1328{
1329 char temp[32];
1330 ssize_t rc;
1331
1332 if (*ppos != 0)
1333 return 0;
1334
1335 sprintf(temp, "%d\n", log_policy);
1336 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1337 return rc;
1338}
1339
1340/**
1341 * smk_write_logging - write() for /smack/logging
1342 * @file: file pointer, not actually used
1343 * @buf: where to get the data from
1344 * @count: bytes sent
1345 * @ppos: where to start
1346 *
1347 * Returns number of bytes written or error code, as appropriate
1348 */
1349static ssize_t smk_write_logging(struct file *file, const char __user *buf,
1350 size_t count, loff_t *ppos)
1351{
1352 char temp[32];
1353 int i;
1354
1355 if (!capable(CAP_MAC_ADMIN))
1356 return -EPERM;
1357
1358 if (count >= sizeof(temp) || count == 0)
1359 return -EINVAL;
1360
1361 if (copy_from_user(temp, buf, count) != 0)
1362 return -EFAULT;
1363
1364 temp[count] = '\0';
1365
1366 if (sscanf(temp, "%d", &i) != 1)
1367 return -EINVAL;
1368 if (i < 0 || i > 3)
1369 return -EINVAL;
1370 log_policy = i;
1371 return count;
1372}
1373
1374
1375
1376static const struct file_operations smk_logging_ops = {
1377 .read = smk_read_logging,
1378 .write = smk_write_logging,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001379 .llseek = default_llseek,
Etienne Bassetecfcc532009-04-08 20:40:06 +02001380};
Casey Schaufler7898e1f2011-01-17 08:05:27 -08001381
1382/*
1383 * Seq_file read operations for /smack/load-self
1384 */
1385
1386static void *load_self_seq_start(struct seq_file *s, loff_t *pos)
1387{
1388 struct task_smack *tsp = current_security();
1389
1390 if (*pos == SEQ_READ_FINISHED)
1391 return NULL;
1392 if (list_empty(&tsp->smk_rules))
1393 return NULL;
1394 return tsp->smk_rules.next;
1395}
1396
1397static void *load_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
1398{
1399 struct task_smack *tsp = current_security();
1400 struct list_head *list = v;
1401
1402 if (list_is_last(list, &tsp->smk_rules)) {
1403 *pos = SEQ_READ_FINISHED;
1404 return NULL;
1405 }
1406 return list->next;
1407}
1408
1409static int load_self_seq_show(struct seq_file *s, void *v)
1410{
1411 struct list_head *list = v;
1412 struct smack_rule *srp =
1413 list_entry(list, struct smack_rule, list);
1414
1415 seq_printf(s, "%s %s", (char *)srp->smk_subject,
1416 (char *)srp->smk_object);
1417
1418 seq_putc(s, ' ');
1419
1420 if (srp->smk_access & MAY_READ)
1421 seq_putc(s, 'r');
1422 if (srp->smk_access & MAY_WRITE)
1423 seq_putc(s, 'w');
1424 if (srp->smk_access & MAY_EXEC)
1425 seq_putc(s, 'x');
1426 if (srp->smk_access & MAY_APPEND)
1427 seq_putc(s, 'a');
1428 if (srp->smk_access & MAY_TRANSMUTE)
1429 seq_putc(s, 't');
1430 if (srp->smk_access == 0)
1431 seq_putc(s, '-');
1432
1433 seq_putc(s, '\n');
1434
1435 return 0;
1436}
1437
1438static void load_self_seq_stop(struct seq_file *s, void *v)
1439{
1440 /* No-op */
1441}
1442
1443static const struct seq_operations load_self_seq_ops = {
1444 .start = load_self_seq_start,
1445 .next = load_self_seq_next,
1446 .show = load_self_seq_show,
1447 .stop = load_self_seq_stop,
1448};
1449
1450
1451/**
1452 * smk_open_load_self - open() for /smack/load-self
1453 * @inode: inode structure representing file
1454 * @file: "load" file pointer
1455 *
1456 * For reading, use load_seq_* seq_file reading operations.
1457 */
1458static int smk_open_load_self(struct inode *inode, struct file *file)
1459{
1460 return seq_open(file, &load_self_seq_ops);
1461}
1462
1463/**
1464 * smk_write_load_self - write() for /smack/load-self
1465 * @file: file pointer, not actually used
1466 * @buf: where to get the data from
1467 * @count: bytes sent
1468 * @ppos: where to start - must be 0
1469 *
1470 */
1471static ssize_t smk_write_load_self(struct file *file, const char __user *buf,
1472 size_t count, loff_t *ppos)
1473{
1474 struct task_smack *tsp = current_security();
1475
1476 return smk_write_load_list(file, buf, count, ppos, &tsp->smk_rules,
1477 &tsp->smk_rules_lock);
1478}
1479
1480static const struct file_operations smk_load_self_ops = {
1481 .open = smk_open_load_self,
1482 .read = seq_read,
1483 .llseek = seq_lseek,
1484 .write = smk_write_load_self,
1485 .release = seq_release,
1486};
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001487
1488/**
1489 * smk_write_access - handle access check transaction
1490 * @file: file pointer
1491 * @buf: data from user space
1492 * @count: bytes sent
1493 * @ppos: where to start - must be 0
1494 */
1495static ssize_t smk_write_access(struct file *file, const char __user *buf,
1496 size_t count, loff_t *ppos)
1497{
1498 struct smack_rule rule;
1499 char *data;
Jarkko Sakkinenf8859d92011-10-10 14:29:28 +03001500 int res;
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001501
1502 if (!capable(CAP_MAC_ADMIN))
1503 return -EPERM;
1504
1505 data = simple_transaction_get(file, buf, count);
1506 if (IS_ERR(data))
1507 return PTR_ERR(data);
1508
1509 if (count < SMK_LOADLEN || smk_parse_rule(data, &rule))
1510 return -EINVAL;
1511
Jarkko Sakkinenf8859d92011-10-10 14:29:28 +03001512 res = smk_access(rule.smk_subject, rule.smk_object, rule.smk_access,
1513 NULL);
1514 data[0] = res == 0 ? '1' : '0';
1515 data[1] = '\0';
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001516
Jarkko Sakkinend86b2b62011-10-18 14:34:28 +03001517 simple_transaction_set(file, 2);
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001518 return SMK_LOADLEN;
1519}
1520
1521static const struct file_operations smk_access_ops = {
1522 .write = smk_write_access,
1523 .read = simple_transaction_read,
1524 .release = simple_transaction_release,
1525 .llseek = generic_file_llseek,
1526};
1527
Etienne Bassetecfcc532009-04-08 20:40:06 +02001528/**
Casey Schauflere114e472008-02-04 22:29:50 -08001529 * smk_fill_super - fill the /smackfs superblock
1530 * @sb: the empty superblock
1531 * @data: unused
1532 * @silent: unused
1533 *
1534 * Fill in the well known entries for /smack
1535 *
1536 * Returns 0 on success, an error code on failure
1537 */
1538static int smk_fill_super(struct super_block *sb, void *data, int silent)
1539{
1540 int rc;
1541 struct inode *root_inode;
1542
1543 static struct tree_descr smack_files[] = {
Casey Schaufler7898e1f2011-01-17 08:05:27 -08001544 [SMK_LOAD] = {
1545 "load", &smk_load_ops, S_IRUGO|S_IWUSR},
1546 [SMK_CIPSO] = {
1547 "cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
1548 [SMK_DOI] = {
1549 "doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
1550 [SMK_DIRECT] = {
1551 "direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
1552 [SMK_AMBIENT] = {
1553 "ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
1554 [SMK_NETLBLADDR] = {
1555 "netlabel", &smk_netlbladdr_ops, S_IRUGO|S_IWUSR},
1556 [SMK_ONLYCAP] = {
1557 "onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
1558 [SMK_LOGGING] = {
1559 "logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
1560 [SMK_LOAD_SELF] = {
1561 "load-self", &smk_load_self_ops, S_IRUGO|S_IWUGO},
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001562 [SMK_ACCESSES] = {
1563 "access", &smk_access_ops, S_IRUGO|S_IWUSR},
Casey Schaufler7898e1f2011-01-17 08:05:27 -08001564 /* last one */
1565 {""}
Casey Schauflere114e472008-02-04 22:29:50 -08001566 };
1567
1568 rc = simple_fill_super(sb, SMACK_MAGIC, smack_files);
1569 if (rc != 0) {
1570 printk(KERN_ERR "%s failed %d while creating inodes\n",
1571 __func__, rc);
1572 return rc;
1573 }
1574
1575 root_inode = sb->s_root->d_inode;
1576 root_inode->i_security = new_inode_smack(smack_known_floor.smk_known);
1577
1578 return 0;
1579}
1580
1581/**
Al Virofc14f2f2010-07-25 01:48:30 +04001582 * smk_mount - get the smackfs superblock
Casey Schauflere114e472008-02-04 22:29:50 -08001583 * @fs_type: passed along without comment
1584 * @flags: passed along without comment
1585 * @dev_name: passed along without comment
1586 * @data: passed along without comment
Casey Schauflere114e472008-02-04 22:29:50 -08001587 *
1588 * Just passes everything along.
1589 *
1590 * Returns what the lower level code does.
1591 */
Al Virofc14f2f2010-07-25 01:48:30 +04001592static struct dentry *smk_mount(struct file_system_type *fs_type,
1593 int flags, const char *dev_name, void *data)
Casey Schauflere114e472008-02-04 22:29:50 -08001594{
Al Virofc14f2f2010-07-25 01:48:30 +04001595 return mount_single(fs_type, flags, data, smk_fill_super);
Casey Schauflere114e472008-02-04 22:29:50 -08001596}
1597
1598static struct file_system_type smk_fs_type = {
1599 .name = "smackfs",
Al Virofc14f2f2010-07-25 01:48:30 +04001600 .mount = smk_mount,
Casey Schauflere114e472008-02-04 22:29:50 -08001601 .kill_sb = kill_litter_super,
1602};
1603
1604static struct vfsmount *smackfs_mount;
1605
1606/**
1607 * init_smk_fs - get the smackfs superblock
1608 *
1609 * register the smackfs
1610 *
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +02001611 * Do not register smackfs if Smack wasn't enabled
1612 * on boot. We can not put this method normally under the
1613 * smack_init() code path since the security subsystem get
1614 * initialized before the vfs caches.
1615 *
1616 * Returns true if we were not chosen on boot or if
1617 * we were chosen and filesystem registration succeeded.
Casey Schauflere114e472008-02-04 22:29:50 -08001618 */
1619static int __init init_smk_fs(void)
1620{
1621 int err;
1622
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +02001623 if (!security_module_enable(&smack_ops))
1624 return 0;
1625
Casey Schauflere114e472008-02-04 22:29:50 -08001626 err = register_filesystem(&smk_fs_type);
1627 if (!err) {
1628 smackfs_mount = kern_mount(&smk_fs_type);
1629 if (IS_ERR(smackfs_mount)) {
1630 printk(KERN_ERR "smackfs: could not mount!\n");
1631 err = PTR_ERR(smackfs_mount);
1632 smackfs_mount = NULL;
1633 }
1634 }
1635
Casey Schauflere114e472008-02-04 22:29:50 -08001636 smk_cipso_doi();
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001637 smk_unlbl_ambient(NULL);
Casey Schauflere114e472008-02-04 22:29:50 -08001638
Casey Schaufler272cd7a2011-09-20 12:24:36 -07001639 mutex_init(&smack_known_floor.smk_rules_lock);
1640 mutex_init(&smack_known_hat.smk_rules_lock);
1641 mutex_init(&smack_known_huh.smk_rules_lock);
1642 mutex_init(&smack_known_invalid.smk_rules_lock);
1643 mutex_init(&smack_known_star.smk_rules_lock);
1644 mutex_init(&smack_known_web.smk_rules_lock);
1645
1646 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
1647 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
1648 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
1649 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
1650 INIT_LIST_HEAD(&smack_known_star.smk_rules);
1651 INIT_LIST_HEAD(&smack_known_web.smk_rules);
1652
Casey Schauflere114e472008-02-04 22:29:50 -08001653 return err;
1654}
1655
1656__initcall(init_smk_fs);