Project

General

Profile

Actions

Security #9192

closed
JI JI

nfs: evasion if client inserts more than 512 xid entries before continuation

Security #9192: nfs: evasion if client inserts more than 512 xid entries before continuation

Added by Jason Ish about 2 months ago. Updated 7 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Label:
CVE:
Git IDs:

0c35778488545f38c998c3f302946163371819d0

Severity:
LOW
Disclosure Date:
01/07/2027

Description

Summary

A multi-segment NFSv3 READ keeps the file handle only in the default 512-entry requestmap, keyed by xid. If the client inserts more than 512 new xids before the continuation arrives, the original xid is evicted. filetracker_update on the to-client side then misses, returns 0, and does not consume the outstanding chunk. Those bytes are parsed as a new RPC header. A header that fails parsing returns a fatal error, and Suricata disables app-layer inspection for the rest of that TCP flow. Later NFS file data and a LOOKUP that match on a control flow produce no NFS alert after the eviction. Unpack the attachment and run ./verify.sh.

Affected Versions

Tested image jasonish/suricata:latest, Suricata 8.0.7 RELEASE. NFS over TCP is enabled by default on port 2049. app-layer.protocols.nfs.max-requests was left unset, so the compiled default of 512 is the map size that was hit.

Preconditions

The sensor must observe the TCP connection. The peer speaks ordinary NFSv3 on port 2049. The READ reply has to be parsed once while it is still short of the record length, so tc_chunk_left is armed, and more than 512 distinct xids must be inserted before that continuation is parsed. No account on the sensor is required. The reproduction does not lower max-requests.

Security Impact

On the attacked flow the NFS parser records one parser error, truncates the in-progress file at the 152 bytes already accepted, and does not inspect the later LOOKUP or the 20-byte READ whose data is NFSMAP_FILE_MARKER. The control flow uses the same continuation without evicting the xid, closes a 512-byte file, and alerts on both file.data and nfs_procedure. A TCP content rule and a capture on the bridge show the marker and the LOOKUP name on the attack flow as well, and the Suricata process kept running. Other flows were not tested. Raw TCP content matching can still see those bytes later, so the bypass shown here is of NFS parsing and file inspection. No code execution on the sensor was attempted.

Vulnerable Code

rust/src/nfs/nfs.rs sizes the map from the default and, on a to-client chunk, looks the file handle up only in that map:

pub static mut NFS_CFG_MAX_REQ: usize = 512;
// ...
requestmap: LruCache::new(NonZeroUsize::new(unsafe { NFS_CFG_MAX_REQ }).unwrap()),

When the continuation finishes the chunk, a missing xid returns without consuming input. The partial-chunk get does the same:

match self.requestmap.pop(&xid) {
None => {
return 0;
}
Some(xidmap) => {
file_handle = xidmap.file_handle.to_vec();
}
}

parse_tcp_data_tc only advances the cursor when filetracker_update returns a positive count. The unread continuation is then parsed as a record header, and a hard header failure is fatal:

Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
return AppLayerResult::err();
}

AppLayerParserParse turns that error into StreamTcpDisableAppLayer, so later records on the flow are not parsed. The to-server write path keeps ts_chunk_fh on the state. The to-client read path does not keep an equivalent handle next to tc_chunk_xid.

Call Chain

process_request_record_v3 (rust/src/nfs/nfs3.rs:200) stores the READ file handle with requestmap.put.

A short first segment of a large READ reply goes through parse_tcp_partial_data_tc (rust/src/nfs/nfs.rs:2404) into process_read_record, which sets tc_chunk_xid and tc_chunk_left (rust/src/nfs/nfs.rs:2053) and leaves the xid in the map.

Further requests call requestmap.put until LruCache evicts the chunk xid (rust/src/nfs/nfs.rs:104, rust/src/nfs/nfs.rs:554).

The continuation enters parse_tcp_data_tc (rust/src/nfs/nfs.rs:2584), filetracker_update misses and returns 0 (rust/src/nfs/nfs.rs:1621), parse_rpc_packet_header fails, and the parser returns AppLayerResult::err (rust/src/nfs/nfs.rs:2687).

AppLayerParserParse then calls StreamTcpDisableAppLayer (src/app-layer-parser.c:1728).

Payload

One NFSv3 READ (xid 0x10000001) whose reply record is 560 bytes. The first send is 200 bytes, which is enough for the large-record path (rec_size >= 512 and at least 128 bytes buffered) and leaves tc_chunk_left at 360. Before that continuation, the attack sends 520 NULL calls with distinct xids, above the default capacity of 512. The 360-byte continuation starts with fragment length 16, which parse_rpc_packet_header rejects. After it, the client sends a LOOKUP named NFSMAP_LOOKUP_NAME and a second READ whose file data is NFSMAP_FILE_MARKER. The control flow sends the same READ, continuation, LOOKUP, and marker READ, and does not insert the 520 xids.

Reproduction

Image jasonish/suricata:latest (Suricata 8.0.7 RELEASE). Bridge br-nfsmap, subnet 172.31.9.0/24, NFS peer 172.31.9.10:2049. The peer is a short script in the official python:3.11-slim image, because the Suricata image does not ship a Python client. Suricata is the component under test. It listens on that bridge with -k none because bridge offload leaves checksums empty. max-requests is not set.

./verify.sh
-- control.json --
evict_xids=0
file_data_alerts=1
nfs_lookup_alerts=1
tcp_file_alerts=1
nic_file_marker_packets=1
suricata_running=True
-- attack.json --
evict_xids=520
file_data_alerts=0
nfs_lookup_alerts=0
tcp_file_alerts=1
nic_file_marker_packets=1
nic_lookup_packets=1
suricata_running=True
VERDICT: PASS

Stats from the same run showed app_layer.error.nfs_tcp.parser equal to 1. The control READ file closed at 512 bytes. The attack READ file was truncated at 152 bytes, and no LOOKUP transaction was logged on that flow.

Fix Recommendation

When a to-client READ chunk is armed, store the file handle on NFSState next to tc_chunk_xid, as ts_chunk_fh already does for writes, and do not let requestmap eviction drop an xid that still has tc_chunk_left > 0. If the handle is nevertheless missing, consume or skip tc_chunk_left plus tc_chunk_tail, clear the chunk xid, and resume on the next RPC boundary. filetracker_update must not return 0 while a chunk is outstanding, and those bytes must not be passed to parse_rpc_packet_header.


Files


Subtasks 1 (0 open — 1 closed)

Security #9193: nfs: evasion if client inserts more than 512 xid entries before continuation (8.0.x backport)ClosedOISF DevActions
Actions

Also available in: PDF Atom