Skip to contentSkip to conversation

landlock: Remove warning in collect_domain_accesses()

PATCH In review Mickaël Salaün 2 participants 3 messages Jun 18, 2025 – Jul 1, 2025

Subsystems (2)
lore
Share & tools
lore

Mickaël Salaün

author maintainer
#0 lore raw

PATCH 1/1 landlock: Remove warning in collect_domain_accesses()

As in is_access_to_paths_allowed(), it is also possible to reach disconnected root directories in collect_domain_accesses().

Remove a wrong WARN_ON_ONCE() canary in collect_domain_accesses() and fix comment. Using an unlikely() annotation doesn't seem appropriate here. A following patch from Tingmao tests this case [1].

Cc Günther Noack <[email protected]>
Fixes b91c3e4ea756 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER")
---
 security/landlock/fs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/landlock/fs.c +2 -2
index 6fee7c20f64d..1d6c4e728f92 100644
@@ -1061,8 +1061,8 @@ static bool collect_domain_accesses(
 			break;
 		}
 
-		/* We should not reach a root other than @mnt_root. */
-		if (dir == mnt_root || WARN_ON_ONCE(IS_ROOT(dir)))
+		/* Stops at the mount point or disconnected root directories. */
+		if (dir == mnt_root || IS_ROOT(dir))
 			break;
 
 		parent_dentry = dget_parent(dir);
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Mickaël Salaün

As in is_access_to_paths_allowed(), it is also possible to reach disconnected root directories in collect_domain_accesses().

Remove a wrong WARN_ON_ONCE() canary in collect_domain_accesses() and fix comment. Using an unlikely() annotation doesn't seem appropriate here. A following patch from Tingmao tests this case [1].

Cc Günther Noack <[email protected]>
Fixes b91c3e4ea756 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER")
---
 security/landlock/fs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/landlock/fs.c +2 -2
index 6fee7c20f64d..1d6c4e728f92 100644
@@ -1061,8 +1061,8 @@ static bool collect_domain_accesses(
 			break;
 		}
 
-		/* We should not reach a root other than @mnt_root. */
-		if (dir == mnt_root || WARN_ON_ONCE(IS_ROOT(dir)))
+		/* Stops at the mount point or disconnected root directories. */
+		if (dir == mnt_root || IS_ROOT(dir))
 			break;
 
 		parent_dentry = dget_parent(dir);
Signature · 1 line
2.49.0
author maintainer
#2 lore raw
In reply to Mickaël Salaün
Quoted 7 lines · Mickaël Salaün

As in is_access_to_paths_allowed(), it is also possible to reach disconnected root directories in collect_domain_accesses().

Remove a wrong WARN_ON_ONCE() canary in collect_domain_accesses() and fix comment. Using an unlikely() annotation doesn't seem appropriate here. A following patch from Tingmao tests this case [1].

Quoted 5 lines
Cc Günther Noack <[email protected]>
Fixes b91c3e4ea756 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER")

This patch hides an edge cases that I though wasn't supposed to happen. I'll drop it in favor of this other patch which fixes the underlying issue:
https://lore.kernel.org/all/[email protected]/

Quoted 23 lines
---
 security/landlock/fs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/landlock/fs.c +2 -2
index 6fee7c20f64d..1d6c4e728f92 100644
@@ -1061,8 +1061,8 @@ static bool collect_domain_accesses(
 			break;
 		}
 
-		/* We should not reach a root other than @mnt_root. */
-		if (dir == mnt_root || WARN_ON_ONCE(IS_ROOT(dir)))
+		/* Stops at the mount point or disconnected root directories. */
+		if (dir == mnt_root || IS_ROOT(dir))
 			break;
 
 		parent_dentry = dget_parent(dir);
Signature · 1 line
2.49.0