Skip to content

Commit 90e7e96

Browse files
committed
fix(sandbox): resolve Landlock handle_access ownership move
handle_access() takes self by value, consuming the Ruleset. In the previous code, the match arms meant that on Err the original ruleset was moved into the match and unavailable for create(). Fix by letting handle_access propagate via ? (BestEffort compat level ensures it succeeds on all kernel versions, silently degrading on ABI < v4). Replace tcp_handled bool with direct NetworkMode::Platform check since handle_access now always succeeds in Platform mode. Signed-off-by: Ladislav Smola <lsmola@redhat.com>
1 parent 140e171 commit 90e7e96

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

crates/openshell-sandbox/src/sandbox/linux/landlock.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,13 @@ pub fn prepare(policy: &SandboxPolicy, workdir: Option<&str>) -> Result<Option<P
185185
.into_diagnostic()?;
186186

187187
// Platform mode: declare intent to handle TCP connect access.
188-
// Caught independently -- filesystem sandboxing continues even if
189-
// TCP port restriction is unavailable (ABI < v4).
190-
let mut tcp_handled = false;
188+
// The BestEffort compat level silently ignores this on kernels
189+
// without ABI v4, so handle_access succeeds but the restriction
190+
// has no effect. The add_rule fallback below detects this.
191191
if matches!(policy.network.mode, NetworkMode::Platform) {
192-
match ruleset.handle_access(AccessNet::ConnectTcp) {
193-
Ok(r) => {
194-
ruleset = r;
195-
tcp_handled = true;
196-
}
197-
Err(e) => {
198-
tracing::warn!(
199-
error = %e,
200-
"Landlock handle_access(ConnectTcp) failed (ABI v4 required). \
201-
TCP port restriction will not be applied."
202-
);
203-
}
204-
}
192+
ruleset = ruleset
193+
.handle_access(AccessNet::ConnectTcp)
194+
.into_diagnostic()?;
205195
}
206196

207197
let mut ruleset = ruleset.create().into_diagnostic()?;
@@ -227,7 +217,7 @@ pub fn prepare(policy: &SandboxPolicy, workdir: Option<&str>) -> Result<Option<P
227217
}
228218
}
229219

230-
if tcp_handled {
220+
if matches!(policy.network.mode, NetworkMode::Platform) {
231221
let proxy_port = policy
232222
.network
233223
.proxy

0 commit comments

Comments
 (0)