Skip to content

Commit 4c210f8

Browse files
stephensmalleygregkh
authored andcommitted
selinux: access policycaps with READ_ONCE/WRITE_ONCE
[ Upstream commit e8ba53d ] Use READ_ONCE/WRITE_ONCE for all accesses to the selinux_state.policycaps booleans to prevent compiler mischief. Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4388ceb commit 4c210f8

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

security/selinux/include/security.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,49 +177,49 @@ static inline bool selinux_policycap_netpeer(void)
177177
{
178178
struct selinux_state *state = &selinux_state;
179179

180-
return state->policycap[POLICYDB_CAPABILITY_NETPEER];
180+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_NETPEER]);
181181
}
182182

183183
static inline bool selinux_policycap_openperm(void)
184184
{
185185
struct selinux_state *state = &selinux_state;
186186

187-
return state->policycap[POLICYDB_CAPABILITY_OPENPERM];
187+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_OPENPERM]);
188188
}
189189

190190
static inline bool selinux_policycap_extsockclass(void)
191191
{
192192
struct selinux_state *state = &selinux_state;
193193

194-
return state->policycap[POLICYDB_CAPABILITY_EXTSOCKCLASS];
194+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_EXTSOCKCLASS]);
195195
}
196196

197197
static inline bool selinux_policycap_alwaysnetwork(void)
198198
{
199199
struct selinux_state *state = &selinux_state;
200200

201-
return state->policycap[POLICYDB_CAPABILITY_ALWAYSNETWORK];
201+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_ALWAYSNETWORK]);
202202
}
203203

204204
static inline bool selinux_policycap_cgroupseclabel(void)
205205
{
206206
struct selinux_state *state = &selinux_state;
207207

208-
return state->policycap[POLICYDB_CAPABILITY_CGROUPSECLABEL];
208+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_CGROUPSECLABEL]);
209209
}
210210

211211
static inline bool selinux_policycap_nnp_nosuid_transition(void)
212212
{
213213
struct selinux_state *state = &selinux_state;
214214

215-
return state->policycap[POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION];
215+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION]);
216216
}
217217

218218
static inline bool selinux_policycap_genfs_seclabel_symlinks(void)
219219
{
220220
struct selinux_state *state = &selinux_state;
221221

222-
return state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS];
222+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS]);
223223
}
224224

225225
int security_mls_enabled(struct selinux_state *state);

security/selinux/ss/services.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,8 @@ static void security_load_policycaps(struct selinux_state *state)
21032103
struct ebitmap_node *node;
21042104

21052105
for (i = 0; i < ARRAY_SIZE(state->policycap); i++)
2106-
state->policycap[i] = ebitmap_get_bit(&p->policycaps, i);
2106+
WRITE_ONCE(state->policycap[i],
2107+
ebitmap_get_bit(&p->policycaps, i));
21072108

21082109
for (i = 0; i < ARRAY_SIZE(selinux_policycap_names); i++)
21092110
pr_info("SELinux: policy capability %s=%d\n",

0 commit comments

Comments
 (0)