1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/xattr.h>
19#include <linux/pagemap.h>
20#include <linux/mount.h>
21#include <linux/stat.h>
22#include <linux/ext2_fs.h>
23#include <linux/kd.h>
24#include <asm/ioctls.h>
25#include <linux/ip.h>
26#include <linux/tcp.h>
27#include <linux/udp.h>
28#include <linux/mutex.h>
29#include <linux/pipe_fs_i.h>
30#include <net/netlabel.h>
31#include <net/cipso_ipv4.h>
32#include <linux/audit.h>
33#include <linux/magic.h>
34#include "smack.h"
35
36#define task_security(task) (task_cred_xxx((task), security))
37
38
39
40
41
42
43
44
45
46static char *smk_fetch(struct inode *ip, struct dentry *dp)
47{
48 int rc;
49 char in[SMK_LABELLEN];
50
51 if (ip->i_op->getxattr == NULL)
52 return NULL;
53
54 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
55 if (rc < 0)
56 return NULL;
57
58 return smk_import(in, rc);
59}
60
61
62
63
64
65
66
67struct inode_smack *new_inode_smack(char *smack)
68{
69 struct inode_smack *isp;
70
71 isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
72 if (isp == NULL)
73 return NULL;
74
75 isp->smk_inode = smack;
76 isp->smk_flags = 0;
77 mutex_init(&isp->smk_lock);
78
79 return isp;
80}
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96static int smack_ptrace_access_check(struct task_struct *ctp, unsigned int mode)
97{
98 int rc;
99 struct smk_audit_info ad;
100 char *sp, *tsp;
101
102 rc = cap_ptrace_access_check(ctp, mode);
103 if (rc != 0)
104 return rc;
105
106 sp = current_security();
107 tsp = task_security(ctp);
108 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
109 smk_ad_setfield_u_tsk(&ad, ctp);
110
111
112 rc = smk_access(sp, tsp, MAY_READWRITE, NULL);
113 if (rc != 0 && capable(CAP_MAC_OVERRIDE))
114 rc = 0;
115
116 smack_log(sp, tsp, MAY_READWRITE, rc, &ad);
117 return rc;
118}
119
120
121
122
123
124
125
126
127
128static int smack_ptrace_traceme(struct task_struct *ptp)
129{
130 int rc;
131 struct smk_audit_info ad;
132 char *sp, *tsp;
133
134 rc = cap_ptrace_traceme(ptp);
135 if (rc != 0)
136 return rc;
137
138 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
139 smk_ad_setfield_u_tsk(&ad, ptp);
140
141 sp = current_security();
142 tsp = task_security(ptp);
143
144 rc = smk_access(tsp, sp, MAY_READWRITE, NULL);
145 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
146 rc = 0;
147
148 smack_log(tsp, sp, MAY_READWRITE, rc, &ad);
149 return rc;
150}
151
152
153
154
155
156
157
158
159
160static int smack_syslog(int type)
161{
162 int rc;
163 char *sp = current_security();
164
165 rc = cap_syslog(type);
166 if (rc != 0)
167 return rc;
168
169 if (capable(CAP_MAC_OVERRIDE))
170 return 0;
171
172 if (sp != smack_known_floor.smk_known)
173 rc = -EACCES;
174
175 return rc;
176}
177
178
179
180
181
182
183
184
185
186
187
188
189static int smack_sb_alloc_security(struct super_block *sb)
190{
191 struct superblock_smack *sbsp;
192
193 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
194
195 if (sbsp == NULL)
196 return -ENOMEM;
197
198 sbsp->smk_root = smack_known_floor.smk_known;
199 sbsp->smk_default = smack_known_floor.smk_known;
200 sbsp->smk_floor = smack_known_floor.smk_known;
201 sbsp->smk_hat = smack_known_hat.smk_known;
202 sbsp->smk_initialized = 0;
203 spin_lock_init(&sbsp->smk_sblock);
204
205 sb->s_security = sbsp;
206
207 return 0;
208}
209
210
211
212
213
214
215static void smack_sb_free_security(struct super_block *sb)
216{
217 kfree(sb->s_security);
218 sb->s_security = NULL;
219}
220
221
222
223
224
225
226
227
228
229
230
231static int smack_sb_copy_data(char *orig, char *smackopts)
232{
233 char *cp, *commap, *otheropts, *dp;
234
235 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
236 if (otheropts == NULL)
237 return -ENOMEM;
238
239 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
240 if (strstr(cp, SMK_FSDEFAULT) == cp)
241 dp = smackopts;
242 else if (strstr(cp, SMK_FSFLOOR) == cp)
243 dp = smackopts;
244 else if (strstr(cp, SMK_FSHAT) == cp)
245 dp = smackopts;
246 else if (strstr(cp, SMK_FSROOT) == cp)
247 dp = smackopts;
248 else
249 dp = otheropts;
250
251 commap = strchr(cp, ',');
252 if (commap != NULL)
253 *commap = '\0';
254
255 if (*dp != '\0')
256 strcat(dp, ",");
257 strcat(dp, cp);
258 }
259
260 strcpy(orig, otheropts);
261 free_page((unsigned long)otheropts);
262
263 return 0;
264}
265
266
267
268
269
270
271
272
273
274static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
275{
276 struct dentry *root = sb->s_root;
277 struct inode *inode = root->d_inode;
278 struct superblock_smack *sp = sb->s_security;
279 struct inode_smack *isp;
280 char *op;
281 char *commap;
282 char *nsp;
283
284 spin_lock(&sp->smk_sblock);
285 if (sp->smk_initialized != 0) {
286 spin_unlock(&sp->smk_sblock);
287 return 0;
288 }
289 sp->smk_initialized = 1;
290 spin_unlock(&sp->smk_sblock);
291
292 for (op = data; op != NULL; op = commap) {
293 commap = strchr(op, ',');
294 if (commap != NULL)
295 *commap++ = '\0';
296
297 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
298 op += strlen(SMK_FSHAT);
299 nsp = smk_import(op, 0);
300 if (nsp != NULL)
301 sp->smk_hat = nsp;
302 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
303 op += strlen(SMK_FSFLOOR);
304 nsp = smk_import(op, 0);
305 if (nsp != NULL)
306 sp->smk_floor = nsp;
307 } else if (strncmp(op, SMK_FSDEFAULT,
308 strlen(SMK_FSDEFAULT)) == 0) {
309 op += strlen(SMK_FSDEFAULT);
310 nsp = smk_import(op, 0);
311 if (nsp != NULL)
312 sp->smk_default = nsp;
313 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
314 op += strlen(SMK_FSROOT);
315 nsp = smk_import(op, 0);
316 if (nsp != NULL)
317 sp->smk_root = nsp;
318 }
319 }
320
321
322
323
324 isp = inode->i_security;
325 if (isp == NULL)
326 inode->i_security = new_inode_smack(sp->smk_root);
327 else
328 isp->smk_inode = sp->smk_root;
329
330 return 0;
331}
332
333
334
335
336
337
338
339
340static int smack_sb_statfs(struct dentry *dentry)
341{
342 struct superblock_smack *sbp = dentry->d_sb->s_security;
343 int rc;
344 struct smk_audit_info ad;
345
346 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
347 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
348
349 rc = smk_curacc(sbp->smk_floor, MAY_READ, &ad);
350 return rc;
351}
352
353
354
355
356
357
358
359
360
361
362
363
364static int smack_sb_mount(char *dev_name, struct path *path,
365 char *type, unsigned long flags, void *data)
366{
367 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
368 struct smk_audit_info ad;
369
370 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
371 smk_ad_setfield_u_fs_path(&ad, *path);
372
373 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
374}
375
376
377
378
379
380
381
382
383
384static int smack_sb_umount(struct vfsmount *mnt, int flags)
385{
386 struct superblock_smack *sbp;
387 struct smk_audit_info ad;
388
389 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
390 smk_ad_setfield_u_fs_path_dentry(&ad, mnt->mnt_mountpoint);
391 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
392
393 sbp = mnt->mnt_sb->s_security;
394 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
395}
396
397
398
399
400
401
402
403
404
405
406
407static int smack_inode_alloc_security(struct inode *inode)
408{
409 inode->i_security = new_inode_smack(current_security());
410 if (inode->i_security == NULL)
411 return -ENOMEM;
412 return 0;
413}
414
415
416
417
418
419
420
421static void smack_inode_free_security(struct inode *inode)
422{
423 kfree(inode->i_security);
424 inode->i_security = NULL;
425}
426
427
428
429
430
431
432
433
434
435
436
437static int smack_inode_init_security(struct inode *inode, struct inode *dir,
438 char **name, void **value, size_t *len)
439{
440 char *isp = smk_of_inode(inode);
441
442 if (name) {
443 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
444 if (*name == NULL)
445 return -ENOMEM;
446 }
447
448 if (value) {
449 *value = kstrdup(isp, GFP_KERNEL);
450 if (*value == NULL)
451 return -ENOMEM;
452 }
453
454 if (len)
455 *len = strlen(isp) + 1;
456
457 return 0;
458}
459
460
461
462
463
464
465
466
467
468static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
469 struct dentry *new_dentry)
470{
471 char *isp;
472 struct smk_audit_info ad;
473 int rc;
474
475 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
476 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
477
478 isp = smk_of_inode(old_dentry->d_inode);
479 rc = smk_curacc(isp, MAY_WRITE, &ad);
480
481 if (rc == 0 && new_dentry->d_inode != NULL) {
482 isp = smk_of_inode(new_dentry->d_inode);
483 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
484 rc = smk_curacc(isp, MAY_WRITE, &ad);
485 }
486
487 return rc;
488}
489
490
491
492
493
494
495
496
497
498static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
499{
500 struct inode *ip = dentry->d_inode;
501 struct smk_audit_info ad;
502 int rc;
503
504 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
505 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
506
507
508
509
510 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE, &ad);
511 if (rc == 0) {
512
513
514
515 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
516 smk_ad_setfield_u_fs_inode(&ad, dir);
517 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
518 }
519 return rc;
520}
521
522
523
524
525
526
527
528
529
530static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
531{
532 struct smk_audit_info ad;
533 int rc;
534
535 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
536 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
537
538
539
540
541 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
542 if (rc == 0) {
543
544
545
546 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
547 smk_ad_setfield_u_fs_inode(&ad, dir);
548 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
549 }
550
551 return rc;
552}
553
554
555
556
557
558
559
560
561
562
563
564
565
566static int smack_inode_rename(struct inode *old_inode,
567 struct dentry *old_dentry,
568 struct inode *new_inode,
569 struct dentry *new_dentry)
570{
571 int rc;
572 char *isp;
573 struct smk_audit_info ad;
574
575 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
576 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
577
578 isp = smk_of_inode(old_dentry->d_inode);
579 rc = smk_curacc(isp, MAY_READWRITE, &ad);
580
581 if (rc == 0 && new_dentry->d_inode != NULL) {
582 isp = smk_of_inode(new_dentry->d_inode);
583 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
584 rc = smk_curacc(isp, MAY_READWRITE, &ad);
585 }
586 return rc;
587}
588
589
590
591
592
593
594
595
596
597
598static int smack_inode_permission(struct inode *inode, int mask)
599{
600 struct smk_audit_info ad;
601
602
603
604 if (mask == 0)
605 return 0;
606 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
607 smk_ad_setfield_u_fs_inode(&ad, inode);
608 return smk_curacc(smk_of_inode(inode), mask, &ad);
609}
610
611
612
613
614
615
616
617
618static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
619{
620 struct smk_audit_info ad;
621
622
623
624 if (iattr->ia_valid & ATTR_FORCE)
625 return 0;
626 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
627 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
628
629 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
630}
631
632
633
634
635
636
637
638
639static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
640{
641 struct smk_audit_info ad;
642
643 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
644 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
645 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
646 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
647}
648
649
650
651
652
653
654
655
656
657
658
659
660
661static int smack_inode_setxattr(struct dentry *dentry, const char *name,
662 const void *value, size_t size, int flags)
663{
664 struct smk_audit_info ad;
665 int rc = 0;
666
667 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
668 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
669 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
670 if (!capable(CAP_MAC_ADMIN))
671 rc = -EPERM;
672
673
674
675
676 if (size == 0 || size >= SMK_LABELLEN ||
677 smk_import(value, size) == NULL)
678 rc = -EINVAL;
679 } else
680 rc = cap_inode_setxattr(dentry, name, value, size, flags);
681
682 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
683 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
684
685 if (rc == 0)
686 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
687
688 return rc;
689}
690
691
692
693
694
695
696
697
698
699
700
701
702static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
703 const void *value, size_t size, int flags)
704{
705 struct inode_smack *isp;
706 char *nsp;
707
708
709
710
711 if (strcmp(name, XATTR_NAME_SMACK))
712 return;
713
714 isp = dentry->d_inode->i_security;
715
716
717
718
719
720 nsp = smk_import(value, size);
721 if (nsp != NULL)
722 isp->smk_inode = nsp;
723 else
724 isp->smk_inode = smack_known_invalid.smk_known;
725
726 return;
727}
728
729
730
731
732
733
734
735
736static int smack_inode_getxattr(struct dentry *dentry, const char *name)
737{
738 struct smk_audit_info ad;
739
740 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
741 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
742
743 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
744}
745
746
747
748
749
750
751
752
753
754
755static int smack_inode_removexattr(struct dentry *dentry, const char *name)
756{
757 struct smk_audit_info ad;
758 int rc = 0;
759
760 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
761 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
762 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
763 if (!capable(CAP_MAC_ADMIN))
764 rc = -EPERM;
765 } else
766 rc = cap_inode_removexattr(dentry, name);
767
768 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
769 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
770 if (rc == 0)
771 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
772
773 return rc;
774}
775
776
777
778
779
780
781
782
783
784
785static int smack_inode_getsecurity(const struct inode *inode,
786 const char *name, void **buffer,
787 bool alloc)
788{
789 struct socket_smack *ssp;
790 struct socket *sock;
791 struct super_block *sbp;
792 struct inode *ip = (struct inode *)inode;
793 char *isp;
794 int ilen;
795 int rc = 0;
796
797 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
798 isp = smk_of_inode(inode);
799 ilen = strlen(isp) + 1;
800 *buffer = isp;
801 return ilen;
802 }
803
804
805
806
807 sbp = ip->i_sb;
808 if (sbp->s_magic != SOCKFS_MAGIC)
809 return -EOPNOTSUPP;
810
811 sock = SOCKET_I(ip);
812 if (sock == NULL || sock->sk == NULL)
813 return -EOPNOTSUPP;
814
815 ssp = sock->sk->sk_security;
816
817 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
818 isp = ssp->smk_in;
819 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
820 isp = ssp->smk_out;
821 else
822 return -EOPNOTSUPP;
823
824 ilen = strlen(isp) + 1;
825 if (rc == 0) {
826 *buffer = isp;
827 rc = ilen;
828 }
829
830 return rc;
831}
832
833
834
835
836
837
838
839
840
841
842static int smack_inode_listsecurity(struct inode *inode, char *buffer,
843 size_t buffer_size)
844{
845 int len = strlen(XATTR_NAME_SMACK);
846
847 if (buffer != NULL && len <= buffer_size) {
848 memcpy(buffer, XATTR_NAME_SMACK, len);
849 return len;
850 }
851 return -EINVAL;
852}
853
854
855
856
857
858
859static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
860{
861 struct inode_smack *isp = inode->i_security;
862
863 *secid = smack_to_secid(isp->smk_inode);
864}
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884static int smack_file_permission(struct file *file, int mask)
885{
886 return 0;
887}
888
889
890
891
892
893
894
895
896
897
898static int smack_file_alloc_security(struct file *file)
899{
900 file->f_security = current_security();
901 return 0;
902}
903
904
905
906
907
908
909
910
911static void smack_file_free_security(struct file *file)
912{
913 file->f_security = NULL;
914}
915
916
917
918
919
920
921
922
923
924
925
926static int smack_file_ioctl(struct file *file, unsigned int cmd,
927 unsigned long arg)
928{
929 int rc = 0;
930 struct smk_audit_info ad;
931
932 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
933 smk_ad_setfield_u_fs_path(&ad, file->f_path);
934
935 if (_IOC_DIR(cmd) & _IOC_WRITE)
936 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
937
938 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
939 rc = smk_curacc(file->f_security, MAY_READ, &ad);
940
941 return rc;
942}
943
944
945
946
947
948
949
950
951static int smack_file_lock(struct file *file, unsigned int cmd)
952{
953 struct smk_audit_info ad;
954
955 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
956 smk_ad_setfield_u_fs_path_dentry(&ad, file->f_path.dentry);
957 return smk_curacc(file->f_security, MAY_WRITE, &ad);
958}
959
960
961
962
963
964
965
966
967
968static int smack_file_fcntl(struct file *file, unsigned int cmd,
969 unsigned long arg)
970{
971 struct smk_audit_info ad;
972 int rc;
973
974 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
975 smk_ad_setfield_u_fs_path(&ad, file->f_path);
976
977 switch (cmd) {
978 case F_DUPFD:
979 case F_GETFD:
980 case F_GETFL:
981 case F_GETLK:
982 case F_GETOWN:
983 case F_GETSIG:
984 rc = smk_curacc(file->f_security, MAY_READ, &ad);
985 break;
986 case F_SETFD:
987 case F_SETFL:
988 case F_SETLK:
989 case F_SETLKW:
990 case F_SETOWN:
991 case F_SETSIG:
992 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
993 break;
994 default:
995 rc = smk_curacc(file->f_security, MAY_READWRITE, &ad);
996 }
997
998 return rc;
999}
1000
1001
1002
1003
1004
1005
1006
1007
1008static int smack_file_set_fowner(struct file *file)
1009{
1010 file->f_security = current_security();
1011 return 0;
1012}
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025static int smack_file_send_sigiotask(struct task_struct *tsk,
1026 struct fown_struct *fown, int signum)
1027{
1028 struct file *file;
1029 int rc;
1030 char *tsp = tsk->cred->security;
1031 struct smk_audit_info ad;
1032
1033
1034
1035
1036 file = container_of(fown, struct file, f_owner);
1037
1038 rc = smk_access(file->f_security, tsp, MAY_WRITE, NULL);
1039 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
1040 rc = 0;
1041
1042 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1043 smk_ad_setfield_u_tsk(&ad, tsk);
1044 smack_log(file->f_security, tsp, MAY_WRITE, rc, &ad);
1045 return rc;
1046}
1047
1048
1049
1050
1051
1052
1053
1054static int smack_file_receive(struct file *file)
1055{
1056 int may = 0;
1057 struct smk_audit_info ad;
1058
1059 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1060 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1061
1062
1063
1064 if (file->f_mode & FMODE_READ)
1065 may = MAY_READ;
1066 if (file->f_mode & FMODE_WRITE)
1067 may |= MAY_WRITE;
1068
1069 return smk_curacc(file->f_security, may, &ad);
1070}
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1086{
1087 cred->security = NULL;
1088 return 0;
1089}
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100static void smack_cred_free(struct cred *cred)
1101{
1102 cred->security = NULL;
1103}
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113static int smack_cred_prepare(struct cred *new, const struct cred *old,
1114 gfp_t gfp)
1115{
1116 new->security = old->security;
1117 return 0;
1118}
1119
1120
1121
1122
1123
1124
1125static void smack_cred_commit(struct cred *new, const struct cred *old)
1126{
1127}
1128
1129
1130
1131
1132
1133
1134
1135
1136static void smack_cred_transfer(struct cred *new, const struct cred *old)
1137{
1138 new->security = old->security;
1139}
1140
1141
1142
1143
1144
1145
1146
1147
1148static int smack_kernel_act_as(struct cred *new, u32 secid)
1149{
1150 char *smack = smack_from_secid(secid);
1151
1152 if (smack == NULL)
1153 return -EINVAL;
1154
1155 new->security = smack;
1156 return 0;
1157}
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167static int smack_kernel_create_files_as(struct cred *new,
1168 struct inode *inode)
1169{
1170 struct inode_smack *isp = inode->i_security;
1171
1172 new->security = isp->smk_inode;
1173 return 0;
1174}
1175
1176
1177
1178
1179
1180
1181
1182
1183static int smk_curacc_on_task(struct task_struct *p, int access)
1184{
1185 struct smk_audit_info ad;
1186
1187 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1188 smk_ad_setfield_u_tsk(&ad, p);
1189 return smk_curacc(task_security(p), access, &ad);
1190}
1191
1192
1193
1194
1195
1196
1197
1198
1199static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1200{
1201 return smk_curacc_on_task(p, MAY_WRITE);
1202}
1203
1204
1205
1206
1207
1208
1209
1210static int smack_task_getpgid(struct task_struct *p)
1211{
1212 return smk_curacc_on_task(p, MAY_READ);
1213}
1214
1215
1216
1217
1218
1219
1220
1221static int smack_task_getsid(struct task_struct *p)
1222{
1223 return smk_curacc_on_task(p, MAY_READ);
1224}
1225
1226
1227
1228
1229
1230
1231
1232
1233static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1234{
1235 *secid = smack_to_secid(task_security(p));
1236}
1237
1238
1239
1240
1241
1242
1243
1244
1245static int smack_task_setnice(struct task_struct *p, int nice)
1246{
1247 int rc;
1248
1249 rc = cap_task_setnice(p, nice);
1250 if (rc == 0)
1251 rc = smk_curacc_on_task(p, MAY_WRITE);
1252 return rc;
1253}
1254
1255
1256
1257
1258
1259
1260
1261
1262static int smack_task_setioprio(struct task_struct *p, int ioprio)
1263{
1264 int rc;
1265
1266 rc = cap_task_setioprio(p, ioprio);
1267 if (rc == 0)
1268 rc = smk_curacc_on_task(p, MAY_WRITE);
1269 return rc;
1270}
1271
1272
1273
1274
1275
1276
1277
1278static int smack_task_getioprio(struct task_struct *p)
1279{
1280 return smk_curacc_on_task(p, MAY_READ);
1281}
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291static int smack_task_setscheduler(struct task_struct *p, int policy,
1292 struct sched_param *lp)
1293{
1294 int rc;
1295
1296 rc = cap_task_setscheduler(p, policy, lp);
1297 if (rc == 0)
1298 rc = smk_curacc_on_task(p, MAY_WRITE);
1299 return rc;
1300}
1301
1302
1303
1304
1305
1306
1307
1308static int smack_task_getscheduler(struct task_struct *p)
1309{
1310 return smk_curacc_on_task(p, MAY_READ);
1311}
1312
1313
1314
1315
1316
1317
1318
1319static int smack_task_movememory(struct task_struct *p)
1320{
1321 return smk_curacc_on_task(p, MAY_WRITE);
1322}
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1337 int sig, u32 secid)
1338{
1339 struct smk_audit_info ad;
1340
1341 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1342 smk_ad_setfield_u_tsk(&ad, p);
1343
1344
1345
1346
1347 if (secid == 0)
1348 return smk_curacc(task_security(p), MAY_WRITE, &ad);
1349
1350
1351
1352
1353
1354 return smk_access(smack_from_secid(secid), task_security(p),
1355 MAY_WRITE, &ad);
1356}
1357
1358
1359
1360
1361
1362
1363
1364static int smack_task_wait(struct task_struct *p)
1365{
1366 struct smk_audit_info ad;
1367 char *sp = current_security();
1368 char *tsp = task_security(p);
1369 int rc;
1370
1371
1372 rc = smk_access(sp, tsp, MAY_WRITE, NULL);
1373 if (rc == 0)
1374 goto out_log;
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1388 rc = 0;
1389
1390 out_log:
1391 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1392 smk_ad_setfield_u_tsk(&ad, p);
1393 smack_log(sp, tsp, MAY_WRITE, rc, &ad);
1394 return rc;
1395}
1396
1397
1398
1399
1400
1401
1402
1403
1404static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1405{
1406 struct inode_smack *isp = inode->i_security;
1407 isp->smk_inode = task_security(p);
1408}
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1425{
1426 char *csp = current_security();
1427 struct socket_smack *ssp;
1428
1429 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1430 if (ssp == NULL)
1431 return -ENOMEM;
1432
1433 ssp->smk_in = csp;
1434 ssp->smk_out = csp;
1435 ssp->smk_packet[0] = '\0';
1436
1437 sk->sk_security = ssp;
1438
1439 return 0;
1440}
1441
1442
1443
1444
1445
1446
1447
1448static void smack_sk_free_security(struct sock *sk)
1449{
1450 kfree(sk->sk_security);
1451}
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465static char *smack_host_label(struct sockaddr_in *sip)
1466{
1467 struct smk_netlbladdr *snp;
1468 struct in_addr *siap = &sip->sin_addr;
1469
1470 if (siap->s_addr == 0)
1471 return NULL;
1472
1473 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1474
1475
1476
1477
1478
1479 if ((&snp->smk_host.sin_addr)->s_addr ==
1480 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1481
1482 if (snp->smk_label == smack_cipso_option)
1483 return NULL;
1484 return snp->smk_label;
1485 }
1486
1487 return NULL;
1488}
1489
1490
1491
1492
1493
1494
1495
1496
1497static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1498{
1499 unsigned char *cp;
1500 unsigned char m;
1501 int cat;
1502 int rc;
1503 int byte;
1504
1505 if (!catset)
1506 return;
1507
1508 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1509 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1510 sap->attr.mls.cat->startbit = 0;
1511
1512 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1513 for (m = 0x80; m != 0; m >>= 1, cat++) {
1514 if ((m & *cp) == 0)
1515 continue;
1516 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1517 cat, GFP_ATOMIC);
1518 }
1519}
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1532{
1533 struct smack_cipso cipso;
1534 int rc;
1535
1536 nlsp->domain = smack;
1537 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1538
1539 rc = smack_to_cipso(smack, &cipso);
1540 if (rc == 0) {
1541 nlsp->attr.mls.lvl = cipso.smk_level;
1542 smack_set_catset(cipso.smk_catset, nlsp);
1543 } else {
1544 nlsp->attr.mls.lvl = smack_cipso_direct;
1545 smack_set_catset(smack, nlsp);
1546 }
1547}
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559static int smack_netlabel(struct sock *sk, int labeled)
1560{
1561 struct socket_smack *ssp = sk->sk_security;
1562 struct netlbl_lsm_secattr secattr;
1563 int rc = 0;
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573 local_bh_disable();
1574 bh_lock_sock_nested(sk);
1575
1576 if (ssp->smk_out == smack_net_ambient ||
1577 labeled == SMACK_UNLABELED_SOCKET)
1578 netlbl_sock_delattr(sk);
1579 else {
1580 netlbl_secattr_init(&secattr);
1581 smack_to_secattr(ssp->smk_out, &secattr);
1582 rc = netlbl_sock_setattr(sk, sk->sk_family, &secattr);
1583 netlbl_secattr_destroy(&secattr);
1584 }
1585
1586 bh_unlock_sock(sk);
1587 local_bh_enable();
1588
1589 return rc;
1590}
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1604{
1605 int rc;
1606 int sk_lbl;
1607 char *hostsp;
1608 struct socket_smack *ssp = sk->sk_security;
1609 struct smk_audit_info ad;
1610
1611 rcu_read_lock();
1612 hostsp = smack_host_label(sap);
1613 if (hostsp != NULL) {
1614 sk_lbl = SMACK_UNLABELED_SOCKET;
1615#ifdef CONFIG_AUDIT
1616 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
1617 ad.a.u.net.family = sap->sin_family;
1618 ad.a.u.net.dport = sap->sin_port;
1619 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr;
1620#endif
1621 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1622 } else {
1623 sk_lbl = SMACK_CIPSO_SOCKET;
1624 rc = 0;
1625 }
1626 rcu_read_unlock();
1627 if (rc != 0)
1628 return rc;
1629
1630 return smack_netlabel(sk, sk_lbl);
1631}
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645static int smack_inode_setsecurity(struct inode *inode, const char *name,
1646 const void *value, size_t size, int flags)
1647{
1648 char *sp;
1649 struct inode_smack *nsp = inode->i_security;
1650 struct socket_smack *ssp;
1651 struct socket *sock;
1652 int rc = 0;
1653
1654 if (value == NULL || size > SMK_LABELLEN || size == 0)
1655 return -EACCES;
1656
1657 sp = smk_import(value, size);
1658 if (sp == NULL)
1659 return -EINVAL;
1660
1661 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1662 nsp->smk_inode = sp;
1663 nsp->smk_flags |= SMK_INODE_INSTANT;
1664 return 0;
1665 }
1666
1667
1668
1669 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1670 return -EOPNOTSUPP;
1671
1672 sock = SOCKET_I(inode);
1673 if (sock == NULL || sock->sk == NULL)
1674 return -EOPNOTSUPP;
1675
1676 ssp = sock->sk->sk_security;
1677
1678 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1679 ssp->smk_in = sp;
1680 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1681 ssp->smk_out = sp;
1682 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1683 if (rc != 0)
1684 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
1685 __func__, -rc);
1686 } else
1687 return -EOPNOTSUPP;
1688
1689 return 0;
1690}
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704static int smack_socket_post_create(struct socket *sock, int family,
1705 int type, int protocol, int kern)
1706{
1707 if (family != PF_INET || sock->sk == NULL)
1708 return 0;
1709
1710
1711
1712 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1713}
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
1726 int addrlen)
1727{
1728 if (sock->sk == NULL || sock->sk->sk_family != PF_INET)
1729 return 0;
1730 if (addrlen < sizeof(struct sockaddr_in))
1731 return -EINVAL;
1732
1733 return smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
1734}
1735
1736
1737
1738
1739
1740
1741
1742static int smack_flags_to_may(int flags)
1743{
1744 int may = 0;
1745
1746 if (flags & S_IRUGO)
1747 may |= MAY_READ;
1748 if (flags & S_IWUGO)
1749 may |= MAY_WRITE;
1750 if (flags & S_IXUGO)
1751 may |= MAY_EXEC;
1752
1753 return may;
1754}
1755
1756
1757
1758
1759
1760
1761
1762static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1763{
1764 msg->security = current_security();
1765 return 0;
1766}
1767
1768
1769
1770
1771
1772
1773
1774static void smack_msg_msg_free_security(struct msg_msg *msg)
1775{
1776 msg->security = NULL;
1777}
1778
1779
1780
1781
1782
1783
1784
1785static char *smack_of_shm(struct shmid_kernel *shp)
1786{
1787 return (char *)shp->shm_perm.security;
1788}
1789
1790
1791
1792
1793
1794
1795
1796static int smack_shm_alloc_security(struct shmid_kernel *shp)
1797{
1798 struct kern_ipc_perm *isp = &shp->shm_perm;
1799
1800 isp->security = current_security();
1801 return 0;
1802}
1803
1804
1805
1806
1807
1808
1809
1810static void smack_shm_free_security(struct shmid_kernel *shp)
1811{
1812 struct kern_ipc_perm *isp = &shp->shm_perm;
1813
1814 isp->security = NULL;
1815}
1816
1817
1818
1819
1820
1821
1822
1823
1824static int smk_curacc_shm(struct shmid_kernel *shp, int access)
1825{
1826 char *ssp = smack_of_shm(shp);
1827 struct smk_audit_info ad;
1828
1829#ifdef CONFIG_AUDIT
1830 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1831 ad.a.u.ipc_id = shp->shm_perm.id;
1832#endif
1833 return smk_curacc(ssp, access, &ad);
1834}
1835
1836
1837
1838
1839
1840
1841
1842
1843static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1844{
1845 int may;
1846
1847 may = smack_flags_to_may(shmflg);
1848 return smk_curacc_shm(shp, may);
1849}
1850
1851
1852
1853
1854
1855
1856
1857
1858static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1859{
1860 int may;
1861
1862 switch (cmd) {
1863 case IPC_STAT:
1864 case SHM_STAT:
1865 may = MAY_READ;
1866 break;
1867 case IPC_SET:
1868 case SHM_LOCK:
1869 case SHM_UNLOCK:
1870 case IPC_RMID:
1871 may = MAY_READWRITE;
1872 break;
1873 case IPC_INFO:
1874 case SHM_INFO:
1875
1876
1877
1878 return 0;
1879 default:
1880 return -EINVAL;
1881 }
1882 return smk_curacc_shm(shp, may);
1883}
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1894 int shmflg)
1895{
1896 int may;
1897
1898 may = smack_flags_to_may(shmflg);
1899 return smk_curacc_shm(shp, may);
1900}
1901
1902
1903
1904
1905
1906
1907
1908static char *smack_of_sem(struct sem_array *sma)
1909{
1910 return (char *)sma->sem_perm.security;
1911}
1912
1913
1914
1915
1916
1917
1918
1919static int smack_sem_alloc_security(struct sem_array *sma)
1920{
1921 struct kern_ipc_perm *isp = &sma->sem_perm;
1922
1923 isp->security = current_security();
1924 return 0;
1925}
1926
1927
1928
1929
1930
1931
1932
1933static void smack_sem_free_security(struct sem_array *sma)
1934{
1935 struct kern_ipc_perm *isp = &sma->sem_perm;
1936
1937 isp->security = NULL;
1938}
1939
1940
1941
1942
1943
1944
1945
1946
1947static int smk_curacc_sem(struct sem_array *sma, int access)
1948{
1949 char *ssp = smack_of_sem(sma);
1950 struct smk_audit_info ad;
1951
1952#ifdef CONFIG_AUDIT
1953 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1954 ad.a.u.ipc_id = sma->sem_perm.id;
1955#endif
1956 return smk_curacc(ssp, access, &ad);
1957}
1958
1959
1960
1961
1962
1963
1964
1965
1966static int smack_sem_associate(struct sem_array *sma, int semflg)
1967{
1968 int may;
1969
1970 may = smack_flags_to_may(semflg);
1971 return smk_curacc_sem(sma, may);
1972}
1973
1974
1975
1976
1977
1978
1979
1980
1981static int smack_sem_semctl(struct sem_array *sma, int cmd)
1982{
1983 int may;
1984
1985 switch (cmd) {
1986 case GETPID:
1987 case GETNCNT:
1988 case GETZCNT:
1989 case GETVAL:
1990 case GETALL:
1991 case IPC_STAT:
1992 case SEM_STAT:
1993 may = MAY_READ;
1994 break;
1995 case SETVAL:
1996 case SETALL:
1997 case IPC_RMID:
1998 case IPC_SET:
1999 may = MAY_READWRITE;
2000 break;
2001 case IPC_INFO:
2002 case SEM_INFO:
2003
2004
2005
2006 return 0;
2007 default:
2008 return -EINVAL;
2009 }
2010
2011 return smk_curacc_sem(sma, may);
2012}
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2026 unsigned nsops, int alter)
2027{
2028 return smk_curacc_sem(sma, MAY_READWRITE);
2029}
2030
2031
2032
2033
2034
2035
2036
2037static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2038{
2039 struct kern_ipc_perm *kisp = &msq->q_perm;
2040
2041 kisp->security = current_security();
2042 return 0;
2043}
2044
2045
2046
2047
2048
2049
2050
2051static void smack_msg_queue_free_security(struct msg_queue *msq)
2052{
2053 struct kern_ipc_perm *kisp = &msq->q_perm;
2054
2055 kisp->security = NULL;
2056}
2057
2058
2059
2060
2061
2062
2063
2064static char *smack_of_msq(struct msg_queue *msq)
2065{
2066 return (char *)msq->q_perm.security;
2067}
2068
2069
2070
2071
2072
2073
2074
2075
2076static int smk_curacc_msq(struct msg_queue *msq, int access)
2077{
2078 char *msp = smack_of_msq(msq);
2079 struct smk_audit_info ad;
2080
2081#ifdef CONFIG_AUDIT
2082 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2083 ad.a.u.ipc_id = msq->q_perm.id;
2084#endif
2085 return smk_curacc(msp, access, &ad);
2086}
2087
2088
2089
2090
2091
2092
2093
2094
2095static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2096{
2097 int may;
2098
2099 may = smack_flags_to_may(msqflg);
2100 return smk_curacc_msq(msq, may);
2101}
2102
2103
2104
2105
2106
2107
2108
2109
2110static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2111{
2112 int may;
2113
2114 switch (cmd) {
2115 case IPC_STAT:
2116 case MSG_STAT:
2117 may = MAY_READ;
2118 break;
2119 case IPC_SET:
2120 case IPC_RMID:
2121 may = MAY_READWRITE;
2122 break;
2123 case IPC_INFO:
2124 case MSG_INFO:
2125
2126
2127
2128 return 0;
2129 default:
2130 return -EINVAL;
2131 }
2132
2133 return smk_curacc_msq(msq, may);
2134}
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2145 int msqflg)
2146{
2147 int may;
2148
2149 may = smack_flags_to_may(msqflg);
2150 return smk_curacc_msq(msq, may);
2151}
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2164 struct task_struct *target, long type, int mode)
2165{
2166 return smk_curacc_msq(msq, MAY_READWRITE);
2167}
2168
2169
2170
2171
2172
2173
2174
2175
2176static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2177{
2178 char *isp = ipp->security;
2179 int may = smack_flags_to_may(flag);
2180 struct smk_audit_info ad;
2181
2182#ifdef CONFIG_AUDIT
2183 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2184 ad.a.u.ipc_id = ipp->id;
2185#endif
2186 return smk_curacc(isp, may, &ad);
2187}
2188
2189
2190
2191
2192
2193
2194static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2195{
2196 char *smack = ipp->security;
2197
2198 *secid = smack_to_secid(smack);
2199}
2200
2201
2202
2203
2204
2205
2206
2207
2208static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2209{
2210 struct super_block *sbp;
2211 struct superblock_smack *sbsp;
2212 struct inode_smack *isp;
2213 char *csp = current_security();
2214 char *fetched;
2215 char *final;
2216 struct dentry *dp;
2217
2218 if (inode == NULL)
2219 return;
2220
2221 isp = inode->i_security;
2222
2223 mutex_lock(&isp->smk_lock);
2224
2225
2226
2227
2228 if (isp->smk_flags & SMK_INODE_INSTANT)
2229 goto unlockandout;
2230
2231 sbp = inode->i_sb;
2232 sbsp = sbp->s_security;
2233
2234
2235
2236
2237 final = sbsp->smk_default;
2238
2239
2240
2241
2242
2243
2244
2245 if (opt_dentry->d_parent == opt_dentry) {
2246 isp->smk_inode = sbsp->smk_root;
2247 isp->smk_flags |= SMK_INODE_INSTANT;
2248 goto unlockandout;
2249 }
2250
2251
2252
2253
2254
2255
2256
2257 switch (sbp->s_magic) {
2258 case SMACK_MAGIC:
2259
2260
2261
2262
2263
2264 final = smack_known_star.smk_known;
2265 break;
2266 case PIPEFS_MAGIC:
2267
2268
2269
2270 final = smack_known_star.smk_known;
2271 break;
2272 case DEVPTS_SUPER_MAGIC:
2273
2274
2275
2276
2277
2278 final = csp;
2279 break;
2280 case SOCKFS_MAGIC:
2281
2282
2283
2284 final = csp;
2285 break;
2286 case PROC_SUPER_MAGIC:
2287
2288
2289
2290
2291 break;
2292 case TMPFS_MAGIC:
2293
2294
2295
2296
2297
2298 final = smack_known_star.smk_known;
2299
2300
2301
2302
2303
2304
2305
2306
2307 default:
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317 if (inode->i_op->getxattr == NULL)
2318 break;
2319
2320
2321
2322 if (opt_dentry == NULL) {
2323 dp = d_find_alias(inode);
2324 if (dp == NULL)
2325 break;
2326 } else {
2327 dp = dget(opt_dentry);
2328 if (dp == NULL)
2329 break;
2330 }
2331
2332 fetched = smk_fetch(inode, dp);
2333 if (fetched != NULL)
2334 final = fetched;
2335
2336 dput(dp);
2337 break;
2338 }
2339
2340 if (final == NULL)
2341 isp->smk_inode = csp;
2342 else
2343 isp->smk_inode = final;
2344
2345 isp->smk_flags |= SMK_INODE_INSTANT;
2346
2347unlockandout:
2348 mutex_unlock(&isp->smk_lock);
2349 return;
2350}
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2363{
2364 char *cp;
2365 int slen;
2366
2367 if (strcmp(name, "current") != 0)
2368 return -EINVAL;
2369
2370 cp = kstrdup(task_security(p), GFP_KERNEL);
2371 if (cp == NULL)
2372 return -ENOMEM;
2373
2374 slen = strlen(cp);
2375 *value = cp;
2376 return slen;
2377}
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391static int smack_setprocattr(struct task_struct *p, char *name,
2392 void *value, size_t size)
2393{
2394 struct cred *new;
2395 char *newsmack;
2396
2397
2398
2399
2400
2401 if (p != current)
2402 return -EPERM;
2403
2404 if (!capable(CAP_MAC_ADMIN))
2405 return -EPERM;
2406
2407 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2408 return -EINVAL;
2409
2410 if (strcmp(name, "current") != 0)
2411 return -EINVAL;
2412
2413 newsmack = smk_import(value, size);
2414 if (newsmack == NULL)
2415 return -EINVAL;
2416
2417
2418
2419
2420 if (newsmack == smack_known_web.smk_known)
2421 return -EPERM;
2422
2423 new = prepare_creds();
2424 if (new == NULL)
2425 return -ENOMEM;
2426 new->security = newsmack;
2427 commit_creds(new);
2428 return size;
2429}
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440static int smack_unix_stream_connect(struct socket *sock,
2441 struct socket *other, struct sock *newsk)
2442{
2443 struct inode *sp = SOCK_INODE(sock);
2444 struct inode *op = SOCK_INODE(other);
2445 struct smk_audit_info ad;
2446
2447 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2448 smk_ad_setfield_u_net_sk(&ad, other->sk);
2449 return smk_access(smk_of_inode(sp), smk_of_inode(op),
2450 MAY_READWRITE, &ad);
2451}
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461static int smack_unix_may_send(struct socket *sock, struct socket *other)
2462{
2463 struct inode *sp = SOCK_INODE(sock);
2464 struct inode *op = SOCK_INODE(other);
2465 struct smk_audit_info ad;
2466
2467 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2468 smk_ad_setfield_u_net_sk(&ad, other->sk);
2469 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE, &ad);
2470}
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
2483 int size)
2484{
2485 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
2486
2487
2488
2489
2490 if (sip == NULL || sip->sin_family != AF_INET)
2491 return 0;
2492
2493 return smack_netlabel_send(sock->sk, sip);
2494}
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2505{
2506 char smack[SMK_LABELLEN];
2507 char *sp;
2508 int pcat;
2509
2510 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521 memset(smack, '\0', SMK_LABELLEN);
2522 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2523 for (pcat = -1;;) {
2524 pcat = netlbl_secattr_catmap_walk(
2525 sap->attr.mls.cat, pcat + 1);
2526 if (pcat < 0)
2527 break;
2528 smack_catset_bit(pcat, smack);
2529 }
2530
2531
2532
2533
2534 if (sap->attr.mls.lvl == smack_cipso_direct) {
2535 memcpy(sip, smack, SMK_MAXLEN);
2536 return;
2537 }
2538
2539
2540
2541
2542 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2543 return;
2544 }
2545 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
2546
2547
2548
2549 sp = smack_from_secid(sap->attr.secid);
2550
2551
2552
2553
2554
2555
2556
2557 BUG_ON(sp == NULL);
2558 strncpy(sip, sp, SMK_MAXLEN);
2559 return;
2560 }
2561
2562
2563
2564
2565
2566 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2567 return;
2568}
2569
2570
2571
2572
2573
2574
2575
2576
2577static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2578{
2579 struct netlbl_lsm_secattr secattr;
2580 struct socket_smack *ssp = sk->sk_security;
2581 char smack[SMK_LABELLEN];
2582 char *csp;
2583 int rc;
2584 struct smk_audit_info ad;
2585 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2586 return 0;
2587
2588
2589
2590
2591 netlbl_secattr_init(&secattr);
2592
2593 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2594 if (rc == 0) {
2595 smack_from_secattr(&secattr, smack);
2596 csp = smack;
2597 } else
2598 csp = smack_net_ambient;
2599
2600 netlbl_secattr_destroy(&secattr);
2601
2602#ifdef CONFIG_AUDIT
2603 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2604 ad.a.u.net.family = sk->sk_family;
2605 ad.a.u.net.netif = skb->iif;
2606 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2607#endif
2608
2609
2610
2611
2612
2613
2614 rc = smk_access(csp, ssp->smk_in, MAY_WRITE, &ad);
2615 if (rc != 0)
2616 netlbl_skbuff_err(skb, rc, 0);
2617 return rc;
2618}
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629static int smack_socket_getpeersec_stream(struct socket *sock,
2630 char __user *optval,
2631 int __user *optlen, unsigned len)
2632{
2633 struct socket_smack *ssp;
2634 int slen;
2635 int rc = 0;
2636
2637 ssp = sock->sk->sk_security;
2638 slen = strlen(ssp->smk_packet) + 1;
2639
2640 if (slen > len)
2641 rc = -ERANGE;
2642 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2643 rc = -EFAULT;
2644
2645 if (put_user(slen, optlen) != 0)
2646 rc = -EFAULT;
2647
2648 return rc;
2649}
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660static int smack_socket_getpeersec_dgram(struct socket *sock,
2661 struct sk_buff *skb, u32 *secid)
2662
2663{
2664 struct netlbl_lsm_secattr secattr;
2665 struct sock *sk;
2666 char smack[SMK_LABELLEN];
2667 int family = PF_INET;
2668 u32 s;
2669 int rc;
2670
2671
2672
2673
2674 if (sock != NULL) {
2675 sk = sock->sk;
2676 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2677 return 0;
2678 family = sk->sk_family;
2679 }
2680
2681
2682
2683 netlbl_secattr_init(&secattr);
2684 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2685 if (rc == 0)
2686 smack_from_secattr(&secattr, smack);
2687 netlbl_secattr_destroy(&secattr);
2688
2689
2690
2691
2692 if (rc != 0)
2693 return rc;
2694
2695 s = smack_to_secid(smack);
2696 if (s == 0)
2697 return -EINVAL;
2698
2699 *secid = s;
2700 return 0;
2701}
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711static void smack_sock_graft(struct sock *sk, struct socket *parent)
2712{
2713 struct socket_smack *ssp;
2714
2715 if (sk == NULL ||
2716 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
2717 return;
2718
2719 ssp = sk->sk_security;
2720 ssp->smk_in = ssp->smk_out = current_security();
2721
2722}
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2734 struct request_sock *req)
2735{
2736 u16 family = sk->sk_family;
2737 struct socket_smack *ssp = sk->sk_security;
2738 struct netlbl_lsm_secattr secattr;
2739 struct sockaddr_in addr;
2740 struct iphdr *hdr;
2741 char smack[SMK_LABELLEN];
2742 int rc;
2743 struct smk_audit_info ad;
2744
2745
2746 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
2747 family = PF_INET;
2748
2749 netlbl_secattr_init(&secattr);
2750 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2751 if (rc == 0)
2752 smack_from_secattr(&secattr, smack);
2753 else
2754 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2755 netlbl_secattr_destroy(&secattr);
2756
2757#ifdef CONFIG_AUDIT
2758 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2759 ad.a.u.net.family = family;
2760 ad.a.u.net.netif = skb->iif;
2761 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2762#endif
2763
2764
2765
2766
2767 rc = smk_access(smack, ssp->smk_in, MAY_WRITE, &ad);
2768 if (rc != 0)
2769 return rc;
2770
2771
2772
2773
2774
2775 req->peer_secid = smack_to_secid(smack);
2776
2777
2778
2779
2780
2781
2782 hdr = ip_hdr(skb);
2783 addr.sin_addr.s_addr = hdr->saddr;
2784 rcu_read_lock();
2785 if (smack_host_label(&addr) == NULL) {
2786 rcu_read_unlock();
2787 netlbl_secattr_init(&secattr);
2788 smack_to_secattr(smack, &secattr);
2789 rc = netlbl_req_setattr(req, &secattr);
2790 netlbl_secattr_destroy(&secattr);
2791 } else {
2792 rcu_read_unlock();
2793 netlbl_req_delattr(req);
2794 }
2795
2796 return rc;
2797}
2798
2799
2800
2801
2802
2803
2804
2805
2806static void smack_inet_csk_clone(struct sock *sk,
2807 const struct request_sock *req)
2808{
2809 struct socket_smack *ssp = sk->sk_security;
2810 char *smack;
2811
2812 if (req->peer_secid != 0) {
2813 smack = smack_from_secid(req->peer_secid);
2814 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2815 } else
2816 ssp->smk_packet[0] = '\0';
2817}
2818
2819
2820
2821
2822
2823
2824
2825
2826#ifdef CONFIG_KEYS
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838static int smack_key_alloc(struct key *key, const struct cred *cred,
2839 unsigned long flags)
2840{
2841 key->security = cred->security;
2842 return 0;
2843}
2844
2845
2846
2847
2848
2849
2850
2851static void smack_key_free(struct key *key)
2852{
2853 key->security = NULL;
2854}
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865static int smack_key_permission(key_ref_t key_ref,
2866 const struct cred *cred, key_perm_t perm)
2867{
2868 struct key *keyp;
2869 struct smk_audit_info ad;
2870
2871 keyp = key_ref_to_ptr(key_ref);
2872 if (keyp == NULL)
2873 return -EINVAL;
2874
2875
2876
2877
2878 if (keyp->security == NULL)
2879 return 0;
2880
2881
2882
2883 if (cred->security == NULL)
2884 return -EACCES;
2885#ifdef CONFIG_AUDIT
2886 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
2887 ad.a.u.key_struct.key = keyp->serial;
2888 ad.a.u.key_struct.key_desc = keyp->description;
2889#endif
2890 return smk_access(cred->security, keyp->security,
2891 MAY_READWRITE, &ad);
2892}
2893#endif
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908#ifdef CONFIG_AUDIT
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2921{
2922 char **rule = (char **)vrule;
2923 *rule = NULL;
2924
2925 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2926 return -EINVAL;
2927
2928 if (op != Audit_equal && op != Audit_not_equal)
2929 return -EINVAL;
2930
2931 *rule = smk_import(rulestr, 0);
2932
2933 return 0;
2934}
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944static int smack_audit_rule_known(struct audit_krule *krule)
2945{
2946 struct audit_field *f;
2947 int i;
2948
2949 for (i = 0; i < krule->field_count; i++) {
2950 f = &krule->fields[i];
2951
2952 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2953 return 1;
2954 }
2955
2956 return 0;
2957}
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2971 struct audit_context *actx)
2972{
2973 char *smack;
2974 char *rule = vrule;
2975
2976 if (!rule) {
2977 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2978 "Smack: missing rule\n");
2979 return -ENOENT;
2980 }
2981
2982 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2983 return 0;
2984
2985 smack = smack_from_secid(secid);
2986
2987
2988
2989
2990
2991
2992 if (op == Audit_equal)
2993 return (rule == smack);
2994 if (op == Audit_not_equal)
2995 return (rule != smack);
2996
2997 return 0;
2998}
2999
3000
3001
3002
3003
3004
3005
3006static void smack_audit_rule_free(void *vrule)
3007{
3008
3009}
3010
3011#endif
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3022{
3023 char *sp = smack_from_secid(secid);
3024
3025 *secdata = sp;
3026 *seclen = strlen(sp);
3027 return 0;
3028}
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3039{
3040 *secid = smack_to_secid(secdata);
3041 return 0;
3042}
3043
3044
3045
3046
3047
3048
3049
3050
3051static void smack_release_secctx(char *secdata, u32 seclen)
3052{
3053}
3054
3055static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3056{
3057 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3058}
3059
3060static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3061{
3062 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3063}
3064
3065static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3066{
3067 int len = 0;
3068 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3069
3070 if (len < 0)
3071 return len;
3072 *ctxlen = len;
3073 return 0;
3074}
3075
3076struct security_operations smack_ops = {
3077 .name = "smack",
3078
3079 .ptrace_access_check = smack_ptrace_access_check,
3080 .ptrace_traceme = smack_ptrace_traceme,
3081 .syslog = smack_syslog,
3082
3083 .sb_alloc_security = smack_sb_alloc_security,
3084 .sb_free_security = smack_sb_free_security,
3085 .sb_copy_data = smack_sb_copy_data,
3086 .sb_kern_mount = smack_sb_kern_mount,
3087 .sb_statfs = smack_sb_statfs,
3088 .sb_mount = smack_sb_mount,
3089 .sb_umount = smack_sb_umount,
3090
3091 .inode_alloc_security = smack_inode_alloc_security,
3092 .inode_free_security = smack_inode_free_security,
3093 .inode_init_security = smack_inode_init_security,
3094 .inode_link = smack_inode_link,
3095 .inode_unlink = smack_inode_unlink,
3096 .inode_rmdir = smack_inode_rmdir,
3097 .inode_rename = smack_inode_rename,
3098 .inode_permission = smack_inode_permission,
3099 .inode_setattr = smack_inode_setattr,
3100 .inode_getattr = smack_inode_getattr,
3101 .inode_setxattr = smack_inode_setxattr,
3102 .inode_post_setxattr = smack_inode_post_setxattr,
3103 .inode_getxattr = smack_inode_getxattr,
3104 .inode_removexattr = smack_inode_removexattr,
3105 .inode_getsecurity = smack_inode_getsecurity,
3106 .inode_setsecurity = smack_inode_setsecurity,
3107 .inode_listsecurity = smack_inode_listsecurity,
3108 .inode_getsecid = smack_inode_getsecid,
3109
3110 .file_permission = smack_file_permission,
3111 .file_alloc_security = smack_file_alloc_security,
3112 .file_free_security = smack_file_free_security,
3113 .file_ioctl = smack_file_ioctl,
3114 .file_lock = smack_file_lock,
3115 .file_fcntl = smack_file_fcntl,
3116 .file_set_fowner = smack_file_set_fowner,
3117 .file_send_sigiotask = smack_file_send_sigiotask,
3118 .file_receive = smack_file_receive,
3119
3120 .cred_alloc_blank = smack_cred_alloc_blank,
3121 .cred_free = smack_cred_free,
3122 .cred_prepare = smack_cred_prepare,
3123 .cred_commit = smack_cred_commit,
3124 .cred_transfer = smack_cred_transfer,
3125 .kernel_act_as = smack_kernel_act_as,
3126 .kernel_create_files_as = smack_kernel_create_files_as,
3127 .task_setpgid = smack_task_setpgid,
3128 .task_getpgid = smack_task_getpgid,
3129 .task_getsid = smack_task_getsid,
3130 .task_getsecid = smack_task_getsecid,
3131 .task_setnice = smack_task_setnice,
3132 .task_setioprio = smack_task_setioprio,
3133 .task_getioprio = smack_task_getioprio,
3134 .task_setscheduler = smack_task_setscheduler,
3135 .task_getscheduler = smack_task_getscheduler,
3136 .task_movememory = smack_task_movememory,
3137 .task_kill = smack_task_kill,
3138 .task_wait = smack_task_wait,
3139 .task_to_inode = smack_task_to_inode,
3140
3141 .ipc_permission = smack_ipc_permission,
3142 .ipc_getsecid = smack_ipc_getsecid,
3143
3144 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3145 .msg_msg_free_security = smack_msg_msg_free_security,
3146
3147 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3148 .msg_queue_free_security = smack_msg_queue_free_security,
3149 .msg_queue_associate = smack_msg_queue_associate,
3150 .msg_queue_msgctl = smack_msg_queue_msgctl,
3151 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3152 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3153
3154 .shm_alloc_security = smack_shm_alloc_security,
3155 .shm_free_security = smack_shm_free_security,
3156 .shm_associate = smack_shm_associate,
3157 .shm_shmctl = smack_shm_shmctl,
3158 .shm_shmat = smack_shm_shmat,
3159
3160 .sem_alloc_security = smack_sem_alloc_security,
3161 .sem_free_security = smack_sem_free_security,
3162 .sem_associate = smack_sem_associate,
3163 .sem_semctl = smack_sem_semctl,
3164 .sem_semop = smack_sem_semop,
3165
3166 .d_instantiate = smack_d_instantiate,
3167
3168 .getprocattr = smack_getprocattr,
3169 .setprocattr = smack_setprocattr,
3170
3171 .unix_stream_connect = smack_unix_stream_connect,
3172 .unix_may_send = smack_unix_may_send,
3173
3174 .socket_post_create = smack_socket_post_create,
3175 .socket_connect = smack_socket_connect,
3176 .socket_sendmsg = smack_socket_sendmsg,
3177 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3178 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3179 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3180 .sk_alloc_security = smack_sk_alloc_security,
3181 .sk_free_security = smack_sk_free_security,
3182 .sock_graft = smack_sock_graft,
3183 .inet_conn_request = smack_inet_conn_request,
3184 .inet_csk_clone = smack_inet_csk_clone,
3185
3186
3187#ifdef CONFIG_KEYS
3188 .key_alloc = smack_key_alloc,
3189 .key_free = smack_key_free,
3190 .key_permission = smack_key_permission,
3191#endif
3192
3193
3194#ifdef CONFIG_AUDIT
3195 .audit_rule_init = smack_audit_rule_init,
3196 .audit_rule_known = smack_audit_rule_known,
3197 .audit_rule_match = smack_audit_rule_match,
3198 .audit_rule_free = smack_audit_rule_free,
3199#endif
3200
3201 .secid_to_secctx = smack_secid_to_secctx,
3202 .secctx_to_secid = smack_secctx_to_secid,
3203 .release_secctx = smack_release_secctx,
3204 .inode_notifysecctx = smack_inode_notifysecctx,
3205 .inode_setsecctx = smack_inode_setsecctx,
3206 .inode_getsecctx = smack_inode_getsecctx,
3207};
3208
3209
3210static __init void init_smack_know_list(void)
3211{
3212 list_add(&smack_known_huh.list, &smack_known_list);
3213 list_add(&smack_known_hat.list, &smack_known_list);
3214 list_add(&smack_known_star.list, &smack_known_list);
3215 list_add(&smack_known_floor.list, &smack_known_list);
3216 list_add(&smack_known_invalid.list, &smack_known_list);
3217 list_add(&smack_known_web.list, &smack_known_list);
3218}
3219
3220
3221
3222
3223
3224
3225static __init int smack_init(void)
3226{
3227 struct cred *cred;
3228
3229 if (!security_module_enable(&smack_ops))
3230 return 0;
3231
3232 printk(KERN_INFO "Smack: Initializing.\n");
3233
3234
3235
3236
3237 cred = (struct cred *) current->cred;
3238 cred->security = &smack_known_floor.smk_known;
3239
3240
3241 init_smack_know_list();
3242
3243
3244
3245 spin_lock_init(&smack_known_huh.smk_cipsolock);
3246 spin_lock_init(&smack_known_hat.smk_cipsolock);
3247 spin_lock_init(&smack_known_star.smk_cipsolock);
3248 spin_lock_init(&smack_known_floor.smk_cipsolock);
3249 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3250
3251
3252
3253
3254 if (register_security(&smack_ops))
3255 panic("smack: Unable to register with kernel.\n");
3256
3257 return 0;
3258}
3259
3260
3261
3262
3263
3264security_initcall(smack_init);
3265