History

Merge branch 'master' of git://git.infradead.org/users/eparis/selinux into next

Per pull request, for 3.5.

James Morris committed 14 years ago

Commit ff2bb042 parents cffee16 c737f8233 files · +422 −350Browse files

Unified · Split

33 files
  1. fs/open.c +1 −1
  2. include/linux/lsm_audit.h +0 −6
  3. include/linux/security.h +5 −8
  4. net/xfrm/xfrm_policy.c +1 −0
  5. security/apparmor/audit.c +9 −2
  6. security/apparmor/capability.c +2 −2
  7. security/apparmor/file.c +1 −1
  8. security/apparmor/include/audit.h +1 −0
  9. security/apparmor/ipc.c +1 −1
  10. security/apparmor/lib.c +1 −1
  11. security/apparmor/lsm.c +3 −3
  12. security/apparmor/policy.c +1 −1
  13. security/apparmor/policy_unpack.c +1 −1
  14. security/apparmor/resource.c +1 −1
  15. security/capability.c +2 −2
  16. security/lsm_audit.c +9 −6
  17. security/security.c +2 −2
  18. security/selinux/avc.c +24 −106
  19. security/selinux/hooks.c +118 −140
  20. security/selinux/include/avc.h +77 −23
  21. security/selinux/include/security.h +3 −1
  22. security/selinux/netif.c +2 −4
  23. security/selinux/netnode.c +2 −4
  24. security/selinux/netport.c +2 −4
  25. security/selinux/selinuxfs.c +4 −7
  26. security/selinux/ss/context.h +20 −0
  27. security/selinux/ss/mls.c +24 −0
  28. security/selinux/ss/policydb.c +44 −0
  29. security/selinux/ss/policydb.h +14 −0
  30. security/selinux/ss/services.c +40 −16
  31. security/smack/smack.h +1 −1
  32. security/smack/smack_lsm.c +3 −3
  33. security/tomoyo/tomoyo.c +3 −3
fs/open.c+1−1
@@ -681,7 +681,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, · 680 unmodified lines
681681
682682 f->f_op = fops_get(inode->i_fop);
683683
684− error = security_dentry_open(f, cred);
684+ error = security_file_open(f, cred);
685685 if (error)
686686 goto cleanup_all;
687687
include/linux/lsm_audit.h+0−6
@@ -53,7 +53,6 @@ struct common_audit_data { · 52 unmodified lines
5353 #define LSM_AUDIT_DATA_KMOD 8
5454 #define LSM_AUDIT_DATA_INODE 9
5555 #define LSM_AUDIT_DATA_DENTRY 10
56− struct task_struct *tsk;
5756 union {
5857 struct path path;
5958 struct dentry *dentry;
@@ -93,11 +92,6 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb, · 33 unmodified lines
9392 int ipv6_skb_to_auditdata(struct sk_buff *skb,
9493 struct common_audit_data *ad, u8 *proto);
9594
96−/* Initialize an LSM audit data structure. */
97−#define COMMON_AUDIT_DATA_INIT(_d, _t) \
98− { memset((_d), 0, sizeof(struct common_audit_data)); \
99− (_d)->type = LSM_AUDIT_DATA_##_t; }
100−
10195 void common_lsm_audit(struct common_audit_data *a,
10296 void (*pre_audit)(struct audit_buffer *, void *),
10397 void (*post_audit)(struct audit_buffer *, void *));
include/linux/security.h+5−8
@@ -640,10 +640,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · 639 unmodified lines
640640 * to receive an open file descriptor via socket IPC.
641641 * @file contains the file structure being received.
642642 * Return 0 if permission is granted.
643− *
644− * Security hook for dentry
645− *
646− * @dentry_open
643+ * @file_open
647644 * Save open-time permission checking state for later use upon
648645 * file_permission, and recheck access if anything has changed
649646 * since inode_permission.
@@ -1498,7 +1495,7 @@ struct security_operations { · 848 unmodified lines
14981495 int (*file_send_sigiotask) (struct task_struct *tsk,
14991496 struct fown_struct *fown, int sig);
15001497 int (*file_receive) (struct file *file);
1501− int (*dentry_open) (struct file *file, const struct cred *cred);
1498+ int (*file_open) (struct file *file, const struct cred *cred);
15021499
15031500 int (*task_create) (unsigned long clone_flags);
15041501 void (*task_free) (struct task_struct *task);
@@ -1757,7 +1754,7 @@ int security_file_set_fowner(struct file *file); · 252 unmodified lines
17571754 int security_file_send_sigiotask(struct task_struct *tsk,
17581755 struct fown_struct *fown, int sig);
17591756 int security_file_receive(struct file *file);
1760−int security_dentry_open(struct file *file, const struct cred *cred);
1757+int security_file_open(struct file *file, const struct cred *cred);
17611758 int security_task_create(unsigned long clone_flags);
17621759 void security_task_free(struct task_struct *task);
17631760 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp);
@@ -2228,8 +2225,8 @@ static inline int security_file_receive(struct file *file) · 464 unmodified lines
22282225 return 0;
22292226 }
22302227
2231−static inline int security_dentry_open(struct file *file,
2232− const struct cred *cred)
2228+static inline int security_file_open(struct file *file,
2229+ const struct cred *cred)
22332230 {
22342231 return 0;
22352232 }
net/xfrm/xfrm_policy.c+1−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include <linux/cache.h>
2727 #include <linux/audit.h>
2828 #include <net/dst.h>
29+#include <net/flow.h>
2930 #include <net/xfrm.h>
3031 #include <net/ip.h>
3132 #ifdef CONFIG_XFRM_STATISTICS
security/apparmor/audit.c+9−2
@@ -111,7 +111,7 @@ static const char *const aa_audit_type[] = { · 110 unmodified lines
111111 static void audit_pre(struct audit_buffer *ab, void *ca)
112112 {
113113 struct common_audit_data *sa = ca;
114− struct task_struct *tsk = sa->tsk ? sa->tsk : current;
114+ struct task_struct *tsk = sa->aad->tsk ? sa->aad->tsk : current;
115115
116116 if (aa_g_audit_header) {
117117 audit_log_format(ab, "apparmor=");
@@ -149,6 +149,12 @@ static void audit_pre(struct audit_buffer *ab, void *ca) · 31 unmodified lines
149149 audit_log_format(ab, " name=");
150150 audit_log_untrustedstring(ab, sa->aad->name);
151151 }
152+
153+ if (sa->aad->tsk) {
154+ audit_log_format(ab, " pid=%d comm=", tsk->pid);
155+ audit_log_untrustedstring(ab, tsk->comm);
156+ }
157+
152158 }
153159
154160 /**
@@ -205,7 +211,8 @@ int aa_audit(int type, struct aa_profile *profile, gfp_t gfp, · 50 unmodified lines
205211 aa_audit_msg(type, sa, cb);
206212
207213 if (sa->aad->type == AUDIT_APPARMOR_KILL)
208− (void)send_sig_info(SIGKILL, NULL, sa->tsk ? sa->tsk : current);
214+ (void)send_sig_info(SIGKILL, NULL,
215+ sa->aad->tsk ? sa->aad->tsk : current);
209216
210217 if (sa->aad->type == AUDIT_APPARMOR_ALLOWED)
211218 return complain_error(sa->aad->error);
security/apparmor/capability.c+2−2
@@ -65,10 +65,10 @@ static int audit_caps(struct aa_profile *profile, struct task_struct *task, · 64 unmodified lines
6565 int type = AUDIT_APPARMOR_AUTO;
6666 struct common_audit_data sa;
6767 struct apparmor_audit_data aad = {0,};
68− COMMON_AUDIT_DATA_INIT(&sa, CAP);
68+ sa.type = LSM_AUDIT_DATA_CAP;
6969 sa.aad = &aad;
70− sa.tsk = task;
7170 sa.u.cap = cap;
71+ sa.aad->tsk = task;
7272 sa.aad->op = OP_CAPABLE;
7373 sa.aad->error = error;
7474
security/apparmor/file.c+1−1
@@ -108,7 +108,7 @@ int aa_audit_file(struct aa_profile *profile, struct file_perms *perms, · 107 unmodified lines
108108 int type = AUDIT_APPARMOR_AUTO;
109109 struct common_audit_data sa;
110110 struct apparmor_audit_data aad = {0,};
111− COMMON_AUDIT_DATA_INIT(&sa, NONE);
111+ sa.type = LSM_AUDIT_DATA_NONE;
112112 sa.aad = &aad;
113113 aad.op = op,
114114 aad.fs.request = request;
security/apparmor/include/audit.h+1−0
@@ -110,6 +110,7 @@ struct apparmor_audit_data { · 109 unmodified lines
110110 void *profile;
111111 const char *name;
112112 const char *info;
113+ struct task_struct *tsk;
113114 union {
114115 void *target;
115116 struct {
security/apparmor/ipc.c+1−1
@@ -42,7 +42,7 @@ static int aa_audit_ptrace(struct aa_profile *profile, · 41 unmodified lines
4242 {
4343 struct common_audit_data sa;
4444 struct apparmor_audit_data aad = {0,};
45− COMMON_AUDIT_DATA_INIT(&sa, NONE);
45+ sa.type = LSM_AUDIT_DATA_NONE;
4646 sa.aad = &aad;
4747 aad.op = OP_PTRACE;
4848 aad.target = target;
security/apparmor/lib.c+1−1
@@ -66,7 +66,7 @@ void aa_info_message(const char *str) · 65 unmodified lines
6666 if (audit_enabled) {
6767 struct common_audit_data sa;
6868 struct apparmor_audit_data aad = {0,};
69− COMMON_AUDIT_DATA_INIT(&sa, NONE);
69+ sa.type = LSM_AUDIT_DATA_NONE;
7070 sa.aad = &aad;
7171 aad.info = str;
7272 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL);
security/apparmor/lsm.c+3−3
@@ -373,7 +373,7 @@ static int apparmor_inode_getattr(struct vfsmount *mnt, struct dentry *dentry) · 372 unmodified lines
373373 AA_MAY_META_READ);
374374 }
375375
376−static int apparmor_dentry_open(struct file *file, const struct cred *cred)
376+static int apparmor_file_open(struct file *file, const struct cred *cred)
377377 {
378378 struct aa_file_cxt *fcxt = file->f_security;
379379 struct aa_profile *profile;
@@ -589,7 +589,7 @@ static int apparmor_setprocattr(struct task_struct *task, char *name, · 209 unmodified lines
589589 } else {
590590 struct common_audit_data sa;
591591 struct apparmor_audit_data aad = {0,};
592− COMMON_AUDIT_DATA_INIT(&sa, NONE);
592+ sa.type = LSM_AUDIT_DATA_NONE;
593593 sa.aad = &aad;
594594 aad.op = OP_SETPROCATTR;
595595 aad.info = name;
@@ -640,9 +640,9 @@ static struct security_operations apparmor_ops = { · 44 unmodified lines
640640 .path_chmod = apparmor_path_chmod,
641641 .path_chown = apparmor_path_chown,
642642 .path_truncate = apparmor_path_truncate,
643− .dentry_open = apparmor_dentry_open,
644643 .inode_getattr = apparmor_inode_getattr,
645644
645+ .file_open = apparmor_file_open,
646646 .file_permission = apparmor_file_permission,
647647 .file_alloc_security = apparmor_file_alloc_security,
648648 .file_free_security = apparmor_file_free_security,
security/apparmor/policy.c+1−1
@@ -969,7 +969,7 @@ static int audit_policy(int op, gfp_t gfp, const char *name, const char *info, · 968 unmodified lines
969969 {
970970 struct common_audit_data sa;
971971 struct apparmor_audit_data aad = {0,};
972− COMMON_AUDIT_DATA_INIT(&sa, NONE);
972+ sa.type = LSM_AUDIT_DATA_NONE;
973973 sa.aad = &aad;
974974 aad.op = op;
975975 aad.name = name;
security/apparmor/policy_unpack.c+1−1
@@ -95,7 +95,7 @@ static int audit_iface(struct aa_profile *new, const char *name, · 94 unmodified lines
9595 struct aa_profile *profile = __aa_current_profile();
9696 struct common_audit_data sa;
9797 struct apparmor_audit_data aad = {0,};
98− COMMON_AUDIT_DATA_INIT(&sa, NONE);
98+ sa.type = LSM_AUDIT_DATA_NONE;
9999 sa.aad = &aad;
100100 if (e)
101101 aad.iface.pos = e->pos - e->start;
security/apparmor/resource.c+1−1
@@ -52,7 +52,7 @@ static int audit_resource(struct aa_profile *profile, unsigned int resource, · 51 unmodified lines
5252 struct common_audit_data sa;
5353 struct apparmor_audit_data aad = {0,};
5454
55− COMMON_AUDIT_DATA_INIT(&sa, NONE);
55+ sa.type = LSM_AUDIT_DATA_NONE;
5656 sa.aad = &aad;
5757 aad.op = OP_SETRLIMIT,
5858 aad.rlim.rlim = resource;
security/capability.c+2−2
@@ -348,7 +348,7 @@ static int cap_file_receive(struct file *file) · 347 unmodified lines
348348 return 0;
349349 }
350350
351−static int cap_dentry_open(struct file *file, const struct cred *cred)
351+static int cap_file_open(struct file *file, const struct cred *cred)
352352 {
353353 return 0;
354354 }
@@ -956,7 +956,7 @@ void __init security_fixup_ops(struct security_operations *ops) · 601 unmodified lines
956956 set_to_cap_if_null(ops, file_set_fowner);
957957 set_to_cap_if_null(ops, file_send_sigiotask);
958958 set_to_cap_if_null(ops, file_receive);
959− set_to_cap_if_null(ops, dentry_open);
959+ set_to_cap_if_null(ops, file_open);
960960 set_to_cap_if_null(ops, task_create);
961961 set_to_cap_if_null(ops, task_free);
962962 set_to_cap_if_null(ops, cred_alloc_blank);
security/lsm_audit.c+9−6
@@ -213,12 +213,15 @@ static void dump_common_audit_data(struct audit_buffer *ab, · 212 unmodified lines
213213 {
214214 struct task_struct *tsk = current;
215215
216− if (a->tsk)
217− tsk = a->tsk;
218− if (tsk && tsk->pid) {
219− audit_log_format(ab, " pid=%d comm=", tsk->pid);
220− audit_log_untrustedstring(ab, tsk->comm);
221− }
216+ /*
217+ * To keep stack sizes in check force programers to notice if they
218+ * start making this union too large! See struct lsm_network_audit
219+ * as an example of how to deal with large data.
220+ */
221+ BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
222+
223+ audit_log_format(ab, " pid=%d comm=", tsk->pid);
224+ audit_log_untrustedstring(ab, tsk->comm);
222225
223226 switch (a->type) {
224227 case LSM_AUDIT_DATA_NONE:
security/security.c+2−2
@@ -701,11 +701,11 @@ int security_file_receive(struct file *file) · 700 unmodified lines
701701 return security_ops->file_receive(file);
702702 }
703703
704−int security_dentry_open(struct file *file, const struct cred *cred)
704+int security_file_open(struct file *file, const struct cred *cred)
705705 {
706706 int ret;
707707
708− ret = security_ops->dentry_open(file, cred);
708+ ret = security_ops->file_open(file, cred);
709709 if (ret)
710710 return ret;
711711
security/selinux/avc.c+24−106
@@ -65,14 +65,8 @@ struct avc_cache { · 64 unmodified lines
6565 };
6666
6767 struct avc_callback_node {
68− int (*callback) (u32 event, u32 ssid, u32 tsid,
69− u16 tclass, u32 perms,
70− u32 *out_retained);
68+ int (*callback) (u32 event);
7169 u32 events;
72− u32 ssid;
73− u32 tsid;
74− u16 tclass;
75− u32 perms;
7670 struct avc_callback_node *next;
7771 };
7872
@@ -436,9 +430,9 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a) · 357 unmodified lines
436430 {
437431 struct common_audit_data *ad = a;
438432 audit_log_format(ab, "avc: %s ",
439− ad->selinux_audit_data->slad->denied ? "denied" : "granted");
440− avc_dump_av(ab, ad->selinux_audit_data->slad->tclass,
441− ad->selinux_audit_data->slad->audited);
433+ ad->selinux_audit_data->denied ? "denied" : "granted");
434+ avc_dump_av(ab, ad->selinux_audit_data->tclass,
435+ ad->selinux_audit_data->audited);
442436 audit_log_format(ab, " for ");
443437 }
444438
@@ -452,25 +446,23 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a) · 7 unmodified lines
452446 {
453447 struct common_audit_data *ad = a;
454448 audit_log_format(ab, " ");
455− avc_dump_query(ab, ad->selinux_audit_data->slad->ssid,
456− ad->selinux_audit_data->slad->tsid,
457− ad->selinux_audit_data->slad->tclass);
449+ avc_dump_query(ab, ad->selinux_audit_data->ssid,
450+ ad->selinux_audit_data->tsid,
451+ ad->selinux_audit_data->tclass);
458452 }
459453
460454 /* This is the slow part of avc audit with big stack footprint */
461−static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
455+noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
462456 u32 requested, u32 audited, u32 denied,
463457 struct common_audit_data *a,
464458 unsigned flags)
465459 {
466460 struct common_audit_data stack_data;
467− struct selinux_audit_data sad = {0,};
468− struct selinux_late_audit_data slad;
461+ struct selinux_audit_data sad;
469462
470463 if (!a) {
471464 a = &stack_data;
472− COMMON_AUDIT_DATA_INIT(a, NONE);
473− a->selinux_audit_data = &sad;
465+ a->type = LSM_AUDIT_DATA_NONE;
474466 }
475467
476468 /*
@@ -484,104 +476,34 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass, · 7 unmodified lines
484476 (flags & MAY_NOT_BLOCK))
485477 return -ECHILD;
486478
487− slad.tclass = tclass;
488− slad.requested = requested;
489− slad.ssid = ssid;
490− slad.tsid = tsid;
491− slad.audited = audited;
492− slad.denied = denied;
479+ sad.tclass = tclass;
480+ sad.requested = requested;
481+ sad.ssid = ssid;
482+ sad.tsid = tsid;
483+ sad.audited = audited;
484+ sad.denied = denied;
485+
486+ a->selinux_audit_data = &sad;
493487
494− a->selinux_audit_data->slad = &slad;
495488 common_lsm_audit(a, avc_audit_pre_callback, avc_audit_post_callback);
496489 return 0;
497490 }
498491
499−/**
500− * avc_audit - Audit the granting or denial of permissions.
501− * @ssid: source security identifier
502− * @tsid: target security identifier
503− * @tclass: target security class
504− * @requested: requested permissions
505− * @avd: access vector decisions
506− * @result: result from avc_has_perm_noaudit
507− * @a: auxiliary audit data
508− * @flags: VFS walk flags
509− *
510− * Audit the granting or denial of permissions in accordance
511− * with the policy. This function is typically called by
512− * avc_has_perm() after a permission check, but can also be
513− * called directly by callers who use avc_has_perm_noaudit()
514− * in order to separate the permission check from the auditing.
515− * For example, this separation is useful when the permission check must
516− * be performed under a lock, to allow the lock to be released
517− * before calling the auditing code.
518− */
519−inline int avc_audit(u32 ssid, u32 tsid,
520− u16 tclass, u32 requested,
521− struct av_decision *avd, int result, struct common_audit_data *a,
522− unsigned flags)
523−{
524− u32 denied, audited;
525− denied = requested & ~avd->allowed;
526− if (unlikely(denied)) {
527− audited = denied & avd->auditdeny;
528− /*
529− * a->selinux_audit_data->auditdeny is TRICKY! Setting a bit in
530− * this field means that ANY denials should NOT be audited if
531− * the policy contains an explicit dontaudit rule for that
532− * permission. Take notice that this is unrelated to the
533− * actual permissions that were denied. As an example lets
534− * assume:
535− *
536− * denied == READ
537− * avd.auditdeny & ACCESS == 0 (not set means explicit rule)
538− * selinux_audit_data->auditdeny & ACCESS == 1
539− *
540− * We will NOT audit the denial even though the denied
541− * permission was READ and the auditdeny checks were for
542− * ACCESS
543− */
544− if (a &&
545− a->selinux_audit_data->auditdeny &&
546− !(a->selinux_audit_data->auditdeny & avd->auditdeny))
547− audited = 0;
548− } else if (result)
549− audited = denied = requested;
550− else
551− audited = requested & avd->auditallow;
552− if (likely(!audited))
553− return 0;
554−
555− return slow_avc_audit(ssid, tsid, tclass,
556− requested, audited, denied,
557− a, flags);
558−}
559−
560492 /**
561493 * avc_add_callback - Register a callback for security events.
562494 * @callback: callback function
563495 * @events: security events
564− * @ssid: source security identifier or %SECSID_WILD
565− * @tsid: target security identifier or %SECSID_WILD
566− * @tclass: target security class
567− * @perms: permissions
568496 *
569− * Register a callback function for events in the set @events
570− * related to the SID pair (@ssid, @tsid)
571− * and the permissions @perms, interpreting
572− * @perms based on @tclass. Returns %0 on success or
573− * -%ENOMEM if insufficient memory exists to add the callback.
497+ * Register a callback function for events in the set @events.
498+ * Returns %0 on success or -%ENOMEM if insufficient memory
499+ * exists to add the callback.
574500 */
575−int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
576− u16 tclass, u32 perms,
577− u32 *out_retained),
578− u32 events, u32 ssid, u32 tsid,
579− u16 tclass, u32 perms)
501+int __init avc_add_callback(int (*callback)(u32 event), u32 events)
580502 {
581503 struct avc_callback_node *c;
582504 int rc = 0;
583505
584− c = kmalloc(sizeof(*c), GFP_ATOMIC);
506+ c = kmalloc(sizeof(*c), GFP_KERNEL);
585507 if (!c) {
586508 rc = -ENOMEM;
587509 goto out;
@@ -589,9 +511,6 @@ int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid, · 1 unmodified line
589511
590512 c->callback = callback;
591513 c->events = events;
592− c->ssid = ssid;
593− c->tsid = tsid;
594− c->perms = perms;
595514 c->next = avc_callbacks;
596515 avc_callbacks = c;
597516 out:
@@ -731,8 +650,7 @@ int avc_ss_reset(u32 seqno) · 133 unmodified lines
731650
732651 for (c = avc_callbacks; c; c = c->next) {
733652 if (c->events & AVC_CALLBACK_RESET) {
734− tmprc = c->callback(AVC_CALLBACK_RESET,
735− 0, 0, 0, 0, NULL);
653+ tmprc = c->callback(AVC_CALLBACK_RESET);
736654 /* save the first error encountered for the return
737655 value and continue processing the callbacks */
738656 if (!rc)
security/selinux/hooks.c+118−140
@@ -1420,16 +1420,13 @@ static int cred_has_capability(const struct cred *cred, · 1419 unmodified lines
14201420 int cap, int audit)
14211421 {
14221422 struct common_audit_data ad;
1423− struct selinux_audit_data sad = {0,};
14241423 struct av_decision avd;
14251424 u16 sclass;
14261425 u32 sid = cred_sid(cred);
14271426 u32 av = CAP_TO_MASK(cap);
14281427 int rc;
14291428
1430− COMMON_AUDIT_DATA_INIT(&ad, CAP);
1431− ad.selinux_audit_data = &sad;
1432− ad.tsk = current;
1429+ ad.type = LSM_AUDIT_DATA_CAP;
14331430 ad.u.cap = cap;
14341431
14351432 switch (CAP_TO_INDEX(cap)) {
@@ -1488,20 +1485,6 @@ static int inode_has_perm(const struct cred *cred, · 52 unmodified lines
14881485 return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags);
14891486 }
14901487
1491−static int inode_has_perm_noadp(const struct cred *cred,
1492− struct inode *inode,
1493− u32 perms,
1494− unsigned flags)
1495−{
1496− struct common_audit_data ad;
1497− struct selinux_audit_data sad = {0,};
1498−
1499− COMMON_AUDIT_DATA_INIT(&ad, INODE);
1500− ad.u.inode = inode;
1501− ad.selinux_audit_data = &sad;
1502− return inode_has_perm(cred, inode, perms, &ad, flags);
1503−}
1504−
15051488 /* Same as inode_has_perm, but pass explicit audit data containing
15061489 the dentry to help the auditing code to more easily generate the
15071490 pathname if needed. */
@@ -1511,11 +1494,9 @@ static inline int dentry_has_perm(const struct cred *cred, · 3 unmodified lines
15111494 {
15121495 struct inode *inode = dentry->d_inode;
15131496 struct common_audit_data ad;
1514− struct selinux_audit_data sad = {0,};
15151497
1516− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1498+ ad.type = LSM_AUDIT_DATA_DENTRY;
15171499 ad.u.dentry = dentry;
1518− ad.selinux_audit_data = &sad;
15191500 return inode_has_perm(cred, inode, av, &ad, 0);
15201501 }
15211502
@@ -1528,11 +1509,9 @@ static inline int path_has_perm(const struct cred *cred, · 6 unmodified lines
15281509 {
15291510 struct inode *inode = path->dentry->d_inode;
15301511 struct common_audit_data ad;
1531− struct selinux_audit_data sad = {0,};
15321512
1533− COMMON_AUDIT_DATA_INIT(&ad, PATH);
1513+ ad.type = LSM_AUDIT_DATA_PATH;
15341514 ad.u.path = *path;
1535− ad.selinux_audit_data = &sad;
15361515 return inode_has_perm(cred, inode, av, &ad, 0);
15371516 }
15381517
@@ -1551,13 +1530,11 @@ static int file_has_perm(const struct cred *cred, · 12 unmodified lines
15511530 struct file_security_struct *fsec = file->f_security;
15521531 struct inode *inode = file->f_path.dentry->d_inode;
15531532 struct common_audit_data ad;
1554− struct selinux_audit_data sad = {0,};
15551533 u32 sid = cred_sid(cred);
15561534 int rc;
15571535
1558− COMMON_AUDIT_DATA_INIT(&ad, PATH);
1536+ ad.type = LSM_AUDIT_DATA_PATH;
15591537 ad.u.path = file->f_path;
1560− ad.selinux_audit_data = &sad;
15611538
15621539 if (sid != fsec->sid) {
15631540 rc = avc_has_perm(sid, fsec->sid,
@@ -1587,7 +1564,6 @@ static int may_create(struct inode *dir, · 23 unmodified lines
15871564 struct superblock_security_struct *sbsec;
15881565 u32 sid, newsid;
15891566 struct common_audit_data ad;
1590− struct selinux_audit_data sad = {0,};
15911567 int rc;
15921568
15931569 dsec = dir->i_security;
@@ -1596,9 +1572,8 @@ static int may_create(struct inode *dir, · 2 unmodified lines
15961572 sid = tsec->sid;
15971573 newsid = tsec->create_sid;
15981574
1599− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1575+ ad.type = LSM_AUDIT_DATA_DENTRY;
16001576 ad.u.dentry = dentry;
1601− ad.selinux_audit_data = &sad;
16021577
16031578 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
16041579 DIR__ADD_NAME | DIR__SEARCH,
@@ -1643,7 +1618,6 @@ static int may_link(struct inode *dir, · 38 unmodified lines
16431618 {
16441619 struct inode_security_struct *dsec, *isec;
16451620 struct common_audit_data ad;
1646− struct selinux_audit_data sad = {0,};
16471621 u32 sid = current_sid();
16481622 u32 av;
16491623 int rc;
@@ -1651,9 +1625,8 @@ static int may_link(struct inode *dir, · 1 unmodified line
16511625 dsec = dir->i_security;
16521626 isec = dentry->d_inode->i_security;
16531627
1654− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1628+ ad.type = LSM_AUDIT_DATA_DENTRY;
16551629 ad.u.dentry = dentry;
1656− ad.selinux_audit_data = &sad;
16571630
16581631 av = DIR__SEARCH;
16591632 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
@@ -1688,7 +1661,6 @@ static inline int may_rename(struct inode *old_dir, · 28 unmodified lines
16881661 {
16891662 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
16901663 struct common_audit_data ad;
1691− struct selinux_audit_data sad = {0,};
16921664 u32 sid = current_sid();
16931665 u32 av;
16941666 int old_is_dir, new_is_dir;
@@ -1699,8 +1671,7 @@ static inline int may_rename(struct inode *old_dir, · 4 unmodified lines
16991671 old_is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
17001672 new_dsec = new_dir->i_security;
17011673
1702− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1703− ad.selinux_audit_data = &sad;
1674+ ad.type = LSM_AUDIT_DATA_DENTRY;
17041675
17051676 ad.u.dentry = old_dentry;
17061677 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
@@ -1986,7 +1957,6 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) · 279 unmodified lines
19861957 struct task_security_struct *new_tsec;
19871958 struct inode_security_struct *isec;
19881959 struct common_audit_data ad;
1989− struct selinux_audit_data sad = {0,};
19901960 struct inode *inode = bprm->file->f_path.dentry->d_inode;
19911961 int rc;
19921962
@@ -2032,8 +2002,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm) · 39 unmodified lines
20322002 return rc;
20332003 }
20342004
2035− COMMON_AUDIT_DATA_INIT(&ad, PATH);
2036− ad.selinux_audit_data = &sad;
2005+ ad.type = LSM_AUDIT_DATA_PATH;
20372006 ad.u.path = bprm->file->f_path;
20382007
20392008 if ((bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) ||
@@ -2123,8 +2092,6 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm) · 83 unmodified lines
21232092 static inline void flush_unauthorized_files(const struct cred *cred,
21242093 struct files_struct *files)
21252094 {
2126− struct common_audit_data ad;
2127− struct selinux_audit_data sad = {0,};
21282095 struct file *file, *devnull = NULL;
21292096 struct tty_struct *tty;
21302097 struct fdtable *fdt;
@@ -2136,21 +2103,17 @@ static inline void flush_unauthorized_files(const struct cred *cred, · 5 unmodified lines
21362103 spin_lock(&tty_files_lock);
21372104 if (!list_empty(&tty->tty_files)) {
21382105 struct tty_file_private *file_priv;
2139− struct inode *inode;
21402106
21412107 /* Revalidate access to controlling tty.
2142− Use inode_has_perm on the tty inode directly rather
2108+ Use path_has_perm on the tty path directly rather
21432109 than using file_has_perm, as this particular open
21442110 file may belong to another process and we are only
21452111 interested in the inode-based check here. */
21462112 file_priv = list_first_entry(&tty->tty_files,
21472113 struct tty_file_private, list);
21482114 file = file_priv->file;
2149− inode = file->f_path.dentry->d_inode;
2150− if (inode_has_perm_noadp(cred, inode,
2151− FILE__READ | FILE__WRITE, 0)) {
2115+ if (path_has_perm(cred, &file->f_path, FILE__READ | FILE__WRITE))
21522116 drop_tty = 1;
2153− }
21542117 }
21552118 spin_unlock(&tty_files_lock);
21562119 tty_kref_put(tty);
@@ -2160,10 +2123,6 @@ static inline void flush_unauthorized_files(const struct cred *cred, · 3 unmodified lines
21602123 no_tty();
21612124
21622125 /* Revalidate access to inherited open files. */
2163−
2164− COMMON_AUDIT_DATA_INIT(&ad, INODE);
2165− ad.selinux_audit_data = &sad;
2166−
21672126 spin_lock(&files->file_lock);
21682127 for (;;) {
21692128 unsigned long set, i;
@@ -2500,7 +2459,6 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data) · 330 unmodified lines
25002459 {
25012460 const struct cred *cred = current_cred();
25022461 struct common_audit_data ad;
2503− struct selinux_audit_data sad = {0,};
25042462 int rc;
25052463
25062464 rc = superblock_doinit(sb, data);
@@ -2511,8 +2469,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data) · 4 unmodified lines
25112469 if (flags & MS_KERNMOUNT)
25122470 return 0;
25132471
2514− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2515− ad.selinux_audit_data = &sad;
2472+ ad.type = LSM_AUDIT_DATA_DENTRY;
25162473 ad.u.dentry = sb->s_root;
25172474 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
25182475 }
@@ -2521,10 +2478,8 @@ static int selinux_sb_statfs(struct dentry *dentry) · 2 unmodified lines
25212478 {
25222479 const struct cred *cred = current_cred();
25232480 struct common_audit_data ad;
2524− struct selinux_audit_data sad = {0,};
25252481
2526− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2527− ad.selinux_audit_data = &sad;
2482+ ad.type = LSM_AUDIT_DATA_DENTRY;
25282483 ad.u.dentry = dentry->d_sb->s_root;
25292484 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
25302485 }
@@ -2684,14 +2639,35 @@ static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *na · 153 unmodified lines
26842639 return dentry_has_perm(cred, dentry, FILE__READ);
26852640 }
26862641
2642+static noinline int audit_inode_permission(struct inode *inode,
2643+ u32 perms, u32 audited, u32 denied,
2644+ unsigned flags)
2645+{
2646+ struct common_audit_data ad;
2647+ struct inode_security_struct *isec = inode->i_security;
2648+ int rc;
2649+
2650+ ad.type = LSM_AUDIT_DATA_INODE;
2651+ ad.u.inode = inode;
2652+
2653+ rc = slow_avc_audit(current_sid(), isec->sid, isec->sclass, perms,
2654+ audited, denied, &ad, flags);
2655+ if (rc)
2656+ return rc;
2657+ return 0;
2658+}
2659+
26872660 static int selinux_inode_permission(struct inode *inode, int mask)
26882661 {
26892662 const struct cred *cred = current_cred();
2690− struct common_audit_data ad;
2691− struct selinux_audit_data sad = {0,};
26922663 u32 perms;
26932664 bool from_access;
26942665 unsigned flags = mask & MAY_NOT_BLOCK;
2666+ struct inode_security_struct *isec;
2667+ u32 sid;
2668+ struct av_decision avd;
2669+ int rc, rc2;
2670+ u32 audited, denied;
26952671
26962672 from_access = mask & MAY_ACCESS;
26972673 mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
@@ -2700,22 +2676,34 @@ static int selinux_inode_permission(struct inode *inode, int mask) · 2 unmodified lines
27002676 if (!mask)
27012677 return 0;
27022678
2703− COMMON_AUDIT_DATA_INIT(&ad, INODE);
2704− ad.selinux_audit_data = &sad;
2705− ad.u.inode = inode;
2679+ validate_creds(cred);
27062680
2707− if (from_access)
2708− ad.selinux_audit_data->auditdeny |= FILE__AUDIT_ACCESS;
2681+ if (unlikely(IS_PRIVATE(inode)))
2682+ return 0;
27092683
27102684 perms = file_mask_to_av(inode->i_mode, mask);
27112685
2712− return inode_has_perm(cred, inode, perms, &ad, flags);
2686+ sid = cred_sid(cred);
2687+ isec = inode->i_security;
2688+
2689+ rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, &avd);
2690+ audited = avc_audit_required(perms, &avd, rc,
2691+ from_access ? FILE__AUDIT_ACCESS : 0,
2692+ &denied);
2693+ if (likely(!audited))
2694+ return rc;
2695+
2696+ rc2 = audit_inode_permission(inode, perms, audited, denied, flags);
2697+ if (rc2)
2698+ return rc2;
2699+ return rc;
27132700 }
27142701
27152702 static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
27162703 {
27172704 const struct cred *cred = current_cred();
27182705 unsigned int ia_valid = iattr->ia_valid;
2706+ __u32 av = FILE__WRITE;
27192707
27202708 /* ATTR_FORCE is just used for ATTR_KILL_S[UG]ID. */
27212709 if (ia_valid & ATTR_FORCE) {
@@ -2729,7 +2717,10 @@ static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr) · 7 unmodified lines
27292717 ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET))
27302718 return dentry_has_perm(cred, dentry, FILE__SETATTR);
27312719
2732− return dentry_has_perm(cred, dentry, FILE__WRITE);
2720+ if (ia_valid & ATTR_SIZE)
2721+ av |= FILE__OPEN;
2722+
2723+ return dentry_has_perm(cred, dentry, av);
27332724 }
27342725
27352726 static int selinux_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
@@ -2771,7 +2762,6 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, · 35 unmodified lines
27712762 struct inode_security_struct *isec = inode->i_security;
27722763 struct superblock_security_struct *sbsec;
27732764 struct common_audit_data ad;
2774− struct selinux_audit_data sad = {0,};
27752765 u32 newsid, sid = current_sid();
27762766 int rc = 0;
27772767
@@ -2785,8 +2775,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, · 7 unmodified lines
27852775 if (!inode_owner_or_capable(inode))
27862776 return -EPERM;
27872777
2788− COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2789− ad.selinux_audit_data = &sad;
2778+ ad.type = LSM_AUDIT_DATA_DENTRY;
27902779 ad.u.dentry = dentry;
27912780
27922781 rc = avc_has_perm(sid, isec->sid, isec->sclass,
@@ -2796,8 +2785,25 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, · 3 unmodified lines
27962785
27972786 rc = security_context_to_sid(value, size, &newsid);
27982787 if (rc == -EINVAL) {
2799− if (!capable(CAP_MAC_ADMIN))
2788+ if (!capable(CAP_MAC_ADMIN)) {
2789+ struct audit_buffer *ab;
2790+ size_t audit_size;
2791+ const char *str;
2792+
2793+ /* We strip a nul only if it is at the end, otherwise the
2794+ * context contains a nul and we should audit that */
2795+ str = value;
2796+ if (str[size - 1] == '\0')
2797+ audit_size = size - 1;
2798+ else
2799+ audit_size = size;
2800+ ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
2801+ audit_log_format(ab, "op=setxattr invalid_context=");
2802+ audit_log_n_untrustedstring(ab, value, audit_size);
2803+ audit_log_end(ab);
2804+
28002805 return rc;
2806+ }
28012807 rc = security_context_to_sid_force(value, size, &newsid);
28022808 }
28032809 if (rc)
@@ -2977,7 +2983,7 @@ static int selinux_file_permission(struct file *file, int mask) · 173 unmodified lines
29772983
29782984 if (sid == fsec->sid && fsec->isid == isec->sid &&
29792985 fsec->pseqno == avc_policy_seqno())
2980− /* No change since dentry_open check. */
2986+ /* No change since file_open check. */
29812987 return 0;
29822988
29832989 return selinux_revalidate_file_permission(file, mask);
@@ -3236,15 +3242,13 @@ static int selinux_file_receive(struct file *file) · 252 unmodified lines
32363242 return file_has_perm(cred, file, file_to_av(file));
32373243 }
32383244
3239−static int selinux_dentry_open(struct file *file, const struct cred *cred)
3245+static int selinux_file_open(struct file *file, const struct cred *cred)
32403246 {
32413247 struct file_security_struct *fsec;
3242− struct inode *inode;
32433248 struct inode_security_struct *isec;
32443249
3245− inode = file->f_path.dentry->d_inode;
32463250 fsec = file->f_security;
3247− isec = inode->i_security;
3251+ isec = file->f_path.dentry->d_inode->i_security;
32483252 /*
32493253 * Save inode label and policy sequence number
32503254 * at open-time so that selinux_file_permission
@@ -3262,7 +3266,7 @@ static int selinux_dentry_open(struct file *file, const struct cred *cred) · 11 unmodified lines
32623266 * new inode label or new policy.
32633267 * This check is not redundant - do not remove.
32643268 */
3265− return inode_has_perm_noadp(cred, inode, open_file_to_av(file), 0);
3269+ return path_has_perm(cred, &file->f_path, open_file_to_av(file));
32663270 }
32673271
32683272 /* task security operations */
@@ -3381,12 +3385,10 @@ static int selinux_kernel_module_request(char *kmod_name) · 112 unmodified lines
33813385 {
33823386 u32 sid;
33833387 struct common_audit_data ad;
3384− struct selinux_audit_data sad = {0,};
33853388
33863389 sid = task_sid(current);
33873390
3388− COMMON_AUDIT_DATA_INIT(&ad, KMOD);
3389− ad.selinux_audit_data = &sad;
3391+ ad.type = LSM_AUDIT_DATA_KMOD;
33903392 ad.u.kmod_name = kmod_name;
33913393
33923394 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM,
@@ -3759,15 +3761,13 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms) · 366 unmodified lines
37593761 {
37603762 struct sk_security_struct *sksec = sk->sk_security;
37613763 struct common_audit_data ad;
3762− struct selinux_audit_data sad = {0,};
37633764 struct lsm_network_audit net = {0,};
37643765 u32 tsid = task_sid(task);
37653766
37663767 if (sksec->sid == SECINITSID_KERNEL)
37673768 return 0;
37683769
3769− COMMON_AUDIT_DATA_INIT(&ad, NET);
3770− ad.selinux_audit_data = &sad;
3770+ ad.type = LSM_AUDIT_DATA_NET;
37713771 ad.u.net = &net;
37723772 ad.u.net->sk = sk;
37733773
@@ -3847,7 +3847,6 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in · 73 unmodified lines
38473847 char *addrp;
38483848 struct sk_security_struct *sksec = sk->sk_security;
38493849 struct common_audit_data ad;
3850− struct selinux_audit_data sad = {0,};
38513850 struct lsm_network_audit net = {0,};
38523851 struct sockaddr_in *addr4 = NULL;
38533852 struct sockaddr_in6 *addr6 = NULL;
@@ -3874,8 +3873,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in · 20 unmodified lines
38743873 snum, &sid);
38753874 if (err)
38763875 goto out;
3877− COMMON_AUDIT_DATA_INIT(&ad, NET);
3878− ad.selinux_audit_data = &sad;
3876+ ad.type = LSM_AUDIT_DATA_NET;
38793877 ad.u.net = &net;
38803878 ad.u.net->sport = htons(snum);
38813879 ad.u.net->family = family;
@@ -3909,8 +3907,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in · 27 unmodified lines
39093907 if (err)
39103908 goto out;
39113909
3912− COMMON_AUDIT_DATA_INIT(&ad, NET);
3913− ad.selinux_audit_data = &sad;
3910+ ad.type = LSM_AUDIT_DATA_NET;
39143911 ad.u.net = &net;
39153912 ad.u.net->sport = htons(snum);
39163913 ad.u.net->family = family;
@@ -3945,7 +3942,6 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, · 28 unmodified lines
39453942 if (sksec->sclass == SECCLASS_TCP_SOCKET ||
39463943 sksec->sclass == SECCLASS_DCCP_SOCKET) {
39473944 struct common_audit_data ad;
3948− struct selinux_audit_data sad = {0,};
39493945 struct lsm_network_audit net = {0,};
39503946 struct sockaddr_in *addr4 = NULL;
39513947 struct sockaddr_in6 *addr6 = NULL;
@@ -3971,8 +3967,7 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, · 19 unmodified lines
39713967 perm = (sksec->sclass == SECCLASS_TCP_SOCKET) ?
39723968 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
39733969
3974− COMMON_AUDIT_DATA_INIT(&ad, NET);
3975− ad.selinux_audit_data = &sad;
3970+ ad.type = LSM_AUDIT_DATA_NET;
39763971 ad.u.net = &net;
39773972 ad.u.net->dport = htons(snum);
39783973 ad.u.net->family = sk->sk_family;
@@ -4064,12 +4059,10 @@ static int selinux_socket_unix_stream_connect(struct sock *sock, · 85 unmodified lines
40644059 struct sk_security_struct *sksec_other = other->sk_security;
40654060 struct sk_security_struct *sksec_new = newsk->sk_security;
40664061 struct common_audit_data ad;
4067− struct selinux_audit_data sad = {0,};
40684062 struct lsm_network_audit net = {0,};
40694063 int err;
40704064
4071− COMMON_AUDIT_DATA_INIT(&ad, NET);
4072− ad.selinux_audit_data = &sad;
4065+ ad.type = LSM_AUDIT_DATA_NET;
40734066 ad.u.net = &net;
40744067 ad.u.net->sk = other;
40754068
@@ -4098,11 +4091,9 @@ static int selinux_socket_unix_may_send(struct socket *sock, · 22 unmodified lines
40984091 struct sk_security_struct *ssec = sock->sk->sk_security;
40994092 struct sk_security_struct *osec = other->sk->sk_security;
41004093 struct common_audit_data ad;
4101− struct selinux_audit_data sad = {0,};
41024094 struct lsm_network_audit net = {0,};
41034095
4104− COMMON_AUDIT_DATA_INIT(&ad, NET);
4105− ad.selinux_audit_data = &sad;
4096+ ad.type = LSM_AUDIT_DATA_NET;
41064097 ad.u.net = &net;
41074098 ad.u.net->sk = other->sk;
41084099
@@ -4140,12 +4131,10 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, · 31 unmodified lines
41404131 struct sk_security_struct *sksec = sk->sk_security;
41414132 u32 sk_sid = sksec->sid;
41424133 struct common_audit_data ad;
4143− struct selinux_audit_data sad = {0,};
41444134 struct lsm_network_audit net = {0,};
41454135 char *addrp;
41464136
4147− COMMON_AUDIT_DATA_INIT(&ad, NET);
4148− ad.selinux_audit_data = &sad;
4137+ ad.type = LSM_AUDIT_DATA_NET;
41494138 ad.u.net = &net;
41504139 ad.u.net->netif = skb->skb_iif;
41514140 ad.u.net->family = family;
@@ -4175,7 +4164,6 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) · 23 unmodified lines
41754164 u16 family = sk->sk_family;
41764165 u32 sk_sid = sksec->sid;
41774166 struct common_audit_data ad;
4178− struct selinux_audit_data sad = {0,};
41794167 struct lsm_network_audit net = {0,};
41804168 char *addrp;
41814169 u8 secmark_active;
@@ -4200,8 +4188,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) · 18 unmodified lines
42004188 if (!secmark_active && !peerlbl_active)
42014189 return 0;
42024190
4203− COMMON_AUDIT_DATA_INIT(&ad, NET);
4204− ad.selinux_audit_data = &sad;
4191+ ad.type = LSM_AUDIT_DATA_NET;
42054192 ad.u.net = &net;
42064193 ad.u.net->netif = skb->skb_iif;
42074194 ad.u.net->family = family;
@@ -4539,7 +4526,6 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex, · 331 unmodified lines
45394526 char *addrp;
45404527 u32 peer_sid;
45414528 struct common_audit_data ad;
4542− struct selinux_audit_data sad = {0,};
45434529 struct lsm_network_audit net = {0,};
45444530 u8 secmark_active;
45454531 u8 netlbl_active;
@@ -4557,8 +4543,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex, · 11 unmodified lines
45574543 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0)
45584544 return NF_DROP;
45594545
4560− COMMON_AUDIT_DATA_INIT(&ad, NET);
4561− ad.selinux_audit_data = &sad;
4546+ ad.type = LSM_AUDIT_DATA_NET;
45624547 ad.u.net = &net;
45634548 ad.u.net->netif = ifindex;
45644549 ad.u.net->family = family;
@@ -4648,7 +4633,6 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, · 83 unmodified lines
46484633 struct sock *sk = skb->sk;
46494634 struct sk_security_struct *sksec;
46504635 struct common_audit_data ad;
4651− struct selinux_audit_data sad = {0,};
46524636 struct lsm_network_audit net = {0,};
46534637 char *addrp;
46544638 u8 proto;
@@ -4657,8 +4641,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, · 2 unmodified lines
46574641 return NF_ACCEPT;
46584642 sksec = sk->sk_security;
46594643
4660− COMMON_AUDIT_DATA_INIT(&ad, NET);
4661− ad.selinux_audit_data = &sad;
4644+ ad.type = LSM_AUDIT_DATA_NET;
46624645 ad.u.net = &net;
46634646 ad.u.net->netif = ifindex;
46644647 ad.u.net->family = family;
@@ -4683,7 +4666,6 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex, · 18 unmodified lines
46834666 u32 peer_sid;
46844667 struct sock *sk;
46854668 struct common_audit_data ad;
4686− struct selinux_audit_data sad = {0,};
46874669 struct lsm_network_audit net = {0,};
46884670 char *addrp;
46894671 u8 secmark_active;
@@ -4730,8 +4712,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex, · 40 unmodified lines
47304712 secmark_perm = PACKET__SEND;
47314713 }
47324714
4733− COMMON_AUDIT_DATA_INIT(&ad, NET);
4734− ad.selinux_audit_data = &sad;
4715+ ad.type = LSM_AUDIT_DATA_NET;
47354716 ad.u.net = &net;
47364717 ad.u.net->netif = ifindex;
47374718 ad.u.net->family = family;
@@ -4849,13 +4830,11 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms, · 111 unmodified lines
48494830 {
48504831 struct ipc_security_struct *isec;
48514832 struct common_audit_data ad;
4852− struct selinux_audit_data sad = {0,};
48534833 u32 sid = current_sid();
48544834
48554835 isec = ipc_perms->security;
48564836
4857− COMMON_AUDIT_DATA_INIT(&ad, IPC);
4858− ad.selinux_audit_data = &sad;
4837+ ad.type = LSM_AUDIT_DATA_IPC;
48594838 ad.u.ipc_id = ipc_perms->key;
48604839
48614840 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
@@ -4876,7 +4855,6 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq) · 14 unmodified lines
48764855 {
48774856 struct ipc_security_struct *isec;
48784857 struct common_audit_data ad;
4879− struct selinux_audit_data sad = {0,};
48804858 u32 sid = current_sid();
48814859 int rc;
48824860
@@ -4886,8 +4864,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq) · 3 unmodified lines
48864864
48874865 isec = msq->q_perm.security;
48884866
4889− COMMON_AUDIT_DATA_INIT(&ad, IPC);
4890− ad.selinux_audit_data = &sad;
4867+ ad.type = LSM_AUDIT_DATA_IPC;
48914868 ad.u.ipc_id = msq->q_perm.key;
48924869
48934870 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4908,13 +4885,11 @@ static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg) · 14 unmodified lines
49084885 {
49094886 struct ipc_security_struct *isec;
49104887 struct common_audit_data ad;
4911− struct selinux_audit_data sad = {0,};
49124888 u32 sid = current_sid();
49134889
49144890 isec = msq->q_perm.security;
49154891
4916− COMMON_AUDIT_DATA_INIT(&ad, IPC);
4917− ad.selinux_audit_data = &sad;
4892+ ad.type = LSM_AUDIT_DATA_IPC;
49184893 ad.u.ipc_id = msq->q_perm.key;
49194894
49204895 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4954,7 +4929,6 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg, · 33 unmodified lines
49544929 struct ipc_security_struct *isec;
49554930 struct msg_security_struct *msec;
49564931 struct common_audit_data ad;
4957− struct selinux_audit_data sad = {0,};
49584932 u32 sid = current_sid();
49594933 int rc;
49604934
@@ -4975,8 +4949,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg, · 14 unmodified lines
49754949 return rc;
49764950 }
49774951
4978− COMMON_AUDIT_DATA_INIT(&ad, IPC);
4979− ad.selinux_audit_data = &sad;
4952+ ad.type = LSM_AUDIT_DATA_IPC;
49804953 ad.u.ipc_id = msq->q_perm.key;
49814954
49824955 /* Can this process write to the queue? */
@@ -5001,15 +4974,13 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg, · 18 unmodified lines
50014974 struct ipc_security_struct *isec;
50024975 struct msg_security_struct *msec;
50034976 struct common_audit_data ad;
5004− struct selinux_audit_data sad = {0,};
50054977 u32 sid = task_sid(target);
50064978 int rc;
50074979
50084980 isec = msq->q_perm.security;
50094981 msec = msg->security;
50104982
5011− COMMON_AUDIT_DATA_INIT(&ad, IPC);
5012− ad.selinux_audit_data = &sad;
4983+ ad.type = LSM_AUDIT_DATA_IPC;
50134984 ad.u.ipc_id = msq->q_perm.key;
50144985
50154986 rc = avc_has_perm(sid, isec->sid,
@@ -5025,7 +4996,6 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp) · 9 unmodified lines
50254996 {
50264997 struct ipc_security_struct *isec;
50274998 struct common_audit_data ad;
5028− struct selinux_audit_data sad = {0,};
50294999 u32 sid = current_sid();
50305000 int rc;
50315001
@@ -5035,8 +5005,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp) · 3 unmodified lines
50355005
50365006 isec = shp->shm_perm.security;
50375007
5038− COMMON_AUDIT_DATA_INIT(&ad, IPC);
5039− ad.selinux_audit_data = &sad;
5008+ ad.type = LSM_AUDIT_DATA_IPC;
50405009 ad.u.ipc_id = shp->shm_perm.key;
50415010
50425011 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5057,13 +5026,11 @@ static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg) · 14 unmodified lines
50575026 {
50585027 struct ipc_security_struct *isec;
50595028 struct common_audit_data ad;
5060− struct selinux_audit_data sad = {0,};
50615029 u32 sid = current_sid();
50625030
50635031 isec = shp->shm_perm.security;
50645032
5065− COMMON_AUDIT_DATA_INIT(&ad, IPC);
5066− ad.selinux_audit_data = &sad;
5033+ ad.type = LSM_AUDIT_DATA_IPC;
50675034 ad.u.ipc_id = shp->shm_perm.key;
50685035
50695036 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5121,7 +5088,6 @@ static int selinux_sem_alloc_security(struct sem_array *sma) · 51 unmodified lines
51215088 {
51225089 struct ipc_security_struct *isec;
51235090 struct common_audit_data ad;
5124− struct selinux_audit_data sad = {0,};
51255091 u32 sid = current_sid();
51265092 int rc;
51275093
@@ -5131,8 +5097,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma) · 3 unmodified lines
51315097
51325098 isec = sma->sem_perm.security;
51335099
5134− COMMON_AUDIT_DATA_INIT(&ad, IPC);
5135− ad.selinux_audit_data = &sad;
5100+ ad.type = LSM_AUDIT_DATA_IPC;
51365101 ad.u.ipc_id = sma->sem_perm.key;
51375102
51385103 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5153,13 +5118,11 @@ static int selinux_sem_associate(struct sem_array *sma, int semflg) · 14 unmodified lines
51535118 {
51545119 struct ipc_security_struct *isec;
51555120 struct common_audit_data ad;
5156− struct selinux_audit_data sad = {0,};
51575121 u32 sid = current_sid();
51585122
51595123 isec = sma->sem_perm.security;
51605124
5161− COMMON_AUDIT_DATA_INIT(&ad, IPC);
5162− ad.selinux_audit_data = &sad;
5125+ ad.type = LSM_AUDIT_DATA_IPC;
51635126 ad.u.ipc_id = sma->sem_perm.key;
51645127
51655128 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5339,8 +5302,23 @@ static int selinux_setprocattr(struct task_struct *p, · 173 unmodified lines
53395302 }
53405303 error = security_context_to_sid(value, size, &sid);
53415304 if (error == -EINVAL && !strcmp(name, "fscreate")) {
5342− if (!capable(CAP_MAC_ADMIN))
5305+ if (!capable(CAP_MAC_ADMIN)) {
5306+ struct audit_buffer *ab;
5307+ size_t audit_size;
5308+
5309+ /* We strip a nul only if it is at the end, otherwise the
5310+ * context contains a nul and we should audit that */
5311+ if (str[size - 1] == '\0')
5312+ audit_size = size - 1;
5313+ else
5314+ audit_size = size;
5315+ ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
5316+ audit_log_format(ab, "op=fscreate invalid_context=");
5317+ audit_log_n_untrustedstring(ab, value, audit_size);
5318+ audit_log_end(ab);
5319+
53435320 return error;
5321+ }
53445322 error = security_context_to_sid_force(value, size,
53455323 &sid);
53465324 }
@@ -5600,7 +5578,7 @@ static struct security_operations selinux_ops = { · 253 unmodified lines
56005578 .file_send_sigiotask = selinux_file_send_sigiotask,
56015579 .file_receive = selinux_file_receive,
56025580
5603− .dentry_open = selinux_dentry_open,
5581+ .file_open = selinux_file_open,
56045582
56055583 .task_create = selinux_task_create,
56065584 .cred_alloc_blank = selinux_cred_alloc_blank,
security/selinux/include/avc.h+77−23
@@ -49,7 +49,7 @@ struct avc_cache_stats { · 48 unmodified lines
4949 /*
5050 * We only need this data after we have decided to send an audit message.
5151 */
52−struct selinux_late_audit_data {
52+struct selinux_audit_data {
5353 u32 ssid;
5454 u32 tsid;
5555 u16 tclass;
@@ -59,29 +59,87 @@ struct selinux_late_audit_data { · 3 unmodified lines
5959 int result;
6060 };
6161
62−/*
63− * We collect this at the beginning or during an selinux security operation
64− */
65−struct selinux_audit_data {
66− /*
67− * auditdeny is a bit tricky and unintuitive. See the
68− * comments in avc.c for it's meaning and usage.
69− */
70− u32 auditdeny;
71− struct selinux_late_audit_data *slad;
72−};
73−
7462 /*
7563 * AVC operations
7664 */
7765
7866 void __init avc_init(void);
7967
80−int avc_audit(u32 ssid, u32 tsid,
81− u16 tclass, u32 requested,
82− struct av_decision *avd,
83− int result,
84− struct common_audit_data *a, unsigned flags);
68+static inline u32 avc_audit_required(u32 requested,
69+ struct av_decision *avd,
70+ int result,
71+ u32 auditdeny,
72+ u32 *deniedp)
73+{
74+ u32 denied, audited;
75+ denied = requested & ~avd->allowed;
76+ if (unlikely(denied)) {
77+ audited = denied & avd->auditdeny;
78+ /*
79+ * auditdeny is TRICKY! Setting a bit in
80+ * this field means that ANY denials should NOT be audited if
81+ * the policy contains an explicit dontaudit rule for that
82+ * permission. Take notice that this is unrelated to the
83+ * actual permissions that were denied. As an example lets
84+ * assume:
85+ *
86+ * denied == READ
87+ * avd.auditdeny & ACCESS == 0 (not set means explicit rule)
88+ * auditdeny & ACCESS == 1
89+ *
90+ * We will NOT audit the denial even though the denied
91+ * permission was READ and the auditdeny checks were for
92+ * ACCESS
93+ */
94+ if (auditdeny && !(auditdeny & avd->auditdeny))
95+ audited = 0;
96+ } else if (result)
97+ audited = denied = requested;
98+ else
99+ audited = requested & avd->auditallow;
100+ *deniedp = denied;
101+ return audited;
102+}
103+
104+int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
105+ u32 requested, u32 audited, u32 denied,
106+ struct common_audit_data *a,
107+ unsigned flags);
108+
109+/**
110+ * avc_audit - Audit the granting or denial of permissions.
111+ * @ssid: source security identifier
112+ * @tsid: target security identifier
113+ * @tclass: target security class
114+ * @requested: requested permissions
115+ * @avd: access vector decisions
116+ * @result: result from avc_has_perm_noaudit
117+ * @a: auxiliary audit data
118+ * @flags: VFS walk flags
119+ *
120+ * Audit the granting or denial of permissions in accordance
121+ * with the policy. This function is typically called by
122+ * avc_has_perm() after a permission check, but can also be
123+ * called directly by callers who use avc_has_perm_noaudit()
124+ * in order to separate the permission check from the auditing.
125+ * For example, this separation is useful when the permission check must
126+ * be performed under a lock, to allow the lock to be released
127+ * before calling the auditing code.
128+ */
129+static inline int avc_audit(u32 ssid, u32 tsid,
130+ u16 tclass, u32 requested,
131+ struct av_decision *avd,
132+ int result,
133+ struct common_audit_data *a, unsigned flags)
134+{
135+ u32 audited, denied;
136+ audited = avc_audit_required(requested, avd, result, 0, &denied);
137+ if (likely(!audited))
138+ return 0;
139+ return slow_avc_audit(ssid, tsid, tclass,
140+ requested, audited, denied,
141+ a, flags);
142+}
85143
86144 #define AVC_STRICT 1 /* Ignore permissive mode. */
87145 int avc_has_perm_noaudit(u32 ssid, u32 tsid,
@@ -112,11 +170,7 @@ u32 avc_policy_seqno(void); · 24 unmodified lines
112170 #define AVC_CALLBACK_AUDITDENY_ENABLE 64
113171 #define AVC_CALLBACK_AUDITDENY_DISABLE 128
114172
115−int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
116− u16 tclass, u32 perms,
117− u32 *out_retained),
118− u32 events, u32 ssid, u32 tsid,
119− u16 tclass, u32 perms);
173+int avc_add_callback(int (*callback)(u32 event), u32 events);
120174
121175 /* Exported to selinuxfs */
122176 int avc_get_hash_stats(char *page);
security/selinux/include/security.h+3−1
@@ -31,13 +31,15 @@ · 30 unmodified lines
3131 #define POLICYDB_VERSION_BOUNDARY 24
3232 #define POLICYDB_VERSION_FILENAME_TRANS 25
3333 #define POLICYDB_VERSION_ROLETRANS 26
34+#define POLICYDB_VERSION_NEW_OBJECT_DEFAULTS 27
35+#define POLICYDB_VERSION_DEFAULT_TYPE 28
3436
3537 /* Range of policy versions we understand*/
3638 #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
3739 #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
3840 #define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
3941 #else
40−#define POLICYDB_VERSION_MAX POLICYDB_VERSION_ROLETRANS
42+#define POLICYDB_VERSION_MAX POLICYDB_VERSION_DEFAULT_TYPE
4143 #endif
4244
4345 /* Mask for just the mount related flags */
security/selinux/netif.c+2−4
@@ -252,8 +252,7 @@ static void sel_netif_flush(void) · 251 unmodified lines
252252 spin_unlock_bh(&sel_netif_lock);
253253 }
254254
255−static int sel_netif_avc_callback(u32 event, u32 ssid, u32 tsid,
256− u16 class, u32 perms, u32 *retained)
255+static int sel_netif_avc_callback(u32 event)
257256 {
258257 if (event == AVC_CALLBACK_RESET) {
259258 sel_netif_flush();
@@ -292,8 +291,7 @@ static __init int sel_netif_init(void) · 32 unmodified lines
292291
293292 register_netdevice_notifier(&sel_netif_netdev_notifier);
294293
295− err = avc_add_callback(sel_netif_avc_callback, AVC_CALLBACK_RESET,
296− SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0);
294+ err = avc_add_callback(sel_netif_avc_callback, AVC_CALLBACK_RESET);
297295 if (err)
298296 panic("avc_add_callback() failed, error %d\n", err);
299297
security/selinux/netnode.c+2−4
@@ -297,8 +297,7 @@ static void sel_netnode_flush(void) · 296 unmodified lines
297297 spin_unlock_bh(&sel_netnode_lock);
298298 }
299299
300−static int sel_netnode_avc_callback(u32 event, u32 ssid, u32 tsid,
301− u16 class, u32 perms, u32 *retained)
300+static int sel_netnode_avc_callback(u32 event)
302301 {
303302 if (event == AVC_CALLBACK_RESET) {
304303 sel_netnode_flush();
@@ -320,8 +319,7 @@ static __init int sel_netnode_init(void) · 15 unmodified lines
320319 sel_netnode_hash[iter].size = 0;
321320 }
322321
323− ret = avc_add_callback(sel_netnode_avc_callback, AVC_CALLBACK_RESET,
324− SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0);
322+ ret = avc_add_callback(sel_netnode_avc_callback, AVC_CALLBACK_RESET);
325323 if (ret != 0)
326324 panic("avc_add_callback() failed, error %d\n", ret);
327325
security/selinux/netport.c+2−4
@@ -234,8 +234,7 @@ static void sel_netport_flush(void) · 233 unmodified lines
234234 spin_unlock_bh(&sel_netport_lock);
235235 }
236236
237−static int sel_netport_avc_callback(u32 event, u32 ssid, u32 tsid,
238− u16 class, u32 perms, u32 *retained)
237+static int sel_netport_avc_callback(u32 event)
239238 {
240239 if (event == AVC_CALLBACK_RESET) {
241240 sel_netport_flush();
@@ -257,8 +256,7 @@ static __init int sel_netport_init(void) · 15 unmodified lines
257256 sel_netport_hash[iter].size = 0;
258257 }
259258
260− ret = avc_add_callback(sel_netport_avc_callback, AVC_CALLBACK_RESET,
261− SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0);
259+ ret = avc_add_callback(sel_netport_avc_callback, AVC_CALLBACK_RESET);
262260 if (ret != 0)
263261 panic("avc_add_callback() failed, error %d\n", ret);
264262
security/selinux/selinuxfs.c+4−7
@@ -496,6 +496,7 @@ static const struct file_operations sel_policy_ops = { · 495 unmodified lines
496496 .read = sel_read_policy,
497497 .mmap = sel_mmap_policy,
498498 .release = sel_release_policy,
499+ .llseek = generic_file_llseek,
499500 };
500501
501502 static ssize_t sel_write_load(struct file *file, const char __user *buf,
@@ -1232,6 +1233,7 @@ static int sel_make_bools(void) · 730 unmodified lines
12321233 kfree(bool_pending_names[i]);
12331234 kfree(bool_pending_names);
12341235 kfree(bool_pending_values);
1236+ bool_num = 0;
12351237 bool_pending_names = NULL;
12361238 bool_pending_values = NULL;
12371239
@@ -1532,11 +1534,6 @@ static int sel_make_initcon_files(struct dentry *dir) · 294 unmodified lines
15321534 return 0;
15331535 }
15341536
1535−static inline unsigned int sel_div(unsigned long a, unsigned long b)
1536−{
1537− return a / b - (a % b < 0);
1538−}
1539−
15401537 static inline unsigned long sel_class_to_ino(u16 class)
15411538 {
15421539 return (class * (SEL_VEC_MAX + 1)) | SEL_CLASS_INO_OFFSET;
@@ -1544,7 +1541,7 @@ static inline unsigned long sel_class_to_ino(u16 class) · 1 unmodified line
15441541
15451542 static inline u16 sel_ino_to_class(unsigned long ino)
15461543 {
1547− return sel_div(ino & SEL_INO_MASK, SEL_VEC_MAX + 1);
1544+ return (ino & SEL_INO_MASK) / (SEL_VEC_MAX + 1);
15481545 }
15491546
15501547 static inline unsigned long sel_perm_to_ino(u16 class, u32 perm)
@@ -1831,7 +1828,7 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent) · 280 unmodified lines
18311828 [SEL_REJECT_UNKNOWN] = {"reject_unknown", &sel_handle_unknown_ops, S_IRUGO},
18321829 [SEL_DENY_UNKNOWN] = {"deny_unknown", &sel_handle_unknown_ops, S_IRUGO},
18331830 [SEL_STATUS] = {"status", &sel_handle_status_ops, S_IRUGO},
1834− [SEL_POLICY] = {"policy", &sel_policy_ops, S_IRUSR},
1831+ [SEL_POLICY] = {"policy", &sel_policy_ops, S_IRUGO},
18351832 /* last one */ {""}
18361833 };
18371834 ret = simple_fill_super(sb, SELINUX_MAGIC, selinux_files);
security/selinux/ss/context.h+20−0
@@ -74,6 +74,26 @@ out: · 73 unmodified lines
7474 return rc;
7575 }
7676
77+/*
78+ * Sets both levels in the MLS range of 'dst' to the high level of 'src'.
79+ */
80+static inline int mls_context_cpy_high(struct context *dst, struct context *src)
81+{
82+ int rc;
83+
84+ dst->range.level[0].sens = src->range.level[1].sens;
85+ rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[1].cat);
86+ if (rc)
87+ goto out;
88+
89+ dst->range.level[1].sens = src->range.level[1].sens;
90+ rc = ebitmap_cpy(&dst->range.level[1].cat, &src->range.level[1].cat);
91+ if (rc)
92+ ebitmap_destroy(&dst->range.level[0].cat);
93+out:
94+ return rc;
95+}
96+
7797 static inline int mls_context_cmp(struct context *c1, struct context *c2)
7898 {
7999 return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
security/selinux/ss/mls.c+24−0
@@ -517,6 +517,8 @@ int mls_compute_sid(struct context *scontext, · 516 unmodified lines
517517 {
518518 struct range_trans rtr;
519519 struct mls_range *r;
520+ struct class_datum *cladatum;
521+ int default_range = 0;
520522
521523 if (!policydb.mls_enabled)
522524 return 0;
@@ -530,6 +532,28 @@ int mls_compute_sid(struct context *scontext, · 7 unmodified lines
530532 r = hashtab_search(policydb.range_tr, &rtr);
531533 if (r)
532534 return mls_range_set(newcontext, r);
535+
536+ if (tclass && tclass <= policydb.p_classes.nprim) {
537+ cladatum = policydb.class_val_to_struct[tclass - 1];
538+ if (cladatum)
539+ default_range = cladatum->default_range;
540+ }
541+
542+ switch (default_range) {
543+ case DEFAULT_SOURCE_LOW:
544+ return mls_context_cpy_low(newcontext, scontext);
545+ case DEFAULT_SOURCE_HIGH:
546+ return mls_context_cpy_high(newcontext, scontext);
547+ case DEFAULT_SOURCE_LOW_HIGH:
548+ return mls_context_cpy(newcontext, scontext);
549+ case DEFAULT_TARGET_LOW:
550+ return mls_context_cpy_low(newcontext, tcontext);
551+ case DEFAULT_TARGET_HIGH:
552+ return mls_context_cpy_high(newcontext, tcontext);
553+ case DEFAULT_TARGET_LOW_HIGH:
554+ return mls_context_cpy(newcontext, tcontext);
555+ }
556+
533557 /* Fallthrough */
534558 case AVTAB_CHANGE:
535559 if ((tclass == policydb.process_class) || (sock == true))
security/selinux/ss/policydb.c+44−0
@@ -133,6 +133,16 @@ static struct policydb_compat_info policydb_compat[] = { · 132 unmodified lines
133133 .sym_num = SYM_NUM,
134134 .ocon_num = OCON_NUM,
135135 },
136+ {
137+ .version = POLICYDB_VERSION_NEW_OBJECT_DEFAULTS,
138+ .sym_num = SYM_NUM,
139+ .ocon_num = OCON_NUM,
140+ },
141+ {
142+ .version = POLICYDB_VERSION_DEFAULT_TYPE,
143+ .sym_num = SYM_NUM,
144+ .ocon_num = OCON_NUM,
145+ },
136146 };
137147
138148 static struct policydb_compat_info *policydb_lookup_compat(int version)
@@ -1306,6 +1316,23 @@ static int class_read(struct policydb *p, struct hashtab *h, void *fp) · 1167 unmodified lines
13061316 goto bad;
13071317 }
13081318
1319+ if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) {
1320+ rc = next_entry(buf, fp, sizeof(u32) * 3);
1321+ if (rc)
1322+ goto bad;
1323+
1324+ cladatum->default_user = le32_to_cpu(buf[0]);
1325+ cladatum->default_role = le32_to_cpu(buf[1]);
1326+ cladatum->default_range = le32_to_cpu(buf[2]);
1327+ }
1328+
1329+ if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) {
1330+ rc = next_entry(buf, fp, sizeof(u32) * 1);
1331+ if (rc)
1332+ goto bad;
1333+ cladatum->default_type = le32_to_cpu(buf[0]);
1334+ }
1335+
13091336 rc = hashtab_insert(h, key, cladatum);
13101337 if (rc)
13111338 goto bad;
@@ -2832,6 +2859,23 @@ static int class_write(void *vkey, void *datum, void *ptr) · 1520 unmodified lines
28322859 if (rc)
28332860 return rc;
28342861
2862+ if (p->policyvers >= POLICYDB_VERSION_NEW_OBJECT_DEFAULTS) {
2863+ buf[0] = cpu_to_le32(cladatum->default_user);
2864+ buf[1] = cpu_to_le32(cladatum->default_role);
2865+ buf[2] = cpu_to_le32(cladatum->default_range);
2866+
2867+ rc = put_entry(buf, sizeof(uint32_t), 3, fp);
2868+ if (rc)
2869+ return rc;
2870+ }
2871+
2872+ if (p->policyvers >= POLICYDB_VERSION_DEFAULT_TYPE) {
2873+ buf[0] = cpu_to_le32(cladatum->default_type);
2874+ rc = put_entry(buf, sizeof(uint32_t), 1, fp);
2875+ if (rc)
2876+ return rc;
2877+ }
2878+
28352879 return 0;
28362880 }
28372881
security/selinux/ss/policydb.h+14−0
@@ -60,6 +60,20 @@ struct class_datum { · 59 unmodified lines
6060 struct symtab permissions; /* class-specific permission symbol table */
6161 struct constraint_node *constraints; /* constraints on class permissions */
6262 struct constraint_node *validatetrans; /* special transition rules */
63+/* Options how a new object user, role, and type should be decided */
64+#define DEFAULT_SOURCE 1
65+#define DEFAULT_TARGET 2
66+ char default_user;
67+ char default_role;
68+ char default_type;
69+/* Options how a new object range should be decided */
70+#define DEFAULT_SOURCE_LOW 1
71+#define DEFAULT_SOURCE_HIGH 2
72+#define DEFAULT_SOURCE_LOW_HIGH 3
73+#define DEFAULT_TARGET_LOW 4
74+#define DEFAULT_TARGET_HIGH 5
75+#define DEFAULT_TARGET_LOW_HIGH 6
76+ char default_range;
6377 };
6478
6579 /* Role attributes */
security/selinux/ss/services.c+40−16
@@ -1018,9 +1018,11 @@ static int context_struct_to_string(struct context *context, char **scontext, u3 · 1017 unmodified lines
10181018
10191019 if (context->len) {
10201020 *scontext_len = context->len;
1021− *scontext = kstrdup(context->str, GFP_ATOMIC);
1022− if (!(*scontext))
1023− return -ENOMEM;
1021+ if (scontext) {
1022+ *scontext = kstrdup(context->str, GFP_ATOMIC);
1023+ if (!(*scontext))
1024+ return -ENOMEM;
1025+ }
10241026 return 0;
10251027 }
10261028
@@ -1389,6 +1391,7 @@ static int security_compute_sid(u32 ssid, · 362 unmodified lines
13891391 u32 *out_sid,
13901392 bool kern)
13911393 {
1394+ struct class_datum *cladatum = NULL;
13921395 struct context *scontext = NULL, *tcontext = NULL, newcontext;
13931396 struct role_trans *roletr = NULL;
13941397 struct avtab_key avkey;
@@ -1437,12 +1440,20 @@ static int security_compute_sid(u32 ssid, · 42 unmodified lines
14371440 goto out_unlock;
14381441 }
14391442
1443+ if (tclass && tclass <= policydb.p_classes.nprim)
1444+ cladatum = policydb.class_val_to_struct[tclass - 1];
1445+
14401446 /* Set the user identity. */
14411447 switch (specified) {
14421448 case AVTAB_TRANSITION:
14431449 case AVTAB_CHANGE:
1444− /* Use the process user identity. */
1445− newcontext.user = scontext->user;
1450+ if (cladatum && cladatum->default_user == DEFAULT_TARGET) {
1451+ newcontext.user = tcontext->user;
1452+ } else {
1453+ /* notice this gets both DEFAULT_SOURCE and unset */
1454+ /* Use the process user identity. */
1455+ newcontext.user = scontext->user;
1456+ }
14461457 break;
14471458 case AVTAB_MEMBER:
14481459 /* Use the related object owner. */
@@ -1450,16 +1461,31 @@ static int security_compute_sid(u32 ssid, · 1 unmodified line
14501461 break;
14511462 }
14521463
1453− /* Set the role and type to default values. */
1454− if ((tclass == policydb.process_class) || (sock == true)) {
1455− /* Use the current role and type of process. */
1464+ /* Set the role to default values. */
1465+ if (cladatum && cladatum->default_role == DEFAULT_SOURCE) {
14561466 newcontext.role = scontext->role;
1457− newcontext.type = scontext->type;
1467+ } else if (cladatum && cladatum->default_role == DEFAULT_TARGET) {
1468+ newcontext.role = tcontext->role;
14581469 } else {
1459− /* Use the well-defined object role. */
1460− newcontext.role = OBJECT_R_VAL;
1461− /* Use the type of the related object. */
1470+ if ((tclass == policydb.process_class) || (sock == true))
1471+ newcontext.role = scontext->role;
1472+ else
1473+ newcontext.role = OBJECT_R_VAL;
1474+ }
1475+
1476+ /* Set the type to default values. */
1477+ if (cladatum && cladatum->default_type == DEFAULT_SOURCE) {
1478+ newcontext.type = scontext->type;
1479+ } else if (cladatum && cladatum->default_type == DEFAULT_TARGET) {
14621480 newcontext.type = tcontext->type;
1481+ } else {
1482+ if ((tclass == policydb.process_class) || (sock == true)) {
1483+ /* Use the type of process. */
1484+ newcontext.type = scontext->type;
1485+ } else {
1486+ /* Use the type of the related object. */
1487+ newcontext.type = tcontext->type;
1488+ }
14631489 }
14641490
14651491 /* Look for a type transition/member/change rule. */
@@ -3018,8 +3044,7 @@ out: · 1552 unmodified lines
30183044
30193045 static int (*aurule_callback)(void) = audit_update_lsm_rules;
30203046
3021−static int aurule_avc_callback(u32 event, u32 ssid, u32 tsid,
3022− u16 class, u32 perms, u32 *retained)
3047+static int aurule_avc_callback(u32 event)
30233048 {
30243049 int err = 0;
30253050
@@ -3032,8 +3057,7 @@ static int __init aurule_init(void) · 6 unmodified lines
30323057 {
30333058 int err;
30343059
3035− err = avc_add_callback(aurule_avc_callback, AVC_CALLBACK_RESET,
3036− SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0);
3060+ err = avc_add_callback(aurule_avc_callback, AVC_CALLBACK_RESET);
30373061 if (err)
30383062 panic("avc_add_callback() failed, error %d\n", err);
30393063
security/smack/smack.h+1−1
@@ -304,7 +304,7 @@ void smack_log(char *subject_label, char *object_label, · 303 unmodified lines
304304 static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
305305 char type)
306306 {
307− memset(a, 0, sizeof(*a));
307+ memset(&a->sad, 0, sizeof(a->sad));
308308 a->a.type = type;
309309 a->a.smack_audit_data = &a->sad;
310310 a->a.smack_audit_data->function = func;
security/smack/smack_lsm.c+3−3
@@ -1359,7 +1359,7 @@ static int smack_file_receive(struct file *file) · 1358 unmodified lines
13591359 }
13601360
13611361 /**
1362− * smack_dentry_open - Smack dentry open processing
1362+ * smack_file_open - Smack dentry open processing
13631363 * @file: the object
13641364 * @cred: unused
13651365 *
@@ -1367,7 +1367,7 @@ static int smack_file_receive(struct file *file) · 1 unmodified line
13671367 *
13681368 * Returns 0
13691369 */
1370−static int smack_dentry_open(struct file *file, const struct cred *cred)
1370+static int smack_file_open(struct file *file, const struct cred *cred)
13711371 {
13721372 struct inode_smack *isp = file->f_path.dentry->d_inode->i_security;
13731373
@@ -3487,7 +3487,7 @@ struct security_operations smack_ops = { · 2113 unmodified lines
34873487 .file_send_sigiotask = smack_file_send_sigiotask,
34883488 .file_receive = smack_file_receive,
34893489
3490− .dentry_open = smack_dentry_open,
3490+ .file_open = smack_file_open,
34913491
34923492 .cred_alloc_blank = smack_cred_alloc_blank,
34933493 .cred_free = smack_cred_free,
security/tomoyo/tomoyo.c+3−3
@@ -319,14 +319,14 @@ static int tomoyo_file_fcntl(struct file *file, unsigned int cmd, · 318 unmodified lines
319319 }
320320
321321 /**
322− * tomoyo_dentry_open - Target for security_dentry_open().
322+ * tomoyo_file_open - Target for security_file_open().
323323 *
324324 * @f: Pointer to "struct file".
325325 * @cred: Pointer to "struct cred".
326326 *
327327 * Returns 0 on success, negative value otherwise.
328328 */
329−static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
329+static int tomoyo_file_open(struct file *f, const struct cred *cred)
330330 {
331331 int flags = f->f_flags;
332332 /* Don't check read permission here if called from do_execve(). */
@@ -510,7 +510,7 @@ static struct security_operations tomoyo_security_ops = { · 177 unmodified lines
510510 .bprm_set_creds = tomoyo_bprm_set_creds,
511511 .bprm_check_security = tomoyo_bprm_check_security,
512512 .file_fcntl = tomoyo_file_fcntl,
513− .dentry_open = tomoyo_dentry_open,
513+ .file_open = tomoyo_file_open,
514514 .path_truncate = tomoyo_path_truncate,
515515 .path_unlink = tomoyo_path_unlink,
516516 .path_mkdir = tomoyo_path_mkdir,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t