Commit 46afc66
committed
libselinux: stringrep: serialize access to the discover_class_cache
The discover_class_cache list is accessed without locking by the
string_to_*() and *_to_string() functions in libselinux for
translating between string names and class/perm values, and returns
pointers to strings within this list to callers.
selinux_flush_class_cache() frees the list upon a policy reload,
called by avc_process_policyload() from selinux_status_updated() and
avc_netlink_process().
Make this safe for multi-threaded users by introducing and taking a
mutex around the list accesses, and by moving flushed nodes to a
retired list rather than freeing them so that returned string pointers
remain valid. Given the infrequency of policy reloads, the relative
stability of the class/perm mapping even across policy reloads, and
the small amount of memory required, this seems a worthwhile tradeoff.
If it becomes an issue, there are several options:
1. Only load/refresh new/modified class/permission names and values
upon policy reload rather than flushing and reloading them all,
2. Provide a way to drain the retired list safely when the application
knows it is no longer using any returned strings.
Fixes: SELinuxProject#287 SELinuxProject#335 SELinuxProject#336
Link: https://lore.kernel.org/selinux/CAJsHiNx1E7x1jaBkS0i4L1nBWXp8YXLHRWcCaDaH4LOn=zm+Zw@mail.gmail.com/
Link: https://lore.kernel.org/selinux/20220120073329.15234-1-purushottamchoudhary29@gmail.com/
Reported-by: Seth Moore <sethmo@google.com>
Reported-by: Purushottam Choudhary <purushottamchoudhary29@gmail.com>
Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>1 parent 6d855c0 commit 46afc66
1 file changed
Lines changed: 87 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
156 | 158 | | |
157 | 159 | | |
158 | 160 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | 161 | | |
163 | 162 | | |
164 | 163 | | |
| |||
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 178 | + | |
189 | 179 | | |
190 | | - | |
191 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
192 | 183 | | |
193 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
194 | 202 | | |
195 | | - | |
196 | | - | |
| 203 | + | |
197 | 204 | | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
201 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
202 | 211 | | |
| 212 | + | |
203 | 213 | | |
204 | | - | |
205 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
206 | 220 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
211 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
212 | 254 | | |
213 | | - | |
| 255 | + | |
214 | 256 | | |
215 | 257 | | |
216 | 258 | | |
| |||
239 | 281 | | |
240 | 282 | | |
241 | 283 | | |
| 284 | + | |
242 | 285 | | |
243 | 286 | | |
244 | 287 | | |
245 | 288 | | |
246 | | - | |
| 289 | + | |
| 290 | + | |
247 | 291 | | |
| 292 | + | |
248 | 293 | | |
| 294 | + | |
249 | 295 | | |
250 | 296 | | |
251 | 297 | | |
| |||
254 | 300 | | |
255 | 301 | | |
256 | 302 | | |
| 303 | + | |
257 | 304 | | |
258 | 305 | | |
259 | 306 | | |
| 307 | + | |
260 | 308 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
265 | 313 | | |
266 | 314 | | |
267 | 315 | | |
268 | 316 | | |
269 | 317 | | |
270 | 318 | | |
271 | 319 | | |
| 320 | + | |
272 | 321 | | |
273 | 322 | | |
274 | 323 | | |
275 | 324 | | |
| 325 | + | |
276 | 326 | | |
277 | 327 | | |
278 | 328 | | |
279 | | - | |
280 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
281 | 334 | | |
| 335 | + | |
282 | 336 | | |
283 | 337 | | |
284 | 338 | | |
| |||
0 commit comments