Skip to contentSkip to conversation

selinux_restorecon: Do not exit on directory cycles

PATCH Superseded Johannes Segitz 2 participants 3 messages Jul 27 – Jul 28 SELinux security module

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selinux_restorecon: Do not exit on directory cycles

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(-)
libselinux/src/selinux_restorecon.c +5 -6
index 30f1b836..fdefc92c 100644
@@ -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 &&
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 20 lines · Johannes Segitz

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(-)
libselinux/src/selinux_restorecon.c +1 -1
index 30f1b836..fdefc92c 100644
@@ -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,

libselinux/src/selinux_restorecon.c static void *selinux_restorecon_thread(void *arg) · line 1401

Quoted 10 lines
libselinux/src/selinux_restorecon.c +2 -5
                                            "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);

As before, you don't need the if (rd_fd >= 0) test here because this is under an if (descend...)
so it is a tautology. And i thought you were going to explicitly note the change in behavior via
e.g. a man page update or similar?

Quoted 9 lines
libselinux/src/selinux_restorecon.c +2 -1
+                               prune_pathbuf(state);
+                               continue;
                        }
 
                        if (state->sfsb.f_type == SYSFS_MAGIC &&
--

2.55.0

#2 lore raw
Quoted 29 lines · Stephen Smalley
Quoted 28 lines · Johannes Segitz

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(-)
libselinux/src/selinux_restorecon.c +1 -6
index 30f1b836..fdefc92c 100644
@@ -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;
Quoted 8 lines

libselinux/src/selinux_restorecon.c static void *selinux_restorecon_thread(void *arg) · line 1401

Quoted 2 lines
libselinux/src/selinux_restorecon.c +2 -0
+                               if (rd_fd >= 0)
+                                       close(rd_fd);

As before, you don't need the if (rd_fd >= 0) test here because this is under an if (descend...)
so it is a tautology. And i thought you were going to explicitly note the change in behavior via
e.g. a man page update or similar?

yes, I might have gotten carried away that I finally beat git send-email into submission that I sent the wrong patch ... v4 will be there in a sec, sorry

Johannes

Signature · 4 lines
GPG Key                EE16 6BCE AD56 E034 BFB3  3ADD 7BF7 29D5 E7C8 1FA0
Subkey fingerprint:    250F 43F5 F7CE 6F1E 9C59  4F95 BC27 DD9D 2CC4 FD66
SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg, Germany
www.suse.com, Geschäftsführer: Jochen Jaser, Andrew McDonald, Abhinav Puri, (HRB 36809, AG Nürnberg)