blob: 76e520be1b5d18c1e4a72c021c5d135a214141a7 [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)
107/*
Casey Schauflere114e472008-02-04 22:29:50 -0800108#define SEQ_READ_FINISHED 1
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700109*/
Casey Schauflere114e472008-02-04 22:29:50 -0800110
111/*
Casey Schauflere114e472008-02-04 22:29:50 -0800112 * Values for parsing cipso rules
113 * SMK_DIGITLEN: Length of a digit field in a rule.
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700114 * SMK_CIPSOMIN: Minimum possible cipso rule length.
115 * SMK_CIPSOMAX: Maximum possible cipso rule length.
Casey Schauflere114e472008-02-04 22:29:50 -0800116 */
117#define SMK_DIGITLEN 4
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700118#define SMK_CIPSOMIN (SMK_LABELLEN + 2 * SMK_DIGITLEN)
119#define SMK_CIPSOMAX (SMK_CIPSOMIN + SMACK_CIPSO_MAXCATNUM * SMK_DIGITLEN)
120
121/*
122 * Values for parsing MAC rules
123 * SMK_ACCESS: Maximum possible combination of access permissions
124 * SMK_ACCESSLEN: Maximum length for a rule access field
125 * SMK_LOADLEN: Smack rule length
126 */
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200127#define SMK_OACCESS "rwxa"
128#define SMK_ACCESS "rwxat"
129#define SMK_OACCESSLEN (sizeof(SMK_OACCESS) - 1)
130#define SMK_ACCESSLEN (sizeof(SMK_ACCESS) - 1)
131#define SMK_OLOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_OACCESSLEN)
132#define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN)
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700133
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500134/**
135 * smk_netlabel_audit_set - fill a netlbl_audit struct
136 * @nap: structure to fill
137 */
138static void smk_netlabel_audit_set(struct netlbl_audit *nap)
139{
140 nap->loginuid = audit_get_loginuid(current);
141 nap->sessionid = audit_get_sessionid(current);
Casey Schaufler676dac42010-12-02 06:43:39 -0800142 nap->secid = smack_to_secid(smk_of_current());
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500143}
144
145/*
146 * Values for parsing single label host rules
147 * "1.2.3.4 X"
148 * "192.168.138.129/32 abcdefghijklmnopqrstuvw"
149 */
150#define SMK_NETLBLADDRMIN 9
151#define SMK_NETLBLADDRMAX 42
Casey Schauflere114e472008-02-04 22:29:50 -0800152
Casey Schauflere114e472008-02-04 22:29:50 -0800153/**
154 * smk_set_access - add a rule to the rule list
155 * @srp: the new rule to add
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800156 * @rule_list: the list of rules
157 * @rule_lock: the rule list lock
Casey Schauflere114e472008-02-04 22:29:50 -0800158 *
159 * Looks through the current subject/object/access list for
160 * the subject/object pair and replaces the access that was
161 * there. If the pair isn't found add it with the specified
162 * access.
Sergio Luis81ea7142008-12-22 01:16:15 -0300163 *
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800164 * Returns 1 if a rule was found to exist already, 0 if it is new
Sergio Luis81ea7142008-12-22 01:16:15 -0300165 * Returns 0 if nothing goes wrong or -ENOMEM if it fails
166 * during the allocation of the new pair to add.
Casey Schauflere114e472008-02-04 22:29:50 -0800167 */
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800168static int smk_set_access(struct smack_rule *srp, struct list_head *rule_list,
169 struct mutex *rule_lock)
Casey Schauflere114e472008-02-04 22:29:50 -0800170{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100171 struct smack_rule *sp;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800172 int found = 0;
Casey Schauflere114e472008-02-04 22:29:50 -0800173
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800174 mutex_lock(rule_lock);
175
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700176 /*
177 * Because the object label is less likely to match
178 * than the subject label check it first
179 */
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800180 list_for_each_entry_rcu(sp, rule_list, list) {
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700181 if (sp->smk_object == srp->smk_object &&
182 sp->smk_subject == srp->smk_subject) {
Etienne Basset7198e2e2009-03-24 20:53:24 +0100183 found = 1;
184 sp->smk_access = srp->smk_access;
Casey Schauflere114e472008-02-04 22:29:50 -0800185 break;
186 }
Casey Schauflere114e472008-02-04 22:29:50 -0800187 }
Etienne Basset7198e2e2009-03-24 20:53:24 +0100188 if (found == 0)
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800189 list_add_rcu(&srp->list, rule_list);
Casey Schauflere114e472008-02-04 22:29:50 -0800190
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800191 mutex_unlock(rule_lock);
Casey Schauflere114e472008-02-04 22:29:50 -0800192
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800193 return found;
Casey Schauflere114e472008-02-04 22:29:50 -0800194}
195
196/**
Jarkko Sakkinen828716c2011-09-08 10:12:01 +0300197 * smk_parse_rule - parse subject, object and access type
198 * @data: string to be parsed whose size is SMK_LOADLEN
199 * @rule: parsed entities are stored in here
200 */
201static int smk_parse_rule(const char *data, struct smack_rule *rule)
202{
203 rule->smk_subject = smk_import(data, 0);
204 if (rule->smk_subject == NULL)
205 return -1;
206
207 rule->smk_object = smk_import(data + SMK_LABELLEN, 0);
208 if (rule->smk_object == NULL)
209 return -1;
210
211 rule->smk_access = 0;
212
213 switch (data[SMK_LABELLEN + SMK_LABELLEN]) {
214 case '-':
215 break;
216 case 'r':
217 case 'R':
218 rule->smk_access |= MAY_READ;
219 break;
220 default:
221 return -1;
222 }
223
224 switch (data[SMK_LABELLEN + SMK_LABELLEN + 1]) {
225 case '-':
226 break;
227 case 'w':
228 case 'W':
229 rule->smk_access |= MAY_WRITE;
230 break;
231 default:
232 return -1;
233 }
234
235 switch (data[SMK_LABELLEN + SMK_LABELLEN + 2]) {
236 case '-':
237 break;
238 case 'x':
239 case 'X':
240 rule->smk_access |= MAY_EXEC;
241 break;
242 default:
243 return -1;
244 }
245
246 switch (data[SMK_LABELLEN + SMK_LABELLEN + 3]) {
247 case '-':
248 break;
249 case 'a':
250 case 'A':
251 rule->smk_access |= MAY_APPEND;
252 break;
253 default:
254 return -1;
255 }
256
257 switch (data[SMK_LABELLEN + SMK_LABELLEN + 4]) {
258 case '-':
259 break;
260 case 't':
261 case 'T':
262 rule->smk_access |= MAY_TRANSMUTE;
263 break;
264 default:
265 return -1;
266 }
267
268 return 0;
269}
270
271/**
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800272 * smk_write_load_list - write() for any /smack/load
Randy Dunlap251a2a92009-02-18 11:42:33 -0800273 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -0800274 * @buf: where to get the data from
275 * @count: bytes sent
276 * @ppos: where to start - must be 0
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800277 * @rule_list: the list of rules to write to
278 * @rule_lock: lock for the rule list
Casey Schauflere114e472008-02-04 22:29:50 -0800279 *
280 * Get one smack access rule from above.
281 * The format is exactly:
282 * char subject[SMK_LABELLEN]
283 * char object[SMK_LABELLEN]
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700284 * char access[SMK_ACCESSLEN]
Casey Schauflere114e472008-02-04 22:29:50 -0800285 *
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700286 * writes must be SMK_LABELLEN+SMK_LABELLEN+SMK_ACCESSLEN bytes.
Casey Schauflere114e472008-02-04 22:29:50 -0800287 */
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800288static ssize_t smk_write_load_list(struct file *file, const char __user *buf,
289 size_t count, loff_t *ppos,
290 struct list_head *rule_list,
291 struct mutex *rule_lock)
Casey Schauflere114e472008-02-04 22:29:50 -0800292{
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700293 struct smack_master_list *smlp;
294 struct smack_known *skp;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100295 struct smack_rule *rule;
Casey Schauflere114e472008-02-04 22:29:50 -0800296 char *data;
297 int rc = -EINVAL;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700298 int load = 0;
Casey Schauflere114e472008-02-04 22:29:50 -0800299
300 /*
Casey Schauflere114e472008-02-04 22:29:50 -0800301 * No partial writes.
302 * Enough data must be present.
303 */
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200304 if (*ppos != 0)
305 return -EINVAL;
306 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300307 * Minor hack for backward compatibility
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200308 */
309 if (count < (SMK_OLOADLEN) || count > SMK_LOADLEN)
Casey Schauflere114e472008-02-04 22:29:50 -0800310 return -EINVAL;
311
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200312 data = kzalloc(SMK_LOADLEN, GFP_KERNEL);
Casey Schauflere114e472008-02-04 22:29:50 -0800313 if (data == NULL)
314 return -ENOMEM;
315
316 if (copy_from_user(data, buf, count) != 0) {
317 rc = -EFAULT;
318 goto out;
319 }
320
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200321 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300322 * More on the minor hack for backward compatibility
Jarkko Sakkinen5c6d1122010-12-07 13:34:01 +0200323 */
324 if (count == (SMK_OLOADLEN))
325 data[SMK_OLOADLEN] = '-';
326
Etienne Basset7198e2e2009-03-24 20:53:24 +0100327 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
328 if (rule == NULL) {
329 rc = -ENOMEM;
Casey Schauflere114e472008-02-04 22:29:50 -0800330 goto out;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100331 }
Casey Schauflere114e472008-02-04 22:29:50 -0800332
Jarkko Sakkinen828716c2011-09-08 10:12:01 +0300333 if (smk_parse_rule(data, rule))
Etienne Basset7198e2e2009-03-24 20:53:24 +0100334 goto out_free_rule;
Casey Schauflere114e472008-02-04 22:29:50 -0800335
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700336 if (rule_list == NULL) {
337 load = 1;
338 skp = smk_find_entry(rule->smk_subject);
339 rule_list = &skp->smk_rules;
340 rule_lock = &skp->smk_rules_lock;
341 }
342
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800343 rc = count;
344 /*
345 * smk_set_access returns true if there was already a rule
346 * for the subject/object pair, and false if it was new.
347 */
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700348 if (!smk_set_access(rule, rule_list, rule_lock)) {
349 smlp = kzalloc(sizeof(*smlp), GFP_KERNEL);
350 if (smlp != NULL) {
351 smlp->smk_rule = rule;
352 list_add_rcu(&smlp->list, &smack_rule_list);
353 } else
354 rc = -ENOMEM;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800355 goto out;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700356 }
Casey Schauflere114e472008-02-04 22:29:50 -0800357
Etienne Basset7198e2e2009-03-24 20:53:24 +0100358out_free_rule:
359 kfree(rule);
Casey Schauflere114e472008-02-04 22:29:50 -0800360out:
361 kfree(data);
362 return rc;
363}
364
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800365
366/*
367 * Seq_file read operations for /smack/load
368 */
369
370static void *load_seq_start(struct seq_file *s, loff_t *pos)
371{
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700372 struct list_head *list;
373
374 /*
375 * This is 0 the first time through.
376 */
377 if (s->index == 0)
378 s->private = &smack_rule_list;
379
380 if (s->private == NULL)
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800381 return NULL;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700382
383 list = s->private;
384 if (list_empty(list))
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800385 return NULL;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700386
387 if (s->index == 0)
388 return list->next;
389 return list;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800390}
391
392static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
393{
394 struct list_head *list = v;
395
396 if (list_is_last(list, &smack_rule_list)) {
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700397 s->private = NULL;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800398 return NULL;
399 }
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700400 s->private = list->next;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800401 return list->next;
402}
403
404static int load_seq_show(struct seq_file *s, void *v)
405{
406 struct list_head *list = v;
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700407 struct smack_master_list *smlp =
408 list_entry(list, struct smack_master_list, list);
409 struct smack_rule *srp = smlp->smk_rule;
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800410
411 seq_printf(s, "%s %s", (char *)srp->smk_subject,
412 (char *)srp->smk_object);
413
414 seq_putc(s, ' ');
415
416 if (srp->smk_access & MAY_READ)
417 seq_putc(s, 'r');
418 if (srp->smk_access & MAY_WRITE)
419 seq_putc(s, 'w');
420 if (srp->smk_access & MAY_EXEC)
421 seq_putc(s, 'x');
422 if (srp->smk_access & MAY_APPEND)
423 seq_putc(s, 'a');
424 if (srp->smk_access & MAY_TRANSMUTE)
425 seq_putc(s, 't');
426 if (srp->smk_access == 0)
427 seq_putc(s, '-');
428
429 seq_putc(s, '\n');
430
431 return 0;
432}
433
434static void load_seq_stop(struct seq_file *s, void *v)
435{
436 /* No-op */
437}
438
439static const struct seq_operations load_seq_ops = {
440 .start = load_seq_start,
441 .next = load_seq_next,
442 .show = load_seq_show,
443 .stop = load_seq_stop,
444};
445
446/**
447 * smk_open_load - open() for /smack/load
448 * @inode: inode structure representing file
449 * @file: "load" file pointer
450 *
451 * For reading, use load_seq_* seq_file reading operations.
452 */
453static int smk_open_load(struct inode *inode, struct file *file)
454{
455 return seq_open(file, &load_seq_ops);
456}
457
458/**
459 * smk_write_load - write() for /smack/load
460 * @file: file pointer, not actually used
461 * @buf: where to get the data from
462 * @count: bytes sent
463 * @ppos: where to start - must be 0
464 *
465 */
466static ssize_t smk_write_load(struct file *file, const char __user *buf,
467 size_t count, loff_t *ppos)
468{
469
470 /*
471 * Must have privilege.
472 * No partial writes.
473 * Enough data must be present.
474 */
475 if (!capable(CAP_MAC_ADMIN))
476 return -EPERM;
477
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700478/*
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800479 return smk_write_load_list(file, buf, count, ppos, &smack_rule_list,
480 &smack_list_lock);
Casey Schaufler272cd7a2011-09-20 12:24:36 -0700481*/
482 return smk_write_load_list(file, buf, count, ppos, NULL, NULL);
Casey Schaufler7898e1f2011-01-17 08:05:27 -0800483}
484
Casey Schauflere114e472008-02-04 22:29:50 -0800485static const struct file_operations smk_load_ops = {
486 .open = smk_open_load,
487 .read = seq_read,
488 .llseek = seq_lseek,
489 .write = smk_write_load,
Ahmed S. Darwishcb622bb2008-03-24 12:29:49 -0700490 .release = seq_release,
Casey Schauflere114e472008-02-04 22:29:50 -0800491};
492
493/**
494 * smk_cipso_doi - initialize the CIPSO domain
495 */
Casey Schaufler30aa4fa2008-04-28 02:13:43 -0700496static void smk_cipso_doi(void)
Casey Schauflere114e472008-02-04 22:29:50 -0800497{
498 int rc;
499 struct cipso_v4_doi *doip;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500500 struct netlbl_audit nai;
Casey Schauflere114e472008-02-04 22:29:50 -0800501
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500502 smk_netlabel_audit_set(&nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800503
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500504 rc = netlbl_cfg_map_del(NULL, PF_INET, NULL, NULL, &nai);
Casey Schauflere114e472008-02-04 22:29:50 -0800505 if (rc != 0)
506 printk(KERN_WARNING "%s:%d remove rc = %d\n",
507 __func__, __LINE__, rc);
508
509 doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
510 if (doip == NULL)
511 panic("smack: Failed to initialize cipso DOI.\n");
512 doip->map.std = NULL;
513 doip->doi = smk_cipso_doi_value;
514 doip->type = CIPSO_V4_MAP_PASS;
515 doip->tags[0] = CIPSO_V4_TAG_RBITMAP;
516 for (rc = 1; rc < CIPSO_V4_TAG_MAXCNT; rc++)
517 doip->tags[rc] = CIPSO_V4_TAG_INVALID;
518
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500519 rc = netlbl_cfg_cipsov4_add(doip, &nai);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400520 if (rc != 0) {
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500521 printk(KERN_WARNING "%s:%d cipso add rc = %d\n",
Casey Schauflere114e472008-02-04 22:29:50 -0800522 __func__, __LINE__, rc);
Paul Mooreb1edeb12008-10-10 10:16:31 -0400523 kfree(doip);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500524 return;
525 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500526 rc = netlbl_cfg_cipsov4_map_add(doip->doi, NULL, NULL, NULL, &nai);
Paul Moore6c2e8ac2008-12-31 12:54:11 -0500527 if (rc != 0) {
528 printk(KERN_WARNING "%s:%d map add rc = %d\n",
529 __func__, __LINE__, rc);
530 kfree(doip);
531 return;
Paul Mooreb1edeb12008-10-10 10:16:31 -0400532 }
Casey Schauflere114e472008-02-04 22:29:50 -0800533}
534
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800535/**
536 * smk_unlbl_ambient - initialize the unlabeled domain
Randy Dunlap251a2a92009-02-18 11:42:33 -0800537 * @oldambient: previous domain string
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800538 */
Casey Schaufler30aa4fa2008-04-28 02:13:43 -0700539static void smk_unlbl_ambient(char *oldambient)
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800540{
541 int rc;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500542 struct netlbl_audit nai;
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800543
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500544 smk_netlabel_audit_set(&nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800545
546 if (oldambient != NULL) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500547 rc = netlbl_cfg_map_del(oldambient, PF_INET, NULL, NULL, &nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800548 if (rc != 0)
549 printk(KERN_WARNING "%s:%d remove rc = %d\n",
550 __func__, __LINE__, rc);
551 }
552
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500553 rc = netlbl_cfg_unlbl_map_add(smack_net_ambient, PF_INET,
554 NULL, NULL, &nai);
Casey Schaufler4bc87e62008-02-15 15:24:25 -0800555 if (rc != 0)
556 printk(KERN_WARNING "%s:%d add rc = %d\n",
557 __func__, __LINE__, rc);
558}
559
Casey Schauflere114e472008-02-04 22:29:50 -0800560/*
561 * Seq_file read operations for /smack/cipso
562 */
563
564static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
565{
566 if (*pos == SEQ_READ_FINISHED)
567 return NULL;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100568 if (list_empty(&smack_known_list))
569 return NULL;
Casey Schauflere114e472008-02-04 22:29:50 -0800570
Etienne Basset7198e2e2009-03-24 20:53:24 +0100571 return smack_known_list.next;
Casey Schauflere114e472008-02-04 22:29:50 -0800572}
573
574static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
575{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100576 struct list_head *list = v;
Casey Schauflere114e472008-02-04 22:29:50 -0800577
578 /*
Etienne Basset7198e2e2009-03-24 20:53:24 +0100579 * labels with no associated cipso value wont be printed
580 * in cipso_seq_show
Casey Schauflere114e472008-02-04 22:29:50 -0800581 */
Etienne Basset7198e2e2009-03-24 20:53:24 +0100582 if (list_is_last(list, &smack_known_list)) {
Casey Schauflere114e472008-02-04 22:29:50 -0800583 *pos = SEQ_READ_FINISHED;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100584 return NULL;
585 }
Casey Schauflere114e472008-02-04 22:29:50 -0800586
Etienne Basset7198e2e2009-03-24 20:53:24 +0100587 return list->next;
Casey Schauflere114e472008-02-04 22:29:50 -0800588}
589
590/*
591 * Print cipso labels in format:
592 * label level[/cat[,cat]]
593 */
594static int cipso_seq_show(struct seq_file *s, void *v)
595{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100596 struct list_head *list = v;
597 struct smack_known *skp =
598 list_entry(list, struct smack_known, list);
Casey Schauflere114e472008-02-04 22:29:50 -0800599 struct smack_cipso *scp = skp->smk_cipso;
600 char *cbp;
601 char sep = '/';
602 int cat = 1;
603 int i;
604 unsigned char m;
605
606 if (scp == NULL)
607 return 0;
608
609 seq_printf(s, "%s %3d", (char *)&skp->smk_known, scp->smk_level);
610
611 cbp = scp->smk_catset;
612 for (i = 0; i < SMK_LABELLEN; i++)
613 for (m = 0x80; m != 0; m >>= 1) {
614 if (m & cbp[i]) {
615 seq_printf(s, "%c%d", sep, cat);
616 sep = ',';
617 }
618 cat++;
619 }
620
621 seq_putc(s, '\n');
622
623 return 0;
624}
625
626static void cipso_seq_stop(struct seq_file *s, void *v)
627{
628 /* No-op */
629}
630
James Morris88e9d342009-09-22 16:43:43 -0700631static const struct seq_operations cipso_seq_ops = {
Casey Schauflere114e472008-02-04 22:29:50 -0800632 .start = cipso_seq_start,
633 .stop = cipso_seq_stop,
634 .next = cipso_seq_next,
635 .show = cipso_seq_show,
636};
637
638/**
639 * smk_open_cipso - open() for /smack/cipso
640 * @inode: inode structure representing file
641 * @file: "cipso" file pointer
642 *
643 * Connect our cipso_seq_* operations with /smack/cipso
644 * file_operations
645 */
646static int smk_open_cipso(struct inode *inode, struct file *file)
647{
648 return seq_open(file, &cipso_seq_ops);
649}
650
651/**
652 * smk_write_cipso - write() for /smack/cipso
Randy Dunlap251a2a92009-02-18 11:42:33 -0800653 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -0800654 * @buf: where to get the data from
655 * @count: bytes sent
656 * @ppos: where to start
657 *
658 * Accepts only one cipso rule per write call.
659 * Returns number of bytes written or error code, as appropriate
660 */
661static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
662 size_t count, loff_t *ppos)
663{
664 struct smack_known *skp;
665 struct smack_cipso *scp = NULL;
666 char mapcatset[SMK_LABELLEN];
667 int maplevel;
668 int cat;
669 int catlen;
670 ssize_t rc = -EINVAL;
671 char *data = NULL;
672 char *rule;
673 int ret;
674 int i;
675
676 /*
677 * Must have privilege.
678 * No partial writes.
679 * Enough data must be present.
680 */
681 if (!capable(CAP_MAC_ADMIN))
682 return -EPERM;
683 if (*ppos != 0)
684 return -EINVAL;
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700685 if (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX)
Casey Schauflere114e472008-02-04 22:29:50 -0800686 return -EINVAL;
687
688 data = kzalloc(count + 1, GFP_KERNEL);
689 if (data == NULL)
690 return -ENOMEM;
691
692 if (copy_from_user(data, buf, count) != 0) {
693 rc = -EFAULT;
694 goto unlockedout;
695 }
696
Etienne Basset43031542009-03-27 17:11:01 -0400697 /* labels cannot begin with a '-' */
698 if (data[0] == '-') {
699 rc = -EINVAL;
700 goto unlockedout;
701 }
Casey Schauflere114e472008-02-04 22:29:50 -0800702 data[count] = '\0';
703 rule = data;
704 /*
705 * Only allow one writer at a time. Writes should be
706 * quite rare and small in any case.
707 */
708 mutex_lock(&smack_cipso_lock);
709
710 skp = smk_import_entry(rule, 0);
711 if (skp == NULL)
712 goto out;
713
Fernando Carrijoc19a28e2009-01-07 18:09:08 -0800714 rule += SMK_LABELLEN;
Casey Schauflere114e472008-02-04 22:29:50 -0800715 ret = sscanf(rule, "%d", &maplevel);
716 if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
717 goto out;
718
719 rule += SMK_DIGITLEN;
720 ret = sscanf(rule, "%d", &catlen);
721 if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
722 goto out;
723
Ahmed S. Darwishb500ce82008-03-13 12:32:34 -0700724 if (count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
Casey Schauflere114e472008-02-04 22:29:50 -0800725 goto out;
726
727 memset(mapcatset, 0, sizeof(mapcatset));
728
729 for (i = 0; i < catlen; i++) {
730 rule += SMK_DIGITLEN;
731 ret = sscanf(rule, "%d", &cat);
732 if (ret != 1 || cat > SMACK_CIPSO_MAXCATVAL)
733 goto out;
734
735 smack_catset_bit(cat, mapcatset);
736 }
737
738 if (skp->smk_cipso == NULL) {
739 scp = kzalloc(sizeof(struct smack_cipso), GFP_KERNEL);
740 if (scp == NULL) {
741 rc = -ENOMEM;
742 goto out;
743 }
744 }
745
746 spin_lock_bh(&skp->smk_cipsolock);
747
748 if (scp == NULL)
749 scp = skp->smk_cipso;
750 else
751 skp->smk_cipso = scp;
752
753 scp->smk_level = maplevel;
754 memcpy(scp->smk_catset, mapcatset, sizeof(mapcatset));
755
756 spin_unlock_bh(&skp->smk_cipsolock);
757
758 rc = count;
759out:
760 mutex_unlock(&smack_cipso_lock);
761unlockedout:
762 kfree(data);
763 return rc;
764}
765
766static const struct file_operations smk_cipso_ops = {
767 .open = smk_open_cipso,
768 .read = seq_read,
769 .llseek = seq_lseek,
770 .write = smk_write_cipso,
771 .release = seq_release,
772};
773
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500774/*
775 * Seq_file read operations for /smack/netlabel
776 */
777
778static void *netlbladdr_seq_start(struct seq_file *s, loff_t *pos)
779{
780 if (*pos == SEQ_READ_FINISHED)
781 return NULL;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100782 if (list_empty(&smk_netlbladdr_list))
783 return NULL;
784 return smk_netlbladdr_list.next;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500785}
786
787static void *netlbladdr_seq_next(struct seq_file *s, void *v, loff_t *pos)
788{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100789 struct list_head *list = v;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500790
Etienne Basset7198e2e2009-03-24 20:53:24 +0100791 if (list_is_last(list, &smk_netlbladdr_list)) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500792 *pos = SEQ_READ_FINISHED;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100793 return NULL;
794 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500795
Etienne Basset7198e2e2009-03-24 20:53:24 +0100796 return list->next;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500797}
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500798#define BEBITS (sizeof(__be32) * 8)
799
800/*
801 * Print host/label pairs
802 */
803static int netlbladdr_seq_show(struct seq_file *s, void *v)
804{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100805 struct list_head *list = v;
806 struct smk_netlbladdr *skp =
807 list_entry(list, struct smk_netlbladdr, list);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500808 unsigned char *hp = (char *) &skp->smk_host.sin_addr.s_addr;
etienne113a0e42009-03-04 07:33:51 +0100809 int maskn;
810 u32 temp_mask = be32_to_cpu(skp->smk_mask.s_addr);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500811
etienne113a0e42009-03-04 07:33:51 +0100812 for (maskn = 0; temp_mask; temp_mask <<= 1, maskn++);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500813
814 seq_printf(s, "%u.%u.%u.%u/%d %s\n",
815 hp[0], hp[1], hp[2], hp[3], maskn, skp->smk_label);
816
817 return 0;
818}
819
820static void netlbladdr_seq_stop(struct seq_file *s, void *v)
821{
822 /* No-op */
823}
824
James Morris88e9d342009-09-22 16:43:43 -0700825static const struct seq_operations netlbladdr_seq_ops = {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500826 .start = netlbladdr_seq_start,
827 .stop = netlbladdr_seq_stop,
828 .next = netlbladdr_seq_next,
829 .show = netlbladdr_seq_show,
830};
831
832/**
833 * smk_open_netlbladdr - open() for /smack/netlabel
834 * @inode: inode structure representing file
835 * @file: "netlabel" file pointer
836 *
837 * Connect our netlbladdr_seq_* operations with /smack/netlabel
838 * file_operations
839 */
840static int smk_open_netlbladdr(struct inode *inode, struct file *file)
841{
842 return seq_open(file, &netlbladdr_seq_ops);
843}
844
845/**
etienne113a0e42009-03-04 07:33:51 +0100846 * smk_netlbladdr_insert
847 * @new : netlabel to insert
848 *
849 * This helper insert netlabel in the smack_netlbladdrs list
850 * sorted by netmask length (longest to smallest)
Etienne Basset7198e2e2009-03-24 20:53:24 +0100851 * locked by &smk_netlbladdr_lock in smk_write_netlbladdr
852 *
etienne113a0e42009-03-04 07:33:51 +0100853 */
854static void smk_netlbladdr_insert(struct smk_netlbladdr *new)
855{
Etienne Basset7198e2e2009-03-24 20:53:24 +0100856 struct smk_netlbladdr *m, *m_next;
etienne113a0e42009-03-04 07:33:51 +0100857
Etienne Basset7198e2e2009-03-24 20:53:24 +0100858 if (list_empty(&smk_netlbladdr_list)) {
859 list_add_rcu(&new->list, &smk_netlbladdr_list);
etienne113a0e42009-03-04 07:33:51 +0100860 return;
861 }
862
Jiri Pirko05725f72009-04-14 20:17:16 +0200863 m = list_entry_rcu(smk_netlbladdr_list.next,
864 struct smk_netlbladdr, list);
Etienne Basset7198e2e2009-03-24 20:53:24 +0100865
etienne113a0e42009-03-04 07:33:51 +0100866 /* the comparison '>' is a bit hacky, but works */
Etienne Basset7198e2e2009-03-24 20:53:24 +0100867 if (new->smk_mask.s_addr > m->smk_mask.s_addr) {
868 list_add_rcu(&new->list, &smk_netlbladdr_list);
etienne113a0e42009-03-04 07:33:51 +0100869 return;
870 }
Etienne Basset7198e2e2009-03-24 20:53:24 +0100871
872 list_for_each_entry_rcu(m, &smk_netlbladdr_list, list) {
873 if (list_is_last(&m->list, &smk_netlbladdr_list)) {
874 list_add_rcu(&new->list, &m->list);
etienne113a0e42009-03-04 07:33:51 +0100875 return;
876 }
Jiri Pirko05725f72009-04-14 20:17:16 +0200877 m_next = list_entry_rcu(m->list.next,
878 struct smk_netlbladdr, list);
Etienne Basset7198e2e2009-03-24 20:53:24 +0100879 if (new->smk_mask.s_addr > m_next->smk_mask.s_addr) {
880 list_add_rcu(&new->list, &m->list);
etienne113a0e42009-03-04 07:33:51 +0100881 return;
882 }
883 }
884}
885
886
887/**
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500888 * smk_write_netlbladdr - write() for /smack/netlabel
Randy Dunlap251a2a92009-02-18 11:42:33 -0800889 * @file: file pointer, not actually used
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500890 * @buf: where to get the data from
891 * @count: bytes sent
892 * @ppos: where to start
893 *
894 * Accepts only one netlbladdr per write call.
895 * Returns number of bytes written or error code, as appropriate
896 */
897static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
898 size_t count, loff_t *ppos)
899{
900 struct smk_netlbladdr *skp;
901 struct sockaddr_in newname;
902 char smack[SMK_LABELLEN];
903 char *sp;
Roel Kluin6470c072009-05-21 18:42:54 +0200904 char data[SMK_NETLBLADDRMAX + 1];
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500905 char *host = (char *)&newname.sin_addr.s_addr;
906 int rc;
907 struct netlbl_audit audit_info;
908 struct in_addr mask;
909 unsigned int m;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100910 int found;
etienne113a0e42009-03-04 07:33:51 +0100911 u32 mask_bits = (1<<31);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500912 __be32 nsa;
etienne113a0e42009-03-04 07:33:51 +0100913 u32 temp_mask;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500914
915 /*
916 * Must have privilege.
917 * No partial writes.
918 * Enough data must be present.
919 * "<addr/mask, as a.b.c.d/e><space><label>"
920 * "<addr, as a.b.c.d><space><label>"
921 */
922 if (!capable(CAP_MAC_ADMIN))
923 return -EPERM;
924 if (*ppos != 0)
925 return -EINVAL;
926 if (count < SMK_NETLBLADDRMIN || count > SMK_NETLBLADDRMAX)
927 return -EINVAL;
928 if (copy_from_user(data, buf, count) != 0)
929 return -EFAULT;
930
931 data[count] = '\0';
932
933 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd/%d %s",
934 &host[0], &host[1], &host[2], &host[3], &m, smack);
935 if (rc != 6) {
936 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd %s",
937 &host[0], &host[1], &host[2], &host[3], smack);
938 if (rc != 5)
939 return -EINVAL;
940 m = BEBITS;
941 }
942 if (m > BEBITS)
943 return -EINVAL;
944
Etienne Basset43031542009-03-27 17:11:01 -0400945 /* if smack begins with '-', its an option, don't import it */
946 if (smack[0] != '-') {
947 sp = smk_import(smack, 0);
948 if (sp == NULL)
949 return -EINVAL;
950 } else {
951 /* check known options */
952 if (strcmp(smack, smack_cipso_option) == 0)
953 sp = (char *)smack_cipso_option;
954 else
955 return -EINVAL;
956 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500957
etienne113a0e42009-03-04 07:33:51 +0100958 for (temp_mask = 0; m > 0; m--) {
959 temp_mask |= mask_bits;
960 mask_bits >>= 1;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500961 }
etienne113a0e42009-03-04 07:33:51 +0100962 mask.s_addr = cpu_to_be32(temp_mask);
963
964 newname.sin_addr.s_addr &= mask.s_addr;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500965 /*
966 * Only allow one writer at a time. Writes should be
967 * quite rare and small in any case.
968 */
969 mutex_lock(&smk_netlbladdr_lock);
970
971 nsa = newname.sin_addr.s_addr;
etienne113a0e42009-03-04 07:33:51 +0100972 /* try to find if the prefix is already in the list */
Etienne Basset7198e2e2009-03-24 20:53:24 +0100973 found = 0;
974 list_for_each_entry_rcu(skp, &smk_netlbladdr_list, list) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500975 if (skp->smk_host.sin_addr.s_addr == nsa &&
Etienne Basset7198e2e2009-03-24 20:53:24 +0100976 skp->smk_mask.s_addr == mask.s_addr) {
977 found = 1;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500978 break;
Etienne Basset7198e2e2009-03-24 20:53:24 +0100979 }
980 }
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500981 smk_netlabel_audit_set(&audit_info);
982
Etienne Basset7198e2e2009-03-24 20:53:24 +0100983 if (found == 0) {
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500984 skp = kzalloc(sizeof(*skp), GFP_KERNEL);
985 if (skp == NULL)
986 rc = -ENOMEM;
987 else {
988 rc = 0;
989 skp->smk_host.sin_addr.s_addr = newname.sin_addr.s_addr;
990 skp->smk_mask.s_addr = mask.s_addr;
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500991 skp->smk_label = sp;
etienne113a0e42009-03-04 07:33:51 +0100992 smk_netlbladdr_insert(skp);
Casey Schaufler6d3dc072008-12-31 12:54:12 -0500993 }
994 } else {
Etienne Basset43031542009-03-27 17:11:01 -0400995 /* we delete the unlabeled entry, only if the previous label
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300996 * wasn't the special CIPSO option */
Etienne Basset43031542009-03-27 17:11:01 -0400997 if (skp->smk_label != smack_cipso_option)
998 rc = netlbl_cfg_unlbl_static_del(&init_net, NULL,
999 &skp->smk_host.sin_addr, &skp->smk_mask,
1000 PF_INET, &audit_info);
1001 else
1002 rc = 0;
Casey Schaufler6d3dc072008-12-31 12:54:12 -05001003 skp->smk_label = sp;
1004 }
1005
1006 /*
1007 * Now tell netlabel about the single label nature of
1008 * this host so that incoming packets get labeled.
Etienne Basset43031542009-03-27 17:11:01 -04001009 * but only if we didn't get the special CIPSO option
Casey Schaufler6d3dc072008-12-31 12:54:12 -05001010 */
Etienne Basset43031542009-03-27 17:11:01 -04001011 if (rc == 0 && sp != smack_cipso_option)
Casey Schaufler6d3dc072008-12-31 12:54:12 -05001012 rc = netlbl_cfg_unlbl_static_add(&init_net, NULL,
1013 &skp->smk_host.sin_addr, &skp->smk_mask, PF_INET,
1014 smack_to_secid(skp->smk_label), &audit_info);
1015
1016 if (rc == 0)
1017 rc = count;
1018
1019 mutex_unlock(&smk_netlbladdr_lock);
1020
1021 return rc;
1022}
1023
1024static const struct file_operations smk_netlbladdr_ops = {
1025 .open = smk_open_netlbladdr,
1026 .read = seq_read,
1027 .llseek = seq_lseek,
1028 .write = smk_write_netlbladdr,
1029 .release = seq_release,
1030};
1031
Casey Schauflere114e472008-02-04 22:29:50 -08001032/**
1033 * smk_read_doi - read() for /smack/doi
1034 * @filp: file pointer, not actually used
1035 * @buf: where to put the result
1036 * @count: maximum to send along
1037 * @ppos: where to start
1038 *
1039 * Returns number of bytes read or error code, as appropriate
1040 */
1041static ssize_t smk_read_doi(struct file *filp, char __user *buf,
1042 size_t count, loff_t *ppos)
1043{
1044 char temp[80];
1045 ssize_t rc;
1046
1047 if (*ppos != 0)
1048 return 0;
1049
1050 sprintf(temp, "%d", smk_cipso_doi_value);
1051 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1052
1053 return rc;
1054}
1055
1056/**
1057 * smk_write_doi - write() for /smack/doi
Randy Dunlap251a2a92009-02-18 11:42:33 -08001058 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -08001059 * @buf: where to get the data from
1060 * @count: bytes sent
1061 * @ppos: where to start
1062 *
1063 * Returns number of bytes written or error code, as appropriate
1064 */
1065static ssize_t smk_write_doi(struct file *file, const char __user *buf,
1066 size_t count, loff_t *ppos)
1067{
1068 char temp[80];
1069 int i;
1070
1071 if (!capable(CAP_MAC_ADMIN))
1072 return -EPERM;
1073
1074 if (count >= sizeof(temp) || count == 0)
1075 return -EINVAL;
1076
1077 if (copy_from_user(temp, buf, count) != 0)
1078 return -EFAULT;
1079
1080 temp[count] = '\0';
1081
1082 if (sscanf(temp, "%d", &i) != 1)
1083 return -EINVAL;
1084
1085 smk_cipso_doi_value = i;
1086
1087 smk_cipso_doi();
1088
1089 return count;
1090}
1091
1092static const struct file_operations smk_doi_ops = {
1093 .read = smk_read_doi,
1094 .write = smk_write_doi,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001095 .llseek = default_llseek,
Casey Schauflere114e472008-02-04 22:29:50 -08001096};
1097
1098/**
1099 * smk_read_direct - read() for /smack/direct
1100 * @filp: file pointer, not actually used
1101 * @buf: where to put the result
1102 * @count: maximum to send along
1103 * @ppos: where to start
1104 *
1105 * Returns number of bytes read or error code, as appropriate
1106 */
1107static ssize_t smk_read_direct(struct file *filp, char __user *buf,
1108 size_t count, loff_t *ppos)
1109{
1110 char temp[80];
1111 ssize_t rc;
1112
1113 if (*ppos != 0)
1114 return 0;
1115
1116 sprintf(temp, "%d", smack_cipso_direct);
1117 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1118
1119 return rc;
1120}
1121
1122/**
1123 * smk_write_direct - write() for /smack/direct
Randy Dunlap251a2a92009-02-18 11:42:33 -08001124 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -08001125 * @buf: where to get the data from
1126 * @count: bytes sent
1127 * @ppos: where to start
1128 *
1129 * Returns number of bytes written or error code, as appropriate
1130 */
1131static ssize_t smk_write_direct(struct file *file, const char __user *buf,
1132 size_t count, loff_t *ppos)
1133{
1134 char temp[80];
1135 int i;
1136
1137 if (!capable(CAP_MAC_ADMIN))
1138 return -EPERM;
1139
1140 if (count >= sizeof(temp) || count == 0)
1141 return -EINVAL;
1142
1143 if (copy_from_user(temp, buf, count) != 0)
1144 return -EFAULT;
1145
1146 temp[count] = '\0';
1147
1148 if (sscanf(temp, "%d", &i) != 1)
1149 return -EINVAL;
1150
1151 smack_cipso_direct = i;
1152
1153 return count;
1154}
1155
1156static const struct file_operations smk_direct_ops = {
1157 .read = smk_read_direct,
1158 .write = smk_write_direct,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001159 .llseek = default_llseek,
Casey Schauflere114e472008-02-04 22:29:50 -08001160};
1161
1162/**
1163 * smk_read_ambient - read() for /smack/ambient
1164 * @filp: file pointer, not actually used
1165 * @buf: where to put the result
1166 * @cn: maximum to send along
1167 * @ppos: where to start
1168 *
1169 * Returns number of bytes read or error code, as appropriate
1170 */
1171static ssize_t smk_read_ambient(struct file *filp, char __user *buf,
1172 size_t cn, loff_t *ppos)
1173{
1174 ssize_t rc;
Casey Schauflere114e472008-02-04 22:29:50 -08001175 int asize;
1176
1177 if (*ppos != 0)
1178 return 0;
1179 /*
1180 * Being careful to avoid a problem in the case where
1181 * smack_net_ambient gets changed in midstream.
Casey Schauflere114e472008-02-04 22:29:50 -08001182 */
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001183 mutex_lock(&smack_ambient_lock);
Casey Schauflere114e472008-02-04 22:29:50 -08001184
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001185 asize = strlen(smack_net_ambient) + 1;
Casey Schauflere114e472008-02-04 22:29:50 -08001186
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001187 if (cn >= asize)
1188 rc = simple_read_from_buffer(buf, cn, ppos,
1189 smack_net_ambient, asize);
1190 else
1191 rc = -EINVAL;
1192
1193 mutex_unlock(&smack_ambient_lock);
Casey Schauflere114e472008-02-04 22:29:50 -08001194
1195 return rc;
1196}
1197
1198/**
1199 * smk_write_ambient - write() for /smack/ambient
Randy Dunlap251a2a92009-02-18 11:42:33 -08001200 * @file: file pointer, not actually used
Casey Schauflere114e472008-02-04 22:29:50 -08001201 * @buf: where to get the data from
1202 * @count: bytes sent
1203 * @ppos: where to start
1204 *
1205 * Returns number of bytes written or error code, as appropriate
1206 */
1207static ssize_t smk_write_ambient(struct file *file, const char __user *buf,
1208 size_t count, loff_t *ppos)
1209{
1210 char in[SMK_LABELLEN];
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001211 char *oldambient;
Casey Schauflere114e472008-02-04 22:29:50 -08001212 char *smack;
1213
1214 if (!capable(CAP_MAC_ADMIN))
1215 return -EPERM;
1216
1217 if (count >= SMK_LABELLEN)
1218 return -EINVAL;
1219
1220 if (copy_from_user(in, buf, count) != 0)
1221 return -EFAULT;
1222
1223 smack = smk_import(in, count);
1224 if (smack == NULL)
1225 return -EINVAL;
1226
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001227 mutex_lock(&smack_ambient_lock);
1228
1229 oldambient = smack_net_ambient;
Casey Schauflere114e472008-02-04 22:29:50 -08001230 smack_net_ambient = smack;
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001231 smk_unlbl_ambient(oldambient);
1232
1233 mutex_unlock(&smack_ambient_lock);
Casey Schauflere114e472008-02-04 22:29:50 -08001234
1235 return count;
1236}
1237
1238static const struct file_operations smk_ambient_ops = {
1239 .read = smk_read_ambient,
1240 .write = smk_write_ambient,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001241 .llseek = default_llseek,
Casey Schauflere114e472008-02-04 22:29:50 -08001242};
1243
Casey Schaufler15446232008-07-30 15:37:11 -07001244/**
1245 * smk_read_onlycap - read() for /smack/onlycap
1246 * @filp: file pointer, not actually used
1247 * @buf: where to put the result
1248 * @cn: maximum to send along
1249 * @ppos: where to start
1250 *
1251 * Returns number of bytes read or error code, as appropriate
1252 */
1253static ssize_t smk_read_onlycap(struct file *filp, char __user *buf,
1254 size_t cn, loff_t *ppos)
1255{
1256 char *smack = "";
1257 ssize_t rc = -EINVAL;
1258 int asize;
1259
1260 if (*ppos != 0)
1261 return 0;
1262
1263 if (smack_onlycap != NULL)
1264 smack = smack_onlycap;
1265
1266 asize = strlen(smack) + 1;
1267
1268 if (cn >= asize)
1269 rc = simple_read_from_buffer(buf, cn, ppos, smack, asize);
1270
1271 return rc;
1272}
1273
1274/**
1275 * smk_write_onlycap - write() for /smack/onlycap
Randy Dunlap251a2a92009-02-18 11:42:33 -08001276 * @file: file pointer, not actually used
Casey Schaufler15446232008-07-30 15:37:11 -07001277 * @buf: where to get the data from
1278 * @count: bytes sent
1279 * @ppos: where to start
1280 *
1281 * Returns number of bytes written or error code, as appropriate
1282 */
1283static ssize_t smk_write_onlycap(struct file *file, const char __user *buf,
1284 size_t count, loff_t *ppos)
1285{
1286 char in[SMK_LABELLEN];
Casey Schaufler676dac42010-12-02 06:43:39 -08001287 char *sp = smk_of_task(current->cred->security);
Casey Schaufler15446232008-07-30 15:37:11 -07001288
1289 if (!capable(CAP_MAC_ADMIN))
1290 return -EPERM;
1291
1292 /*
1293 * This can be done using smk_access() but is done
1294 * explicitly for clarity. The smk_access() implementation
1295 * would use smk_access(smack_onlycap, MAY_WRITE)
1296 */
1297 if (smack_onlycap != NULL && smack_onlycap != sp)
1298 return -EPERM;
1299
1300 if (count >= SMK_LABELLEN)
1301 return -EINVAL;
1302
1303 if (copy_from_user(in, buf, count) != 0)
1304 return -EFAULT;
1305
1306 /*
1307 * Should the null string be passed in unset the onlycap value.
1308 * This seems like something to be careful with as usually
1309 * smk_import only expects to return NULL for errors. It
1310 * is usually the case that a nullstring or "\n" would be
1311 * bad to pass to smk_import but in fact this is useful here.
1312 */
1313 smack_onlycap = smk_import(in, count);
1314
1315 return count;
1316}
1317
1318static const struct file_operations smk_onlycap_ops = {
1319 .read = smk_read_onlycap,
1320 .write = smk_write_onlycap,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001321 .llseek = default_llseek,
Casey Schaufler15446232008-07-30 15:37:11 -07001322};
1323
Casey Schauflere114e472008-02-04 22:29:50 -08001324/**
Etienne Bassetecfcc532009-04-08 20:40:06 +02001325 * smk_read_logging - read() for /smack/logging
1326 * @filp: file pointer, not actually used
1327 * @buf: where to put the result
1328 * @cn: maximum to send along
1329 * @ppos: where to start
1330 *
1331 * Returns number of bytes read or error code, as appropriate
1332 */
1333static ssize_t smk_read_logging(struct file *filp, char __user *buf,
1334 size_t count, loff_t *ppos)
1335{
1336 char temp[32];
1337 ssize_t rc;
1338
1339 if (*ppos != 0)
1340 return 0;
1341
1342 sprintf(temp, "%d\n", log_policy);
1343 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1344 return rc;
1345}
1346
1347/**
1348 * smk_write_logging - write() for /smack/logging
1349 * @file: file pointer, not actually used
1350 * @buf: where to get the data from
1351 * @count: bytes sent
1352 * @ppos: where to start
1353 *
1354 * Returns number of bytes written or error code, as appropriate
1355 */
1356static ssize_t smk_write_logging(struct file *file, const char __user *buf,
1357 size_t count, loff_t *ppos)
1358{
1359 char temp[32];
1360 int i;
1361
1362 if (!capable(CAP_MAC_ADMIN))
1363 return -EPERM;
1364
1365 if (count >= sizeof(temp) || count == 0)
1366 return -EINVAL;
1367
1368 if (copy_from_user(temp, buf, count) != 0)
1369 return -EFAULT;
1370
1371 temp[count] = '\0';
1372
1373 if (sscanf(temp, "%d", &i) != 1)
1374 return -EINVAL;
1375 if (i < 0 || i > 3)
1376 return -EINVAL;
1377 log_policy = i;
1378 return count;
1379}
1380
1381
1382
1383static const struct file_operations smk_logging_ops = {
1384 .read = smk_read_logging,
1385 .write = smk_write_logging,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001386 .llseek = default_llseek,
Etienne Bassetecfcc532009-04-08 20:40:06 +02001387};
Casey Schaufler7898e1f2011-01-17 08:05:27 -08001388
1389/*
1390 * Seq_file read operations for /smack/load-self
1391 */
1392
1393static void *load_self_seq_start(struct seq_file *s, loff_t *pos)
1394{
1395 struct task_smack *tsp = current_security();
1396
1397 if (*pos == SEQ_READ_FINISHED)
1398 return NULL;
1399 if (list_empty(&tsp->smk_rules))
1400 return NULL;
1401 return tsp->smk_rules.next;
1402}
1403
1404static void *load_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
1405{
1406 struct task_smack *tsp = current_security();
1407 struct list_head *list = v;
1408
1409 if (list_is_last(list, &tsp->smk_rules)) {
1410 *pos = SEQ_READ_FINISHED;
1411 return NULL;
1412 }
1413 return list->next;
1414}
1415
1416static int load_self_seq_show(struct seq_file *s, void *v)
1417{
1418 struct list_head *list = v;
1419 struct smack_rule *srp =
1420 list_entry(list, struct smack_rule, list);
1421
1422 seq_printf(s, "%s %s", (char *)srp->smk_subject,
1423 (char *)srp->smk_object);
1424
1425 seq_putc(s, ' ');
1426
1427 if (srp->smk_access & MAY_READ)
1428 seq_putc(s, 'r');
1429 if (srp->smk_access & MAY_WRITE)
1430 seq_putc(s, 'w');
1431 if (srp->smk_access & MAY_EXEC)
1432 seq_putc(s, 'x');
1433 if (srp->smk_access & MAY_APPEND)
1434 seq_putc(s, 'a');
1435 if (srp->smk_access & MAY_TRANSMUTE)
1436 seq_putc(s, 't');
1437 if (srp->smk_access == 0)
1438 seq_putc(s, '-');
1439
1440 seq_putc(s, '\n');
1441
1442 return 0;
1443}
1444
1445static void load_self_seq_stop(struct seq_file *s, void *v)
1446{
1447 /* No-op */
1448}
1449
1450static const struct seq_operations load_self_seq_ops = {
1451 .start = load_self_seq_start,
1452 .next = load_self_seq_next,
1453 .show = load_self_seq_show,
1454 .stop = load_self_seq_stop,
1455};
1456
1457
1458/**
1459 * smk_open_load_self - open() for /smack/load-self
1460 * @inode: inode structure representing file
1461 * @file: "load" file pointer
1462 *
1463 * For reading, use load_seq_* seq_file reading operations.
1464 */
1465static int smk_open_load_self(struct inode *inode, struct file *file)
1466{
1467 return seq_open(file, &load_self_seq_ops);
1468}
1469
1470/**
1471 * smk_write_load_self - write() for /smack/load-self
1472 * @file: file pointer, not actually used
1473 * @buf: where to get the data from
1474 * @count: bytes sent
1475 * @ppos: where to start - must be 0
1476 *
1477 */
1478static ssize_t smk_write_load_self(struct file *file, const char __user *buf,
1479 size_t count, loff_t *ppos)
1480{
1481 struct task_smack *tsp = current_security();
1482
1483 return smk_write_load_list(file, buf, count, ppos, &tsp->smk_rules,
1484 &tsp->smk_rules_lock);
1485}
1486
1487static const struct file_operations smk_load_self_ops = {
1488 .open = smk_open_load_self,
1489 .read = seq_read,
1490 .llseek = seq_lseek,
1491 .write = smk_write_load_self,
1492 .release = seq_release,
1493};
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001494
1495/**
1496 * smk_write_access - handle access check transaction
1497 * @file: file pointer
1498 * @buf: data from user space
1499 * @count: bytes sent
1500 * @ppos: where to start - must be 0
1501 */
1502static ssize_t smk_write_access(struct file *file, const char __user *buf,
1503 size_t count, loff_t *ppos)
1504{
1505 struct smack_rule rule;
1506 char *data;
1507
1508 if (!capable(CAP_MAC_ADMIN))
1509 return -EPERM;
1510
1511 data = simple_transaction_get(file, buf, count);
1512 if (IS_ERR(data))
1513 return PTR_ERR(data);
1514
1515 if (count < SMK_LOADLEN || smk_parse_rule(data, &rule))
1516 return -EINVAL;
1517
1518 data[0] = smk_access(rule.smk_subject, rule.smk_object,
1519 rule.smk_access, NULL) == 0;
1520
1521 simple_transaction_set(file, 1);
1522 return SMK_LOADLEN;
1523}
1524
1525static const struct file_operations smk_access_ops = {
1526 .write = smk_write_access,
1527 .read = simple_transaction_read,
1528 .release = simple_transaction_release,
1529 .llseek = generic_file_llseek,
1530};
1531
Etienne Bassetecfcc532009-04-08 20:40:06 +02001532/**
Casey Schauflere114e472008-02-04 22:29:50 -08001533 * smk_fill_super - fill the /smackfs superblock
1534 * @sb: the empty superblock
1535 * @data: unused
1536 * @silent: unused
1537 *
1538 * Fill in the well known entries for /smack
1539 *
1540 * Returns 0 on success, an error code on failure
1541 */
1542static int smk_fill_super(struct super_block *sb, void *data, int silent)
1543{
1544 int rc;
1545 struct inode *root_inode;
1546
1547 static struct tree_descr smack_files[] = {
Casey Schaufler7898e1f2011-01-17 08:05:27 -08001548 [SMK_LOAD] = {
1549 "load", &smk_load_ops, S_IRUGO|S_IWUSR},
1550 [SMK_CIPSO] = {
1551 "cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
1552 [SMK_DOI] = {
1553 "doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
1554 [SMK_DIRECT] = {
1555 "direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
1556 [SMK_AMBIENT] = {
1557 "ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
1558 [SMK_NETLBLADDR] = {
1559 "netlabel", &smk_netlbladdr_ops, S_IRUGO|S_IWUSR},
1560 [SMK_ONLYCAP] = {
1561 "onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
1562 [SMK_LOGGING] = {
1563 "logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
1564 [SMK_LOAD_SELF] = {
1565 "load-self", &smk_load_self_ops, S_IRUGO|S_IWUGO},
Jarkko Sakkinen828716c2011-09-08 10:12:01 +03001566 [SMK_ACCESSES] = {
1567 "access", &smk_access_ops, S_IRUGO|S_IWUSR},
Casey Schaufler7898e1f2011-01-17 08:05:27 -08001568 /* last one */
1569 {""}
Casey Schauflere114e472008-02-04 22:29:50 -08001570 };
1571
1572 rc = simple_fill_super(sb, SMACK_MAGIC, smack_files);
1573 if (rc != 0) {
1574 printk(KERN_ERR "%s failed %d while creating inodes\n",
1575 __func__, rc);
1576 return rc;
1577 }
1578
1579 root_inode = sb->s_root->d_inode;
1580 root_inode->i_security = new_inode_smack(smack_known_floor.smk_known);
1581
1582 return 0;
1583}
1584
1585/**
Al Virofc14f2f2010-07-25 01:48:30 +04001586 * smk_mount - get the smackfs superblock
Casey Schauflere114e472008-02-04 22:29:50 -08001587 * @fs_type: passed along without comment
1588 * @flags: passed along without comment
1589 * @dev_name: passed along without comment
1590 * @data: passed along without comment
Casey Schauflere114e472008-02-04 22:29:50 -08001591 *
1592 * Just passes everything along.
1593 *
1594 * Returns what the lower level code does.
1595 */
Al Virofc14f2f2010-07-25 01:48:30 +04001596static struct dentry *smk_mount(struct file_system_type *fs_type,
1597 int flags, const char *dev_name, void *data)
Casey Schauflere114e472008-02-04 22:29:50 -08001598{
Al Virofc14f2f2010-07-25 01:48:30 +04001599 return mount_single(fs_type, flags, data, smk_fill_super);
Casey Schauflere114e472008-02-04 22:29:50 -08001600}
1601
1602static struct file_system_type smk_fs_type = {
1603 .name = "smackfs",
Al Virofc14f2f2010-07-25 01:48:30 +04001604 .mount = smk_mount,
Casey Schauflere114e472008-02-04 22:29:50 -08001605 .kill_sb = kill_litter_super,
1606};
1607
1608static struct vfsmount *smackfs_mount;
1609
1610/**
1611 * init_smk_fs - get the smackfs superblock
1612 *
1613 * register the smackfs
1614 *
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +02001615 * Do not register smackfs if Smack wasn't enabled
1616 * on boot. We can not put this method normally under the
1617 * smack_init() code path since the security subsystem get
1618 * initialized before the vfs caches.
1619 *
1620 * Returns true if we were not chosen on boot or if
1621 * we were chosen and filesystem registration succeeded.
Casey Schauflere114e472008-02-04 22:29:50 -08001622 */
1623static int __init init_smk_fs(void)
1624{
1625 int err;
1626
Ahmed S. Darwish076c54c2008-03-06 18:09:10 +02001627 if (!security_module_enable(&smack_ops))
1628 return 0;
1629
Casey Schauflere114e472008-02-04 22:29:50 -08001630 err = register_filesystem(&smk_fs_type);
1631 if (!err) {
1632 smackfs_mount = kern_mount(&smk_fs_type);
1633 if (IS_ERR(smackfs_mount)) {
1634 printk(KERN_ERR "smackfs: could not mount!\n");
1635 err = PTR_ERR(smackfs_mount);
1636 smackfs_mount = NULL;
1637 }
1638 }
1639
Casey Schauflere114e472008-02-04 22:29:50 -08001640 smk_cipso_doi();
Casey Schaufler4bc87e62008-02-15 15:24:25 -08001641 smk_unlbl_ambient(NULL);
Casey Schauflere114e472008-02-04 22:29:50 -08001642
Casey Schaufler272cd7a2011-09-20 12:24:36 -07001643 mutex_init(&smack_known_floor.smk_rules_lock);
1644 mutex_init(&smack_known_hat.smk_rules_lock);
1645 mutex_init(&smack_known_huh.smk_rules_lock);
1646 mutex_init(&smack_known_invalid.smk_rules_lock);
1647 mutex_init(&smack_known_star.smk_rules_lock);
1648 mutex_init(&smack_known_web.smk_rules_lock);
1649
1650 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
1651 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
1652 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
1653 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
1654 INIT_LIST_HEAD(&smack_known_star.smk_rules);
1655 INIT_LIST_HEAD(&smack_known_web.smk_rules);
1656
Casey Schauflere114e472008-02-04 22:29:50 -08001657 return err;
1658}
1659
1660__initcall(init_smk_fs);