Compare commits
8 Commits
13f852bd20
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f7720356f3 | |||
| dd6fb23a9e | |||
| f243b7b95c | |||
| 7e45cd719e | |||
| 5757ed1140 | |||
| bfb77a8368 | |||
| 081cac7074 | |||
| 32d799a5e8 |
15
default.nix
15
default.nix
@@ -1,14 +1,7 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, agent
|
||||
}:
|
||||
with pkgs;
|
||||
let
|
||||
agent_src = fetchgit {
|
||||
url = "https://gitea.rixxc.de/rixxc/x25519_agent.git";
|
||||
rev = "201f270624487ded538b63cc5416456bd5b8ba18";
|
||||
hash = "sha256-KPaKG+t3qSMy4Y7fd0PlBWZiZYcs7M1Clmn75emC9LU=";
|
||||
};
|
||||
|
||||
agent = callPackage "${agent_src}/default.nix" { };
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
name = "agent-harness";
|
||||
src = nix-gitignore.gitignoreSource [ ] ./.;
|
||||
@@ -17,5 +10,5 @@ rustPlatform.buildRustPackage {
|
||||
|
||||
buildInputs = [ agent ];
|
||||
|
||||
cargoSha256 = "sha256-ZgwQr1goz9yPws0P1eQwhHEv2WbcJeTCLEPYOUADOtE=";
|
||||
cargoHash = "sha256-ZgwQr1goz9yPws0P1eQwhHEv2WbcJeTCLEPYOUADOtE=";
|
||||
}
|
||||
|
||||
32
src/main.rs
32
src/main.rs
@@ -1,11 +1,13 @@
|
||||
use libc::{
|
||||
c_int, c_void, mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE,
|
||||
c_int, c_void, mlockall, mmap, prctl, MAP_FAILED, MAP_SHARED, MCL_FUTURE, PROT_READ,
|
||||
PROT_WRITE, PR_SET_DUMPABLE, PR_SET_SPECULATION_CTRL, PR_SPEC_FORCE_DISABLE,
|
||||
PR_SPEC_STORE_BYPASS,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::os::fd::AsRawFd;
|
||||
use std::{env, ptr};
|
||||
|
||||
const SHARED_MEMORY_SIZE: usize = 1024;
|
||||
const SHARED_MEMORY_SIZE: usize = 1024 * 1024;
|
||||
|
||||
#[link(name = "agent")]
|
||||
extern "C" {
|
||||
@@ -13,6 +15,22 @@ extern "C" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
assert!(
|
||||
prctl(
|
||||
PR_SET_SPECULATION_CTRL,
|
||||
PR_SPEC_STORE_BYPASS,
|
||||
PR_SPEC_FORCE_DISABLE,
|
||||
0,
|
||||
0,
|
||||
) >= 0,
|
||||
);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
assert!(prctl(PR_SET_DUMPABLE, 0) == 0);
|
||||
}
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
let shared_fd: c_int = args[0]
|
||||
@@ -54,7 +72,15 @@ fn main() {
|
||||
.expect("Cannot open KEY_FILE");
|
||||
|
||||
unsafe {
|
||||
agent_start(shared_memory, sync_memory, private_file.as_raw_fd().try_into().unwrap());
|
||||
assert!(mlockall(MCL_FUTURE) == 0);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
agent_start(
|
||||
shared_memory,
|
||||
sync_memory,
|
||||
private_file.as_raw_fd().try_into().unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
drop(private_file); // don't drop (and close) private file before here
|
||||
|
||||
Reference in New Issue
Block a user