Skip to content

Commit 8557bf2

Browse files
committed
src: Handle Landlock ABI v5
Add the AccessFs::IoctlDev right. Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 949ad38 commit 8557bf2

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

examples/sandboxer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn main() -> anyhow::Result<()> {
111111
anyhow!("Missing command")
112112
})?;
113113

114-
let abi = ABI::V4;
114+
let abi = ABI::V5;
115115
let mut ruleset = Ruleset::default().handle_access(AccessFs::from_all(abi))?;
116116
let ruleset_ref = &mut ruleset;
117117

src/compat.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub enum ABI {
6161
/// Fourth Landlock ABI, introduced with
6262
/// [Linux 6.7](https://git.kernel.org/stable/c/136cc1e1f5be75f57f1e0404b94ee1c8792cb07d).
6363
V4 = 4,
64+
/// Fifth Landlock ABI, introduced with
65+
/// [Linux 6.10](https://git.kernel.org/stable/c/2fc0e7892c10734c1b7c613ef04836d57d4676d5).
66+
V5 = 5,
6467
}
6568

6669
impl ABI {
@@ -87,8 +90,9 @@ impl ABI {
8790
1 => ABI::V1,
8891
2 => ABI::V2,
8992
3 => ABI::V3,
93+
4 => ABI::V4,
9094
// Returns the greatest known ABI.
91-
_ => ABI::V4,
95+
_ => ABI::V5,
9296
}
9397
}
9498

@@ -385,7 +389,7 @@ pub trait Compatible: Sized + private::OptionCompatLevelMut {
385389
/// // However, this ruleset may also handle other (future) access rights
386390
/// // if they are supported by the running kernel.
387391
/// .set_compatibility(CompatLevel::BestEffort)
388-
/// .handle_access(AccessFs::from_all(ABI::V4))?
392+
/// .handle_access(AccessFs::from_all(ABI::V5))?
389393
/// .create()?)
390394
/// }
391395
/// ```
@@ -414,7 +418,7 @@ pub trait Compatible: Sized + private::OptionCompatLevelMut {
414418
/// // if they are supported by the running kernel,
415419
/// // but without returning any error otherwise.
416420
/// .set_compatibility(CompatLevel::BestEffort)
417-
/// .handle_access(AccessFs::from_all(ABI::V2))?
421+
/// .handle_access(AccessFs::from_all(ABI::V5))?
418422
/// .create()?)
419423
/// }
420424
/// ```

src/fs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub enum AccessFs {
8484
Refer = uapi::LANDLOCK_ACCESS_FS_REFER as u64,
8585
/// Truncate a file with `truncate(2)`, `ftruncate(2)`, `creat(2)`, or `open(2)` with `O_TRUNC`.
8686
Truncate = uapi::LANDLOCK_ACCESS_FS_TRUNCATE as u64,
87+
/// Send IOCL commands to a device file.
88+
IoctlDev = uapi::LANDLOCK_ACCESS_FS_IOCTL_DEV as u64,
8789
}
8890

8991
impl Access for AccessFs {
@@ -104,7 +106,7 @@ impl AccessFs {
104106
pub fn from_read(abi: ABI) -> BitFlags<Self> {
105107
match abi {
106108
ABI::Unsupported => BitFlags::EMPTY,
107-
ABI::V1 | ABI::V2 | ABI::V3 | ABI::V4 => make_bitflags!(AccessFs::{
109+
ABI::V1 | ABI::V2 | ABI::V3 | ABI::V4 | ABI::V5 => make_bitflags!(AccessFs::{
108110
Execute
109111
| ReadFile
110112
| ReadDir
@@ -132,6 +134,7 @@ impl AccessFs {
132134
}),
133135
ABI::V2 => Self::from_write(ABI::V1) | AccessFs::Refer,
134136
ABI::V3 | ABI::V4 => Self::from_write(ABI::V2) | AccessFs::Truncate,
137+
ABI::V5 => Self::from_write(ABI::V4) | AccessFs::IoctlDev,
135138
}
136139
}
137140

@@ -185,7 +188,7 @@ impl PrivateAccess for AccessFs {
185188
// TODO: Make ACCESS_FILE a property of AccessFs.
186189
// TODO: Add tests for ACCESS_FILE.
187190
const ACCESS_FILE: BitFlags<AccessFs> = make_bitflags!(AccessFs::{
188-
ReadFile | WriteFile | Execute | Truncate
191+
ReadFile | WriteFile | Execute | Truncate | IoctlDev
189192
});
190193

191194
// XXX: What should we do when a stat call failed?

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,21 @@ mod tests {
385385
false,
386386
);
387387
}
388+
389+
#[test]
390+
fn abi_v5_ioctl_dev() {
391+
check_ruleset_support(
392+
ABI::V4,
393+
Some(ABI::V5),
394+
move |ruleset: Ruleset| -> _ {
395+
Ok(ruleset
396+
.handle_access(AccessNet::BindTcp)?
397+
.handle_access(AccessFs::IoctlDev)?
398+
.create()?
399+
.add_rule(PathBeneath::new(PathFd::new("/")?, AccessFs::IoctlDev))?
400+
.restrict_self()?)
401+
},
402+
false,
403+
);
404+
}
388405
}

src/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Access for AccessNet {
5555
fn from_all(abi: ABI) -> BitFlags<Self> {
5656
match abi {
5757
ABI::Unsupported | ABI::V1 | ABI::V2 | ABI::V3 => BitFlags::EMPTY,
58-
ABI::V4 => AccessNet::BindTcp | AccessNet::ConnectTcp,
58+
ABI::V4 | ABI::V5 => AccessNet::BindTcp | AccessNet::ConnectTcp,
5959
}
6060
}
6161
}

src/uapi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use self::landlock::{
2727
LANDLOCK_ACCESS_FS_MAKE_SYM,
2828
LANDLOCK_ACCESS_FS_REFER,
2929
LANDLOCK_ACCESS_FS_TRUNCATE,
30+
LANDLOCK_ACCESS_FS_IOCTL_DEV,
3031
LANDLOCK_ACCESS_NET_BIND_TCP,
3132
LANDLOCK_ACCESS_NET_CONNECT_TCP,
3233
LANDLOCK_CREATE_RULESET_VERSION,

0 commit comments

Comments
 (0)