-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of landlock calls
- Loading branch information
Showing
12 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "landlock_helpers.h" | ||
|
||
#if PTBOX_LANDLOCK | ||
#include <linux/landlock.h> | ||
|
||
int add_rules(const int ruleset_fd, const char* const* const paths, __u64 access_rule) { | ||
struct landlock_path_beneath_attr path_beneath = { | ||
.parent_fd = -1, | ||
.allowed_access = access_rule, | ||
}; | ||
|
||
for(const char* const* pathptr = paths; *pathptr; pathptr++) { | ||
path_beneath.parent_fd = open(*pathptr, O_PATH | O_CLOEXEC); | ||
if(path_beneath.parent_fd < 0) { | ||
perror("Failed to open path for rule"); | ||
return -1; | ||
} | ||
if(landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH, &path_beneath, 0)) { | ||
perror("Failed to add rule to ruleset"); | ||
return -1; | ||
} | ||
if(close(path_beneath.parent_fd)) { | ||
// Not Fatal: we have a CLOEXEC flag | ||
perror("Failed to close path for rule"); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
#ifndef landlock_create_ruleset | ||
int landlock_create_ruleset( | ||
const struct landlock_ruleset_attr *const attr, | ||
const size_t size, const __u32 flags) | ||
{ | ||
return syscall(__NR_landlock_create_ruleset, attr, size, flags); | ||
} | ||
#endif | ||
|
||
#ifndef landlock_add_rule | ||
int landlock_add_rule(const int ruleset_fd, | ||
const enum landlock_rule_type rule_type, | ||
const void *const rule_attr, const __u32 flags) | ||
{ | ||
return syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, | ||
rule_attr, flags); | ||
} | ||
#endif | ||
|
||
#ifndef landlock_restrict_self | ||
int landlock_restrict_self(const int ruleset_fd, | ||
const __u32 flags) | ||
{ | ||
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags); | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <linux/types.h> | ||
|
||
int add_rules(const int ruleset_fd, const char* const* const paths, __u64 access_rule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters