Commit 4a0b33f
selinux: saner handling of policy reloads
On policy reload selinuxfs replaces two subdirectories (/booleans
and /class) with new variants. Unfortunately, that's done with
serious abuses of directory locking.
1) lock_rename() should be done to parents, not to objects being
exchanged
2) there's a bunch of reasons why it should not be done for directories
that do not have a common ancestor; most of those do not apply to
selinuxfs, but even in the best case the proof is subtle and brittle.
3) failure halfway through the creation of /class will leak
names and values arrays.
4) use of d_genocide() is also rather brittle; it's probably not much of
a bug per se, but e.g. an overmount of /sys/fs/selinuxfs/classes/shm/index
with any regular file will end up with leaked mount on policy reload.
Sure, don't do it, but...
Let's stop messing with disconnected directories; just create
a temporary (/.swapover) with no permissions for anyone (on the
level of ->permission() returing -EPERM, no matter who's calling
it) and build the new /booleans and /class in there; then
lock_rename on root and that temporary directory and d_exchange()
old and new both for class and booleans. Then unlock and use
simple_recursive_removal() to take the temporary out; it's much
more robust.
And instead of bothering with separate pathways for freeing
new (on failure halfway through) and old (on success) names/values,
do all freeing in one place. With temporaries swapped with the
old ones when we are past all possible failures.
The only user-visible difference is that /.swapover shows up
(but isn't possible to open, look up into, etc.) for the
duration of policy reload.
Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
[PM: applied some fixes from Al post merge]
Signed-off-by: Paul Moore <paul@paul-moore.com>1 parent b85ea95 commit 4a0b33f
1 file changed
Lines changed: 66 additions & 78 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | 342 | | |
346 | 343 | | |
347 | 344 | | |
| |||
508 | 505 | | |
509 | 506 | | |
510 | 507 | | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
515 | 512 | | |
516 | 513 | | |
517 | | - | |
| 514 | + | |
518 | 515 | | |
519 | 516 | | |
520 | 517 | | |
| |||
532 | 529 | | |
533 | 530 | | |
534 | 531 | | |
535 | | - | |
536 | | - | |
| 532 | + | |
| 533 | + | |
537 | 534 | | |
538 | 535 | | |
539 | 536 | | |
| |||
542 | 539 | | |
543 | 540 | | |
544 | 541 | | |
| 542 | + | |
| 543 | + | |
545 | 544 | | |
546 | | - | |
547 | | - | |
548 | 545 | | |
549 | 546 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
559 | 550 | | |
560 | 551 | | |
561 | | - | |
562 | 552 | | |
563 | 553 | | |
564 | | - | |
565 | | - | |
566 | 554 | | |
567 | 555 | | |
568 | | - | |
| 556 | + | |
| 557 | + | |
569 | 558 | | |
570 | 559 | | |
| 560 | + | |
571 | 561 | | |
572 | 562 | | |
573 | 563 | | |
574 | 564 | | |
575 | | - | |
576 | | - | |
| 565 | + | |
577 | 566 | | |
578 | 567 | | |
579 | 568 | | |
| |||
1351 | 1340 | | |
1352 | 1341 | | |
1353 | 1342 | | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | 1343 | | |
1361 | 1344 | | |
1362 | 1345 | | |
1363 | 1346 | | |
1364 | 1347 | | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
| 1348 | + | |
1370 | 1349 | | |
1371 | | - | |
1372 | | - | |
1373 | 1350 | | |
1374 | | - | |
1375 | 1351 | | |
1376 | 1352 | | |
1377 | | - | |
| 1353 | + | |
1378 | 1354 | | |
1379 | | - | |
| 1355 | + | |
1380 | 1356 | | |
1381 | 1357 | | |
1382 | 1358 | | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
1383 | 1362 | | |
1384 | | - | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
1385 | 1374 | | |
1386 | | - | |
1387 | | - | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
1388 | 1379 | | |
1389 | | - | |
1390 | 1380 | | |
1391 | 1381 | | |
1392 | 1382 | | |
1393 | | - | |
1394 | | - | |
1395 | | - | |
1396 | | - | |
1397 | | - | |
1398 | | - | |
1399 | | - | |
1400 | | - | |
1401 | | - | |
| 1383 | + | |
| 1384 | + | |
1402 | 1385 | | |
1403 | 1386 | | |
1404 | 1387 | | |
| |||
1416 | 1399 | | |
1417 | 1400 | | |
1418 | 1401 | | |
1419 | | - | |
1420 | | - | |
1421 | | - | |
1422 | | - | |
1423 | | - | |
1424 | | - | |
1425 | 1402 | | |
1426 | 1403 | | |
1427 | | - | |
1428 | | - | |
1429 | | - | |
1430 | | - | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | 1404 | | |
1437 | 1405 | | |
1438 | 1406 | | |
| |||
1961 | 1929 | | |
1962 | 1930 | | |
1963 | 1931 | | |
1964 | | - | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
1965 | 1943 | | |
1966 | 1944 | | |
1967 | | - | |
| 1945 | + | |
| 1946 | + | |
1968 | 1947 | | |
1969 | | - | |
| 1948 | + | |
1970 | 1949 | | |
1971 | 1950 | | |
1972 | | - | |
1973 | | - | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
1974 | 1958 | | |
1975 | 1959 | | |
1976 | 1960 | | |
1977 | | - | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
1978 | 1966 | | |
1979 | 1967 | | |
1980 | 1968 | | |
| |||
0 commit comments