Skip to content

Commit ba7c451

Browse files
committed
Extend landlock for more conditions
1 parent c008105 commit ba7c451

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/C/kcron_landlock.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ void set_kcron_landlock(void) {
109109
LANDLOCK_ACCESS_FS_MAKE_SYM;
110110

111111
/* Set allowed operations for the keytab directory */
112-
path_beneath.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG;
112+
path_beneath.allowed_access = LANDLOCK_ACCESS_FS_EXECUTE | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG;
113113

114114
/* ABI v2 - Add file renaming/linking control */
115115
if (landlock_abi >= 2) {
116116
ruleset_attr.handled_access_fs |= LANDLOCK_ACCESS_FS_REFER;
117+
path_beneath.allowed_access |= LANDLOCK_ACCESS_FS_REFER;
117118
}
118119

119120
/* ABI v3 - Add file truncation control */
@@ -162,9 +163,10 @@ void set_kcron_landlock(void) {
162163
* Open the parent directory with:
163164
* - O_RDONLY: Read-only access
164165
* - O_NOFOLLOW: Don't follow symlinks (security)
166+
* - O_DIRECTORY: Must be a directory
165167
* - O_CLOEXEC: Close on exec (defense in depth)
166168
*/
167-
parent_fd = open(dirname(client_keytab_parent), O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
169+
parent_fd = open(dirname(client_keytab_parent), O_RDONLY | O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC);
168170
if (parent_fd < 0) {
169171
(void)fprintf(stderr, "%s: Landlock cannot open parent directory %s: %s\n", __PROGRAM_NAME, client_keytab_parent, strerror(errno));
170172
(void)free(client_keytab_parent);

0 commit comments

Comments
 (0)