Skip to contentSkip to conversation

libselinux: selinux_restorecon(): fstat() if skip_multilink set

PATCH Applied Stephen Smalley 2 participants 3 messages Jun 28 – Jul 1 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libselinux: selinux_restorecon(): fstat() if skip_multilink set

selinux_restorecon() must call fstat() on every entry if skip_multilink is set to fetch the st_nlink value.

---
 libselinux/src/selinux_restorecon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
libselinux/src/selinux_restorecon.c +4 -2
index 0159fb7f..b34d8e60 100644
@@ -1271,13 +1271,15 @@ static int walk_next(struct rest_state *state, int *ent_fd, int *rd_fd,
 
 		/*
 		 * Skip fstat() when d_type already gives the file type and
-		 * neither xdev (st_dev) nor add_assoc (st_ino) is needed.
+		 * none of xdev (st_dev), add_assoc (st_ino), or
+		 * skip_multilink (st_nlink) are needed.
 		 * Directories always fstat for cycle detection and walk_push().
 		 */
 		mode_t mode_from_dtype = d_type_to_mode(de->d_type);
 		bool need_fstat =
 			mode_from_dtype == 0 || S_ISDIR(mode_from_dtype) ||
-			state->flags.set_xdev || state->flags.add_assoc;
+			state->flags.set_xdev || state->flags.add_assoc ||
+			state->flags.skip_multilink;
 
 		if (need_fstat) {
 			if (fstat(fd, ent_sb) < 0) {
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Stephen Smalley

selinux_restorecon() must call fstat() on every entry if skip_multilink is set to fetch the st_nlink value.

Quoted 28 lines
---
 libselinux/src/selinux_restorecon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
libselinux/src/selinux_restorecon.c +4 -2
index 0159fb7f..b34d8e60 100644
@@ -1271,13 +1271,15 @@ static int walk_next(struct rest_state *state, int *ent_fd, int *rd_fd,
 
 		/*
 		 * Skip fstat() when d_type already gives the file type and
-		 * neither xdev (st_dev) nor add_assoc (st_ino) is needed.
+		 * none of xdev (st_dev), add_assoc (st_ino), or
+		 * skip_multilink (st_nlink) are needed.
 		 * Directories always fstat for cycle detection and walk_push().
 		 */
 		mode_t mode_from_dtype = d_type_to_mode(de->d_type);
 		bool need_fstat =
 			mode_from_dtype == 0 || S_ISDIR(mode_from_dtype) ||
-			state->flags.set_xdev || state->flags.add_assoc;
+			state->flags.set_xdev || state->flags.add_assoc ||
+			state->flags.skip_multilink;
 
 		if (need_fstat) {
 			if (fstat(fd, ent_sb) < 0) {
Signature · 1 line
2.54.0
#2 lore raw
Quoted 8 lines · Petr Lautrbach
Quoted 4 lines · Stephen Smalley

selinux_restorecon() must call fstat() on every entry if skip_multilink is set to fetch the st_nlink value.

Merged, thanks!

Quoted 29 lines
Quoted 29 lines
---
 libselinux/src/selinux_restorecon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
libselinux/src/selinux_restorecon.c +4 -2
index 0159fb7f..b34d8e60 100644
@@ -1271,13 +1271,15 @@ static int walk_next(struct rest_state *state, int *ent_fd, int *rd_fd,
 
 		/*
 		 * Skip fstat() when d_type already gives the file type and
-		 * neither xdev (st_dev) nor add_assoc (st_ino) is needed.
+		 * none of xdev (st_dev), add_assoc (st_ino), or
+		 * skip_multilink (st_nlink) are needed.
 		 * Directories always fstat for cycle detection and walk_push().
 		 */
 		mode_t mode_from_dtype = d_type_to_mode(de->d_type);
 		bool need_fstat =
 			mode_from_dtype == 0 || S_ISDIR(mode_from_dtype) ||
-			state->flags.set_xdev || state->flags.add_assoc;
+			state->flags.set_xdev || state->flags.add_assoc ||
+			state->flags.skip_multilink;
 
 		if (need_fstat) {
 			if (fstat(fd, ent_sb) < 0) {
Signature · 1 line
2.54.0