fix(worker): second security pass — content-only rejection codes (resource_limit, explicit list), negative proofs of the seccomp argument filters, PR_GET_DUMPABLE self-check, strict WebP chunk structure, iCCP-bomb fixture, separate test target cache; ci: release-images builder actually used (job-level DOCKER_CONFIG, --builder), literal cleanup path, token scoped to the login step, npm advisories gate, digests from build metadata

This commit is contained in:
bchanot committed 2026-10-13 00:36:30 +02:00
1 parent 11813f5560
commit a8b644a515
12 files changed
+278 -55

No files matched your search

+63 -5
View File
@@ -21,7 +21,11 @@ pub enum Reject {
UnsupportedType,
DecodeFailed,
Dimensions,
/// A decoder budget (`image::Limits`, allocation, complexity) exceeded by the content.
ResourceLimit,
/// libwebp failed on the buffer the child produced itself: an environment fault.
EncodeFailed,
/// A programming or I/O fault of the child, never a judgement on the content.
Internal,
}
@@ -31,6 +35,7 @@ impl Reject {
Self::UnsupportedType => exit_codes::UNSUPPORTED_TYPE,
Self::DecodeFailed => exit_codes::DECODE_FAILED,
Self::Dimensions => exit_codes::DIMENSIONS,
Self::ResourceLimit => exit_codes::RESOURCE_LIMIT,
Self::EncodeFailed => exit_codes::ENCODE_FAILED,
Self::Internal => exit_codes::INTERNAL,
}
@@ -120,15 +125,16 @@ pub fn process(bytes: &[u8]) -> Result<Vec<u8>, Reject> {
encode_webp(square.as_raw(), OUTPUT_SIDE, OUTPUT_SIDE, WEBP_QUALITY)
}
/// Every decode-time error is a judgement on the content (a content code): an uploader must
/// never be able to produce a "broken environment" outcome (security audit of R0).
fn map_image_error(error: ImageError) -> Reject {
match error {
ImageError::Limits(limit) => match limit.kind() {
LimitErrorKind::DimensionError => Reject::Dimensions,
_ => Reject::Internal,
_ => Reject::ResourceLimit,
},
ImageError::Unsupported(_) => Reject::UnsupportedType,
ImageError::Decoding(_) | ImageError::IoError(_) => Reject::DecodeFailed,
_ => Reject::Internal,
_ => Reject::DecodeFailed,
}
}
@@ -149,7 +155,7 @@ pub fn encode_webp(rgba: &[u8], width: u32, height: u32, quality: f32) -> Result
return Err(Reject::Internal);
};
let mut output: *mut u8 = std::ptr::null_mut();
// SAFETY: `rgba` holds exactly width × height × 4 bytes (checked above) with the matching
// SAFETY [gated 2026-10-13]: `rgba` holds exactly width × height × 4 bytes (checked above) with the matching
// stride; libwebp allocates the encoded buffer, writes its address into `output` and
// returns its size. The buffer is copied once and released with the matching WebPFree.
let size =
@@ -167,7 +173,7 @@ pub fn encode_webp(rgba: &[u8], width: u32, height: u32, quality: f32) -> Result
/// Version of the libwebp linked into this binary, as (major, minor, revision).
#[allow(unsafe_code)]
pub fn libwebp_version() -> (u8, u8, u8) {
// SAFETY: a pure getter of the FFI without arguments or side effects.
// SAFETY [gated 2026-10-13]: a pure getter of the FFI without arguments or side effects.
let packed = unsafe { libwebp_sys::WebPGetEncoderVersion() };
let packed = u32::try_from(packed).unwrap_or(0);
(
@@ -196,6 +202,10 @@ enum HookAction {
AllocGib(usize),
/// Burns CPU forever: `RLIMIT_CPU` (SIGXCPU) or the parent's deadline must stop it.
Spin,
/// Sends SIGTERM to the parent through `tkill`: the argument filter must kill the child.
SignalParent,
/// Maps executable memory: the `mmap` argument filter must kill the child.
MmapExec,
}
impl TestHooks {
@@ -216,6 +226,8 @@ impl TestHooks {
"--violate" => hooks.action = Some(HookAction::Violate),
"--flood" => hooks.action = Some(HookAction::Flood),
"--spin" => hooks.action = Some(HookAction::Spin),
"--signal-parent" => hooks.action = Some(HookAction::SignalParent),
"--mmap-exec" => hooks.action = Some(HookAction::MmapExec),
"--alloc-gib" => {
let value = iter
.next()
@@ -272,6 +284,22 @@ impl TestHooks {
HookAction::Spin => loop {
std::hint::black_box(0u8);
},
HookAction::SignalParent => {
let survived = negative_hooks::signal_parent();
let _ = writeln!(
stderr,
"decode: tkill(parent) survived the filter: {survived}"
);
Some(exit_codes::INTERNAL)
}
HookAction::MmapExec => {
let survived = negative_hooks::mmap_exec();
let _ = writeln!(
stderr,
"decode: mmap(PROT_EXEC) survived the filter: {survived}"
);
Some(exit_codes::INTERNAL)
}
}
}
@@ -281,6 +309,36 @@ impl TestHooks {
}
}
/// Negative proofs of the seccomp argument filters (`test-hooks` only): each call must die
/// with SIGSYS before returning; a return value means the filter let it through.
#[cfg(feature = "test-hooks")]
#[allow(unsafe_code)]
mod negative_hooks {
/// `tkill(getppid(), SIGTERM)`: a signal to another process.
pub fn signal_parent() -> i32 {
// SAFETY [gated 2026-10-13]: integer arguments only; the syscall is expected to be
// refused by the filter (KillProcess) and never to reach the parent.
unsafe { libc::syscall(libc::SYS_tkill, libc::getppid(), libc::SIGTERM) as i32 }
}
/// `mmap` of one executable page.
pub fn mmap_exec() -> i32 {
// SAFETY [gated 2026-10-13]: an anonymous private mapping with no file and a null
// hint; the filter is expected to kill the process before it exists.
let page = unsafe {
libc::mmap(
std::ptr::null_mut(),
4096,
libc::PROT_READ | libc::PROT_EXEC,
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
-1,
0,
)
};
i32::from(page != libc::MAP_FAILED)
}
}
/// Reads at most `cap` bytes from a reader, reporting whether more were available.
pub fn read_capped(reader: &mut dyn Read, cap: usize) -> io::Result<(Vec<u8>, bool)> {
let mut buffer = Vec::new();