-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Landlock functions are added to the code of Firejail, removing the de…
…pendency on tinyLL
- Loading branch information
1 parent
61b1544
commit ba828be
Showing
9 changed files
with
161 additions
and
35 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <sys/syscall.h> | ||
#include <sys/types.h> | ||
#include <linux/landlock.h> | ||
|
||
int landlock_create_ruleset(struct landlock_ruleset_attr *rsattr,size_t size,__u32 flags) { | ||
return syscall(__NR_landlock_create_ruleset,rsattr,size,flags); | ||
} | ||
|
||
int landlock_add_rule(int fd,enum landlock_rule_type t,void *attr,__u32 flags) { | ||
return syscall(__NR_landlock_add_rule,fd,t,attr,flags); | ||
} | ||
|
||
int landlock_restrict_self(int fd,__u32 flags) { | ||
int result = syscall(__NR_landlock_restrict_self,fd,flags); | ||
if (result!=0) return result; | ||
else { | ||
close(fd); | ||
return 0; | ||
} | ||
} | ||
|
||
int create_full_ruleset() { | ||
struct landlock_ruleset_attr attr; | ||
attr.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM | LANDLOCK_ACCESS_FS_EXECUTE; | ||
return landlock_create_ruleset(&attr,sizeof(attr),0); | ||
} | ||
|
||
int add_read_access_rule_by_path(int rset_fd,char *allowed_path) { | ||
int result; | ||
int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
struct landlock_path_beneath_attr target; | ||
target.parent_fd = allowed_fd; | ||
target.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR; | ||
result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
close(allowed_fd); | ||
return result; | ||
} | ||
|
||
int add_write_access_rule_by_path(int rset_fd,char *allowed_path,int restricted) { | ||
int result; | ||
int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
struct landlock_path_beneath_attr target; | ||
target.parent_fd = allowed_fd; | ||
if (restricted==0) target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
else if (restricted==1) target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
else { | ||
close(allowed_fd); | ||
return -1; | ||
} | ||
result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
close(allowed_fd); | ||
return result; | ||
} | ||
|
||
int add_execute_rule_by_path(int rset_fd,char *allowed_path) { | ||
int result; | ||
int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
struct landlock_path_beneath_attr target; | ||
target.parent_fd = allowed_fd; | ||
target.allowed_access = LANDLOCK_ACCESS_FS_EXECUTE; | ||
result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
close(allowed_fd); | ||
return result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <sys/syscall.h> | ||
#include <sys/types.h> | ||
#include <linux/landlock.h> | ||
|
||
int landlock_create_ruleset(struct landlock_ruleset_attr *rsattr,size_t size,__u32 flags) { | ||
return syscall(__NR_landlock_create_ruleset,rsattr,size,flags); | ||
} | ||
|
||
int landlock_add_rule(int fd,enum landlock_rule_type t,void *attr,__u32 flags) { | ||
return syscall(__NR_landlock_add_rule,fd,t,attr,flags); | ||
} | ||
|
||
int landlock_restrict_self(int fd,__u32 flags) { | ||
int result = syscall(__NR_landlock_restrict_self,fd,flags); | ||
if (result!=0) return result; | ||
else { | ||
close(fd); | ||
return 0; | ||
} | ||
} | ||
|
||
int create_full_ruleset() { | ||
struct landlock_ruleset_attr attr; | ||
attr.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM | LANDLOCK_ACCESS_FS_EXECUTE; | ||
return landlock_create_ruleset(&attr,sizeof(attr),0); | ||
} | ||
|
||
int add_read_access_rule_by_path(int rset_fd,char *allowed_path) { | ||
int result; | ||
int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
struct landlock_path_beneath_attr target; | ||
target.parent_fd = allowed_fd; | ||
target.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR; | ||
result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
close(allowed_fd); | ||
return result; | ||
} | ||
|
||
int add_write_access_rule_by_path(int rset_fd,char *allowed_path,int restricted) { | ||
int result; | ||
int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
struct landlock_path_beneath_attr target; | ||
target.parent_fd = allowed_fd; | ||
if (restricted==0) target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
else if (restricted==1) target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
else { | ||
close(allowed_fd); | ||
return -1; | ||
} | ||
result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
close(allowed_fd); | ||
return result; | ||
} | ||
|
||
int add_execute_rule_by_path(int rset_fd,char *allowed_path) { | ||
int result; | ||
int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
struct landlock_path_beneath_attr target; | ||
target.parent_fd = allowed_fd; | ||
target.allowed_access = LANDLOCK_ACCESS_FS_EXECUTE; | ||
result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
close(allowed_fd); | ||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.