Skip to content

Commit 69fb5d9

Browse files
committed
libceph: prevent potential out-of-bounds reads in process_message_header()
If the message frame is (maliciously) corrupted in a way that the length of the control segment ends up being less than the size of the message header or a different frame is made to look like a message frame, out-of-bounds reads may ensue in process_message_header(). Perform an explicit bounds check before decoding the message header. Cc: [email protected] Reported-by: Raphael Zimmer <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]> Reviewed-by: Alex Markuze <[email protected]> Reviewed-by: Viacheslav Dubeyko <[email protected]>
1 parent 081a0b7 commit 69fb5d9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

net/ceph/messenger_v2.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,12 +2833,15 @@ static int process_message_header(struct ceph_connection *con,
28332833
void *p, void *end)
28342834
{
28352835
struct ceph_frame_desc *desc = &con->v2.in_desc;
2836-
struct ceph_msg_header2 *hdr2 = p;
2836+
struct ceph_msg_header2 *hdr2;
28372837
struct ceph_msg_header hdr;
28382838
int skip;
28392839
int ret;
28402840
u64 seq;
28412841

2842+
ceph_decode_need(&p, end, sizeof(*hdr2), bad);
2843+
hdr2 = p;
2844+
28422845
/* verify seq# */
28432846
seq = le64_to_cpu(hdr2->seq);
28442847
if ((s64)seq - (s64)con->in_seq < 1) {
@@ -2869,6 +2872,10 @@ static int process_message_header(struct ceph_connection *con,
28692872
WARN_ON(!con->in_msg);
28702873
WARN_ON(con->in_msg->con != con);
28712874
return 1;
2875+
2876+
bad:
2877+
pr_err("failed to decode message header\n");
2878+
return -EINVAL;
28722879
}
28732880

28742881
static int process_message(struct ceph_connection *con)

0 commit comments

Comments
 (0)