F08: Later stream writes do not report a retained fatal TLS error
F08: Later stream writes do not report a retained fatal TLS error
- Finding: Suppressed fatal TLS error and false write success
- Affected Software: rustls-util development snapshot
99f2358cae29,StreamandStreamOwned. - Date: September 2026
- Discoverer: OpenAI ([email protected])
A write that accepts plaintext and then discovers a fatal incoming TLS error appropriately reports its accepted byte count. Later writes and flushes can continue succeeding instead of reporting that retained error, acknowledging additional bytes the peer cannot consume.
Cause and prior work
The post-acceptance complete_io result is discarded. Once its alert/output has drained, subsequent write preparation does not check the retained receive failure. The documented next-call error expectation in #1188 is therefore not met on this path. #3289 propagates provider encryption errors, not this already-recorded receive failure.
Source: rustls-util/src/stream.rs.
Reproduction
After a normal TLS 1.3 handshake, corrupt one incoming authentication tag. A valid nonblocking transport briefly blocks output, allowing the first write to encounter that record, then accepts output. Check two writes and a flush before reading; the explicit read exposes the retained error and the peer confirms receipt of the fatal alert.
Use the existing rustls/ checkout at 99f2358cae29 and a standalone sibling repro/ directory outside its Cargo workspace. Save the blocks below as repro/Cargo.toml and repro/src/main.rs; run the commands from the directory containing both rustls/ and repro/.
[package]
name = "post-error-write-check"
version = "0.1.0"
edition = "2024"
[workspace]
[dependencies]
rustls = { path = "../rustls/rustls" }
rustls-ring = { path = "../rustls/rustls-ring" }
rustls-util = { path = "../rustls/rustls-util", default-features = false }use rustls::crypto::Identity;
use rustls::pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject};
use rustls::{
ClientConfig, ClientConnection, Connection, RootCertStore, ServerConfig, ServerConnection,
VecInput,
};
use rustls_util::StreamOwned;
use std::{
io::{self, Read, Write},
sync::Arc,
};
fn pair() -> (ClientConnection, ServerConnection) {
let provider = Arc::new(rustls_ring::DEFAULT_PROVIDER.clone());
// Trust the fixture CA so later failures are unrelated to certificate rejection.
let mut roots = RootCertStore::empty();
roots
.add(CertificateDer::from(
include_bytes!("../../rustls/test-ca/ecdsa-p256/ca.der").as_slice(),
))
.unwrap();
let client_config = ClientConfig::builder(provider.clone())
.with_root_certificates(roots)
.with_no_client_auth()
.unwrap();
// Configure the peer with the matching fixture identity.
let certs = CertificateDer::pem_slice_iter(include_bytes!(
"../../rustls/test-ca/ecdsa-p256/end.fullchain"
))
.map(Result::unwrap)
.collect();
let key =
PrivateKeyDer::from_pem_slice(include_bytes!("../../rustls/test-ca/ecdsa-p256/end.key"))
.unwrap();
let mut server_config = ServerConfig::builder(provider)
.with_no_client_auth()
.with_single_cert(Arc::new(Identity::from_cert_chain(certs).unwrap()), key)
.unwrap();
server_config.send_tls13_tickets = rustls::server::Tls13Tickets { default: 0, max: 0 };
// Create both peers and keep handshake traffic separate from the scenario below.
let mut c_out = Vec::new();
let mut client = Arc::new(client_config)
.connect("localhost".try_into().unwrap())
.build(&mut c_out)
.unwrap();
let mut server = ServerConnection::new(Arc::new(server_config)).unwrap();
let mut c_in = VecInput::default();
let mut s_in = VecInput::default();
let mut s_out = Vec::new();
// Complete both handshake directions and drain their output before returning.
for _ in 0..10 {
transfer(&mut c_out, &mut s_in);
server
.read_tls(&mut s_in, &mut s_out)
.handle_all(&mut Vec::new())
.unwrap();
transfer(&mut s_out, &mut c_in);
client
.read_tls(&mut c_in, &mut c_out)
.handle_all(&mut Vec::new())
.unwrap();
if !client.is_handshaking()
&& !server.is_handshaking()
&& c_out.is_empty()
&& s_out.is_empty()
{
return (client, server);
}
}
panic!("handshake did not finish");
}
fn transfer(output: &mut Vec<u8>, input: &mut VecInput) {
let mut remaining = output.as_slice();
while !remaining.is_empty() {
let consumed = input.read(&mut remaining).unwrap();
assert!(consumed > 0);
}
output.clear();
}
#[derive(Debug)]
struct BackpressureThenWritable {
incoming: io::Cursor<Vec<u8>>,
outgoing: Vec<u8>,
writes: usize,
}
impl Read for BackpressureThenWritable {
fn read(&mut self, out: &mut [u8]) -> io::Result<usize> {
if self.incoming.position() as usize == self.incoming.get_ref().len() {
return Err(io::ErrorKind::WouldBlock.into());
}
self.incoming.read(out)
}
}
impl Write for BackpressureThenWritable {
fn write(&mut self, input: &[u8]) -> io::Result<usize> {
self.writes += 1;
if self.writes == 1 {
return Err(io::ErrorKind::WouldBlock.into());
}
self.outgoing.extend_from_slice(input);
Ok(input.len())
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
fn main() {
let (client, mut server) = pair();
// Corrupt one peer record after a valid handshake to produce a retained TLS failure.
let mut incoming = Vec::new();
server
.write(b"server data".as_slice().into(), &mut incoming)
.expect("encode peer data");
*incoming.last_mut().expect("record tag") ^= 1;
// Block the first transport write so stream I/O also processes the bad incoming record.
let sock = BackpressureThenWritable {
incoming: io::Cursor::new(incoming),
outgoing: Vec::new(),
writes: 0,
};
let mut stream = StreamOwned::new(client, sock, Vec::new());
// The first write accepts data before discovering the error; later calls should surface it.
let first = stream.write(b"before fatal error");
let second = stream.write(b"silently lost after fatal error");
let flush = stream.flush();
println!("first_write={first:?} second_write={second:?} flush={flush:?}");
assert_eq!(first.expect("first write acknowledged"), 18);
assert_eq!(
second.expect("second write acknowledged"),
b"silently lost after fatal error".len()
);
flush.expect("flush acknowledged");
assert!(stream.output.is_empty());
// Only now does an explicit read expose the already recorded fatal TLS error.
let subsequent_read = stream.read(&mut [0u8; 1]);
println!("subsequent_read={subsequent_read:?}");
assert_eq!(
subsequent_read
.expect_err("fatal error retained for reads")
.kind(),
io::ErrorKind::InvalidData
);
// Check the peer independently: it receives the first data and a fatal alert.
let mut peer_input = VecInput::default();
transfer(&mut stream.sock.outgoing, &mut peer_input);
let mut received = Vec::new();
let peer_result = server
.read_tls(&mut peer_input, &mut Vec::new())
.handle_all(&mut received);
println!(
"peer_result={peer_result:?} peer_plaintext={:?}",
String::from_utf8_lossy(&received)
);
assert!(peer_result.is_err());
assert_eq!(received, b"before fatal error");
}cargo +1.98.1 run --release --manifest-path repro/Cargo.tomlResult
first_write=Ok(18) second_write=Ok(31) flush=Ok(())
subsequent_read=Err(... InvalidData ... DecryptError ...)
peer_result=Err(AlertReceived(BadRecordMac))The peer receives only the first plaintext. It sees a fatal alert rather than clean EOF, so this is not an independent clean-truncation exploit. The partial-write schedule is lawful; no caller invariant is violated.
Suggested correction
Retain and surface a deferred fatal error on subsequent stream operations after accounting for any bytes already accepted. Apply the same behavior to ordinary and vectored writes and flush.
Disclaimer
This information is being shared by OpenAI solely for the purpose of improving security and reducing potential harm. This information is presented as-is. We make no representations or warranties, express or implied, as to the completeness, accuracy, or fitness for any particular purpose of the information. This includes, without limitation any suggestions or ideas presented on how to remedy or mitigate an identified vulnerability, including whether such suggestions or ideas would be effective and/or could have other negative impacts.
OpenAI disclaims any liability for direct or indirect damages arising from the reliance on, or use, misuse, or interpretation of this information. Any references to third-party systems, services, or entities are included solely for identification purposes and do not imply endorsement, responsibility, or attribution.
Source: rustls/rustls