forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/security/selinux/ss/context.h
....@@ -31,7 +31,6 @@
3131 u32 len; /* length of string in bytes */
3232 struct mls_range range;
3333 char *str; /* string representation if context cannot be mapped. */
34
- u32 hash; /* a hash of the string representation */
3534 };
3635
3736 static inline void mls_context_init(struct context *c)
....@@ -96,6 +95,38 @@
9695 return rc;
9796 }
9897
98
+
99
+static inline int mls_context_glblub(struct context *dst,
100
+ struct context *c1, struct context *c2)
101
+{
102
+ struct mls_range *dr = &dst->range, *r1 = &c1->range, *r2 = &c2->range;
103
+ int rc = 0;
104
+
105
+ if (r1->level[1].sens < r2->level[0].sens ||
106
+ r2->level[1].sens < r1->level[0].sens)
107
+ /* These ranges have no common sensitivities */
108
+ return -EINVAL;
109
+
110
+ /* Take the greatest of the low */
111
+ dr->level[0].sens = max(r1->level[0].sens, r2->level[0].sens);
112
+
113
+ /* Take the least of the high */
114
+ dr->level[1].sens = min(r1->level[1].sens, r2->level[1].sens);
115
+
116
+ rc = ebitmap_and(&dr->level[0].cat,
117
+ &r1->level[0].cat, &r2->level[0].cat);
118
+ if (rc)
119
+ goto out;
120
+
121
+ rc = ebitmap_and(&dr->level[1].cat,
122
+ &r1->level[1].cat, &r2->level[1].cat);
123
+ if (rc)
124
+ goto out;
125
+
126
+out:
127
+ return rc;
128
+}
129
+
99130 static inline int mls_context_cmp(struct context *c1, struct context *c2)
100131 {
101132 return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
....@@ -137,13 +168,12 @@
137168 kfree(dst->str);
138169 return rc;
139170 }
140
- dst->hash = src->hash;
141171 return 0;
142172 }
143173
144174 static inline void context_destroy(struct context *c)
145175 {
146
- c->user = c->role = c->type = c->hash = 0;
176
+ c->user = c->role = c->type = 0;
147177 kfree(c->str);
148178 c->str = NULL;
149179 c->len = 0;
....@@ -152,8 +182,6 @@
152182
153183 static inline int context_cmp(struct context *c1, struct context *c2)
154184 {
155
- if (c1->hash && c2->hash && (c1->hash != c2->hash))
156
- return 0;
157185 if (c1->len && c2->len)
158186 return (c1->len == c2->len && !strcmp(c1->str, c2->str));
159187 if (c1->len || c2->len)
....@@ -164,10 +192,7 @@
164192 mls_context_cmp(c1, c2));
165193 }
166194
167
-static inline unsigned int context_compute_hash(const char *s)
168
-{
169
- return full_name_hash(NULL, s, strlen(s));
170
-}
195
+u32 context_compute_hash(const struct context *c);
171196
172197 #endif /* _SS_CONTEXT_H_ */
173198