Skip to content

Commit 4944029

Browse files
committed
landlock: Handle weird files
A corrupted filesystem (e.g. bcachefs) might return weird files. Instead of throwing a warning and allowing access to such file, treat them as regular files. Cc: Dave Chinner <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Paul Moore <[email protected]> Reported-by: [email protected] Closes: https://lore.kernel.org/r/[email protected] Reported-by: [email protected] Closes: https://lore.kernel.org/r/[email protected] Reported-by: Ubisectech Sirius <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Fixes: cb2c7d1 ("landlock: Support filesystem access-control") Reviewed-by: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 078bf94 commit 4944029

File tree

1 file changed

+5
-6
lines changed
  • security/landlock

1 file changed

+5
-6
lines changed

security/landlock/fs.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,6 @@ static access_mask_t get_mode_access(const umode_t mode)
937937
switch (mode & S_IFMT) {
938938
case S_IFLNK:
939939
return LANDLOCK_ACCESS_FS_MAKE_SYM;
940-
case 0:
941-
/* A zero mode translates to S_IFREG. */
942-
case S_IFREG:
943-
return LANDLOCK_ACCESS_FS_MAKE_REG;
944940
case S_IFDIR:
945941
return LANDLOCK_ACCESS_FS_MAKE_DIR;
946942
case S_IFCHR:
@@ -951,9 +947,12 @@ static access_mask_t get_mode_access(const umode_t mode)
951947
return LANDLOCK_ACCESS_FS_MAKE_FIFO;
952948
case S_IFSOCK:
953949
return LANDLOCK_ACCESS_FS_MAKE_SOCK;
950+
case S_IFREG:
951+
case 0:
952+
/* A zero mode translates to S_IFREG. */
954953
default:
955-
WARN_ON_ONCE(1);
956-
return 0;
954+
/* Treats weird files as regular files. */
955+
return LANDLOCK_ACCESS_FS_MAKE_REG;
957956
}
958957
}
959958

0 commit comments

Comments
 (0)