~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/security/selinux/ss/context.h

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * A security context is a set of security attributes
  4  * associated with each subject and object controlled
  5  * by the security policy.  Security contexts are
  6   * externally represented as variable-length strings
  7  * that can be interpreted by a user or application
  8  * with an understanding of the security policy.
  9  * Internally, the security server uses a simple
 10  * structure.  This structure is private to the
 11  * security server and can be changed without affecting
 12  * clients of the security server.
 13  *
 14  * Author : Stephen Smalley, <sds@tycho.nsa.gov>
 15  */
 16 #ifndef _SS_CONTEXT_H_
 17 #define _SS_CONTEXT_H_
 18 
 19 #include "ebitmap.h"
 20 #include "mls_types.h"
 21 #include "security.h"
 22 
 23 /*
 24  * A security context consists of an authenticated user
 25  * identity, a role, a type and a MLS range.
 26  */
 27 struct context {
 28         u32 user;
 29         u32 role;
 30         u32 type;
 31         u32 len;        /* length of string in bytes */
 32         struct mls_range range;
 33         char *str;      /* string representation if context cannot be mapped. */
 34 };
 35 
 36 static inline void mls_context_init(struct context *c)
 37 {
 38         memset(&c->range, 0, sizeof(c->range));
 39 }
 40 
 41 static inline int mls_context_cpy(struct context *dst, struct context *src)
 42 {
 43         int rc;
 44 
 45         dst->range.level[0].sens = src->range.level[0].sens;
 46         rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[0].cat);
 47         if (rc)
 48                 goto out;
 49 
 50         dst->range.level[1].sens = src->range.level[1].sens;
 51         rc = ebitmap_cpy(&dst->range.level[1].cat, &src->range.level[1].cat);
 52         if (rc)
 53                 ebitmap_destroy(&dst->range.level[0].cat);
 54 out:
 55         return rc;
 56 }
 57 
 58 /*
 59  * Sets both levels in the MLS range of 'dst' to the low level of 'src'.
 60  */
 61 static inline int mls_context_cpy_low(struct context *dst, struct context *src)
 62 {
 63         int rc;
 64 
 65         dst->range.level[0].sens = src->range.level[0].sens;
 66         rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[0].cat);
 67         if (rc)
 68                 goto out;
 69 
 70         dst->range.level[1].sens = src->range.level[0].sens;
 71         rc = ebitmap_cpy(&dst->range.level[1].cat, &src->range.level[0].cat);
 72         if (rc)
 73                 ebitmap_destroy(&dst->range.level[0].cat);
 74 out:
 75         return rc;
 76 }
 77 
 78 /*
 79  * Sets both levels in the MLS range of 'dst' to the high level of 'src'.
 80  */
 81 static inline int mls_context_cpy_high(struct context *dst, struct context *src)
 82 {
 83         int rc;
 84 
 85         dst->range.level[0].sens = src->range.level[1].sens;
 86         rc = ebitmap_cpy(&dst->range.level[0].cat, &src->range.level[1].cat);
 87         if (rc)
 88                 goto out;
 89 
 90         dst->range.level[1].sens = src->range.level[1].sens;
 91         rc = ebitmap_cpy(&dst->range.level[1].cat, &src->range.level[1].cat);
 92         if (rc)
 93                 ebitmap_destroy(&dst->range.level[0].cat);
 94 out:
 95         return rc;
 96 }
 97 
 98 static inline int mls_context_cmp(struct context *c1, struct context *c2)
 99 {
100         return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
101                 ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
102                 (c1->range.level[1].sens == c2->range.level[1].sens) &&
103                 ebitmap_cmp(&c1->range.level[1].cat, &c2->range.level[1].cat));
104 }
105 
106 static inline void mls_context_destroy(struct context *c)
107 {
108         ebitmap_destroy(&c->range.level[0].cat);
109         ebitmap_destroy(&c->range.level[1].cat);
110         mls_context_init(c);
111 }
112 
113 static inline void context_init(struct context *c)
114 {
115         memset(c, 0, sizeof(*c));
116 }
117 
118 static inline int context_cpy(struct context *dst, struct context *src)
119 {
120         int rc;
121 
122         dst->user = src->user;
123         dst->role = src->role;
124         dst->type = src->type;
125         if (src->str) {
126                 dst->str = kstrdup(src->str, GFP_ATOMIC);
127                 if (!dst->str)
128                         return -ENOMEM;
129                 dst->len = src->len;
130         } else {
131                 dst->str = NULL;
132                 dst->len = 0;
133         }
134         rc = mls_context_cpy(dst, src);
135         if (rc) {
136                 kfree(dst->str);
137                 return rc;
138         }
139         return 0;
140 }
141 
142 static inline void context_destroy(struct context *c)
143 {
144         c->user = c->role = c->type = 0;
145         kfree(c->str);
146         c->str = NULL;
147         c->len = 0;
148         mls_context_destroy(c);
149 }
150 
151 static inline int context_cmp(struct context *c1, struct context *c2)
152 {
153         if (c1->len && c2->len)
154                 return (c1->len == c2->len && !strcmp(c1->str, c2->str));
155         if (c1->len || c2->len)
156                 return 0;
157         return ((c1->user == c2->user) &&
158                 (c1->role == c2->role) &&
159                 (c1->type == c2->type) &&
160                 mls_context_cmp(c1, c2));
161 }
162 
163 #endif  /* _SS_CONTEXT_H_ */
164 
165 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp