[PATCH] selinux_restorecon: Do not exit on directory cycles

Johannes Segitz <[email protected]> Thu, 23 Jul 2026 10:55:21 +0200
Newsgroups org.kernel.vger.selinux
Message-ID <[email protected]>
All other failures are handled gracefully. Directory cycles can e.g.
happen on BTRFS filesystems with subvolumes. Skip them and continue
instead of exiting
---
 libselinux/src/selinux_restorecon.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
index 30f1b836..fdefc92c 100644
--- a/libselinux/src/selinux_restorecon.c
+++ b/libselinux/src/selinux_restorecon.c
@@ -1393,15 +1393,14 @@ static void *selinux_restorecon_thread(void *arg)
                if (is_dir) {
                        if (descend && walk_is_cycle(state, ent_sb.st_dev,
                                                     ent_sb.st_ino)) {
-                               selinux_log(SELINUX_ERROR,
+                               selinux_log(SELINUX_WARNING,
                                            "Directory cycle on %s.\n",
                                            ent_path);
                                close(ent_fd);
-                               close(rd_fd);
-                               errno = ELOOP;
-                               state->error = -1;
-                               state->abort = true;
-                               goto finish;
+                               if (rd_fd >= 0)
+                                       close(rd_fd);
+                               prune_pathbuf(state);
+                               continue;
                        }

                        if (state->sfsb.f_type == SYSFS_MAGIC &&
--
2.55.0
signature.asc (application/pgp-signature, 870 B)
-----BEGIN PGP SIGNATURE-----

iQJPBAEBCgA5FiEEJQ9D9ffObx6cWU+VvCfdnSzE/WYFAmph1vkbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwyAAoJELwn3Z0sxP1mCCgP/jrWoqZRJHCN13vpINua
OUgffskwlxNaXJEyrn34WMkQFSG4XuqX6XaLX8ubqBe0xfLdnnPCXUAhri691ILY
evRpqkqSkJOHQh+mGtuDmyyRY5CRn3oe56ud1yhnHz4yjqz2A4+Wzh1U/5wYVD5S
W8j/o6HQf0/lPhHOIA+pPO7VYV1Nz5XrccwZjM9Mxmb1TSwda6WPLVTTTeveZlxy
gEC2sk7lIuR2ZQjBQ/LOnw5m6CpekJYQNWJ7ZJAXSbaWLiTAw2z82G9HjK29nKBW
srYAmkgHTx4L6QBYbK+dG/Ip+IQ2obC1dPBUmqLYYJjQO0hAT2Eod1QQbxWG8O/N
TSKmVafO4L7nXQKTDoKbrTS5T2+9+IfQI7cXHKlnFaidAuw8Mz6SfOgsTbQTFnKc
m+oXK4dbempvwLm85W7M6soO3X6QoIpFG8ADgTfRgs91QNmFy4AKbTuV5VWnwrVB
gYuhBnsG1dFVXovCzEvbrxAVplYR372fci9nglHqkWK9DZUFD9C396k/io3q+Rn2
YQ6g4+v6BzZdJqQwz6hFRI7Fg376C7Tv8KGVjbAGZBwjJNW+pEpKFZCdqKFFhweo
7NeRjxWgpdibLV8zZd1G2/GnHAfOjrp2VtQ0ox/PNtV1fa47je+RPJbHsrmoXO5e
PosrT2mUh3gCCS+QtJn1oWNW
=+PhR
-----END PGP SIGNATURE-----