dlm: fix RCOM_LOOKUP length underflow
Subsystems (2)
PATCH 1/1 dlm: fix RCOM_LOOKUP length underflow
From: Aohan Mei <[email protected]>
receive_rcom_lookup() derives the resource name length from the peer-supplied 16-bit h_length header field:
int len = le16_to_cpu(rc_in->rc_header.h_length) -
sizeof(struct dlm_rcom);The 3.1 receive path only bounds h_length to the range [sizeof(struct dlm_header), DLM_MAX_SOCKET_BUFSIZE] in dlm_validate_incoming_buffer(), and the RCOM case in dlm_midcomms_receive_buffer_3_1() performs no further length check despite its "length already checked" comment. A peer can therefore send an RCOM_LOOKUP message whose h_length is smaller than sizeof(struct dlm_rcom) (48). The subtraction is evaluated in size_t arithmetic and wraps, and the result is assigned to an int as a negative value.
Both consumers of that length only guard the upper bound (len > DLM_RESNAME_MAXLEN), which a negative len passes as a signed comparison:
- with rc_id == 0xffffffff, len reaches dlm_dump_rsb_name() -> dlm_search_rsb_tree(), where memcpy() converts it to a huge size_t and overflows the on-stack 64-byte key buffer;
- otherwise len reaches dlm_master_lookup() -> _dlm_master_lookup(), where jhash() converts it to a huge u32 and reads out of bounds.
Drop the message when the computed name length falls outside [0, DLM_RESNAME_MAXLEN], which is exactly the range valid lookups use.
--- fs/dlm/rcom.c | 3 +++ 1 file changed, 3 insertions(+)
fs/dlm/rcom.c +3 -0
@@ -385,6 +385,9 @@ static void receive_rcom_lookup(struct dlm_ls *ls,int len =le16_to_cpu (rc_in->rc_header.h_length) -sizeof (struct dlm_rcom ); +if (len <0 || len >DLM_RESNAME_MAXLEN ) +return ; +/* Old code would send this special id to trigger a debug dump. */ if (rc_in->rc_id ==cpu_to_le64 (0xFFFFFFFF )) {log_error (ls,"receive_rcom_lookup dump from %d" , nodeid);
Signature · 1 line
2.43.7