Security #9190
closednfs: partial NFSv3 record checks fatally disable app-layer inspection
9915449327d70fadd5b087ddbe8d6103c5f5f28c
Description
Summary¶
On default NFS over TCP, a partial record whose fragment length is already known still returns AppLayerResult::err() when a later content check fails. That status permanently disables app-layer parsing for the flow. The same failure on a complete record only records MalformedData and continues at the next record. A client can get the flow classified as NFS, send a WRITE split across TCP segments with stable set to 3 in the first segment, and then send a LOOKUP that should match nfs_procedure. The LOOKUP is not alerted. The same LOOKUP, without that partial error, is alerted, and the marker bytes are still captured on the bridge. The sensor process stays up. Unpack the attachment and run ./verify.sh to reproduce.
Affected Versions¶
Confirmed on jasonish/suricata:latest, Suricata 8.0.7 RELEASE, IDS mode, image defaults. NFS TCP inspection is enabled by default and is registered on port 2049. No nfs.enabled override was set.
Preconditions¶
The sensor must see the client TCP flow. The flow has to be classified as NFS before the bad record. The bad record must still be partial when the parser runs, with frag_len already decoded and the failing field present in that chunk. Default port 2049 and the default NFS parser are enough. No Suricata account and no configuration change are required.
Security Impact¶
After the fatal return, StreamTcpDisableAppLayer stops app-layer parsing for both directions of that flow. A following NFSv3 LOOKUP that matches nfs_procedure:3 produces no alert. The process does not exit. A TCP content rule on the same marker still fires, and a capture on the bridge contains the marker, so the miss is not a lost packet. A control flow that puts stable 3 inside one complete WRITE still alerts on the same LOOKUP and does not increment app_layer.error.nfs_tcp.parser. This run does not access files on a real NFS server. The partial reply path below is the same fatal return and was not given its own packet in this run.
Vulnerable Code¶
parse_nfs3_request_write rejects stable above 2. On a partial WRITE that is already long enough to see that field, the TCP parser turns the failure into a fatal error:
match parse_nfs3_request_write(hdr.prog_data, false) {
Ok((_, ref w)) => {
self.process_partial_write_request_record(flow, hdr, w);
return AppLayerResult::ok();
}
Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
return AppLayerResult::err();
}
frag_len was taken from parse_rpc_request_partial before this function runs, so the next record boundary is known. The complete-record loop only sets MalformedData and then skips rec_size bytes.
A partial reply does the same thing when parse_rpc_reply fails after the fragment header has already parsed:
Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
return AppLayerResult::err();
}
AppLayerResult::err() is defined as a status of -1, and the comment states that the parser will not be called again. AppLayerParserParse treats status < 0 as fatal and calls StreamTcpDisableAppLayer.
Call Chain¶
nfs_parse_request (rust/src/nfs/nfs.rs:2812) -> parse_tcp_data_ts (rust/src/nfs/nfs.rs:2268) -> parse_rpc_request_partial (rust/src/nfs/nfs.rs:2331) -> parse_tcp_partial_data_ts (rust/src/nfs/nfs.rs:2153) -> parse_nfs3_request_write (rust/src/nfs/nfs3_records.rs:364) -> AppLayerResult::err() (rust/src/nfs/nfs.rs:2186) -> AppLayerParserParse (src/app-layer-parser.c:1626) -> StreamTcpDisableAppLayer (src/stream-tcp-reassemble.c:444).
Partial replies follow parse_tcp_data_tc (rust/src/nfs/nfs.rs:2571) -> parse_tcp_partial_data_tc (rust/src/nfs/nfs.rs:2404) -> parse_rpc_reply failure -> AppLayerResult::err() (rust/src/nfs/nfs.rs:2441) -> the same disable.
Payload¶
A 44-byte NFSv3 NULL (RPC version 2, program 100003, procedure 0, AUTH_NULL) classifies the flow.
The attack WRITE is procedure 7. The fragment header claims length 800, so the record size is 804. The first TCP segment is 72 bytes and ends with stable = 3. After app_layer.error.nfs_tcp.parser increments, the remaining 732 bytes of that record are sent together with a complete LOOKUP. The LOOKUP is procedure 3 and the filename is NFSERRMARK.
The control WRITE is one 80-byte record. It also carries stable = 3, and its fragment length matches the body, so the parser takes the complete-record path. The following LOOKUP is the same bytes as the attack LOOKUP.
Reproduction¶
Image jasonish/suricata:latest. Bridge br-nfserr, network suri-nfserr, subnet 172.31.6.0/24. The sink is nfserr-app at 172.31.6.10:2049, a python:3.11-slim container that only reads TCP. It is not the product under test. The sensor container nfserr-suri uses host networking and sniffs br-nfserr. The host connects directly to 172.31.6.10:2049. -k none is set because the bridge offloads checksums. NFS parser settings are the image defaults. Bridge sniffing is required so the sensor sees the client segments.
control_nfs_alerts=1
attack_nfs_alerts=0
control_tcp_alerts=1
attack_tcp_alerts=1
pcap_marker_attack=1
pcap_marker_control=1
attack_fatal_before_followup=true
control_fatal_before_followup=false
parser_errors=1
sensor_running=true
VERDICT: PASS
Fix Recommendation¶
Once frag_len is known, a content-check failure must not return AppLayerResult::err(). Record MalformedData, skip the unread tail of that record, and return ok, as the complete-record loops in parse_tcp_data_ts and parse_tcp_data_tc already do. Apply that to the partial WRITE failure in parse_tcp_partial_data_ts, including parse_nfs3_request_write rejecting stable greater than 2, and to the partial reply failure in parse_tcp_partial_data_tc when parse_rpc_reply returns Error or Failure. Keep the fatal return for the case where the RPC header itself does not yield a length. The other partial paths that return err() only after the fragment header has parsed, such as a large READ reply that fails its content check, should skip the same way.
Files
JI Updated by Jason Ish about 2 months ago
- Related to Security #9188: nfsv3/tcp: partial WRITE with count 0 desynchronizes the parser added
JI Updated by Jason Ish about 2 months ago
- Status changed from New to Triaged
- Severity set to LOW
- Label Needs backport to 8.0 added
Recommending low fits our pattern of visibility issues. The supplied reproducer appears to use a TCP sink as well, rather than an NFS server, so not sure if the loss of visibility is actually traffic that will be processed by the NFS server - which might make it more a bug.
OT Updated by OISF Ticketbot about 2 months ago
- Subtask #9191 added
OT Updated by OISF Ticketbot about 2 months ago
- Label deleted (
Needs backport to 8.0)
JI Updated by Jason Ish about 1 month ago
- Status changed from Triaged to In Review
MR1384
JI Updated by Jason Ish about 1 month ago
- Assignee changed from OISF Dev to Jason Ish
JI Updated by Jason Ish about 1 month ago
- GHSA set to GHSA-jq2x-9778-pg6c