Skip to content

Commit

Permalink
uapi: Use libc for syscall constants
Browse files Browse the repository at this point in the history
This patch switches from internally defined system call constants for
the landlock system calls to the ones defined by `libc`.

Besides removing unnecessary code already provided by the latest libc,
this also adds support for additional architectures like ARM since the
existing constants were limited to x86_64.

Signed-off-by: Christian Duerr <chris.durr@phylum.io>
  • Loading branch information
cd-work committed Oct 6, 2022
1 parent 5a22c74 commit 0133aa5
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 12 deletions.
141 changes: 141 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -16,7 +16,7 @@ readme = "README.md"

[dependencies]
enumflags2 = "0.7"
libc = "0.2"
libc = "0.2.133"
thiserror = "1.0"

[dev-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions src/uapi/mod.rs
Expand Up @@ -27,27 +27,23 @@ pub use self::landlock::{
LANDLOCK_CREATE_RULESET_VERSION,
};

use libc::{__u32, c_int, c_void, size_t, syscall};

#[cfg(target_arch = "x86_64")]
const __NR_LANDLOCK_CREATE_RULESET: u32 = 444;
#[cfg(target_arch = "x86_64")]
const __NR_LANDLOCK_ADD_RULE: u32 = 445;
#[cfg(target_arch = "x86_64")]
const __NR_LANDLOCK_RESTRICT_SELF: u32 = 446;
use libc::{
__u32, c_int, c_void, size_t, syscall, SYS_landlock_add_rule, SYS_landlock_create_ruleset,
SYS_landlock_restrict_self,
};

#[rustfmt::skip]
pub unsafe fn landlock_create_ruleset(attr: *const landlock_ruleset_attr, size: size_t,
flags: __u32) -> c_int {
syscall(__NR_LANDLOCK_CREATE_RULESET as i64, attr, size, flags) as c_int
syscall(SYS_landlock_create_ruleset, attr, size, flags) as c_int
}

#[rustfmt::skip]
pub unsafe fn landlock_add_rule(ruleset_fd: c_int, rule_type: landlock_rule_type,
rule_attr: *const c_void, flags: __u32) -> c_int {
syscall(__NR_LANDLOCK_ADD_RULE as i64, ruleset_fd, rule_type, rule_attr, flags) as c_int
syscall(SYS_landlock_add_rule, ruleset_fd, rule_type, rule_attr, flags) as c_int
}

pub unsafe fn landlock_restrict_self(ruleset_fd: c_int, flags: __u32) -> c_int {
syscall(__NR_LANDLOCK_RESTRICT_SELF as i64, ruleset_fd, flags) as c_int
syscall(SYS_landlock_restrict_self, ruleset_fd, flags) as c_int
}

0 comments on commit 0133aa5

Please sign in to comment.