Skip to contentSkip to conversation

libceph: admit message frames only in CEPH_CON_S_OPEN state

PATCH In review Ilya Dryomov 3 participants 5 messages Mar 8 – Mar 9 Ceph common code (libceph)

lore
Share & tools
lore

Ilya Dryomov

author maintainer
#0 lore raw

PATCH 1/1 libceph: admit message frames only in CEPH_CON_S_OPEN state

Similar checks are performed for all control frames, but an early check for message frames was missing. process_message() is already set up to terminate the loop in case the state changes while con->ops->dispatch() handler is being executed.

---
 net/ceph/messenger_v2.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ceph/messenger_v2.c +5 -0
index ed618435d33a..c4ddf7911f7d 100644
@@ -2905,6 +2905,11 @@ static int __handle_control(struct ceph_connection *con, void *p)
 	if (con->v2.in_desc.fd_tag != FRAME_TAG_MESSAGE)
 		return process_control(con, p, end);
 
+	if (con->state != CEPH_CON_S_OPEN) {
+		con->error_msg = "protocol error, unexpected message";
+		return -EINVAL;
+	}
+
 	ret = process_message_header(con, p, end);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Ilya Dryomov

Similar checks are performed for all control frames, but an early check for message frames was missing. process_message() is already set up to terminate the loop in case the state changes while con->ops->dispatch() handler is being executed.

---
 net/ceph/messenger_v2.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ceph/messenger_v2.c +5 -1
index ed618435d33a..c4ddf7911f7d 100644
@@ -2905,6 +2905,11 @@ static int __handle_control(struct ceph_connection *con, void *p)
        if (con->v2.in_desc.fd_tag != FRAME_TAG_MESSAGE)
                return process_control(con, p, end);
 
+       if (con->state != CEPH_CON_S_OPEN) {
+               con->error_msg = "protocol error, unexpected message";
+               return -EINVAL;
+       }
+
        ret = process_message_header(con, p, end);
        if (ret < 0)
                return ret;
--

2.53.0

#2 lore raw
In reply to Ilya Dryomov
Quoted 17 lines · Ilya Dryomov

Similar checks are performed for all control frames, but an early check for message frames was missing. process_message() is already set up to terminate the loop in case the state changes while con->ops->dispatch() handler is being executed.

---
 net/ceph/messenger_v2.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ceph/messenger_v2.c +0 -0
index ed618435d33a..c4ddf7911f7d 100644
@@ -2905,6 +2905,11 @@ static int __handle_control(struct ceph_connection *con, void *p)
 	if (con->v2.in_desc.fd_tag != FRAME_TAG_MESSAGE)

net/ceph/messenger_v2.c static int __handle_control(struct ceph_connection *con, void *p) · line 2915

Quoted 10 lines
net/ceph/messenger_v2.c +5 -0
 		return process_control(con, p, end);
 
+	if (con->state != CEPH_CON_S_OPEN) {
+		con->error_msg = "protocol error, unexpected message";
+		return -EINVAL;
+	}
+
 	ret = process_message_header(con, p, end);
 	if (ret < 0)
 		return ret;

I am slightly worried about this place [1]:

	if (con->state == CEPH_CON_S_V2_AUTH) {
		buf = alloc_conn_buf(con, ctrl_len);
		if (!buf)
			return -ENOMEM;

		memcpy(buf, con->v2.in_kvecs[0].iov_base, ctrl_len);
		return __handle_control(con, buf);
	}

It looks like we always return -EINVAL here because con->state == CEPH_CON_S_V2_AUTH. Am I missing something here?

Thanks,
Slava.

[1] https://elixir.bootlin.com/linux/v6.19/source/net/ceph/messenger_v2.c#L2982

author maintainer
#3 lore raw
Quoted 41 lines · Viacheslav Dubeyko
Quoted 17 lines · Ilya Dryomov

Similar checks are performed for all control frames, but an early check for message frames was missing. process_message() is already set up to terminate the loop in case the state changes while con->ops->dispatch() handler is being executed.

---
 net/ceph/messenger_v2.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ceph/messenger_v2.c +0 -0
index ed618435d33a..c4ddf7911f7d 100644
@@ -2905,6 +2905,11 @@ static int __handle_control(struct ceph_connection *con, void *p)
      if (con->v2.in_desc.fd_tag != FRAME_TAG_MESSAGE)

net/ceph/messenger_v2.c static int __handle_control(struct ceph_connection *con, void *p) · line 2915

Quoted 10 lines
net/ceph/messenger_v2.c +5 -0
              return process_control(con, p, end);
 
+     if (con->state != CEPH_CON_S_OPEN) {
+             con->error_msg = "protocol error, unexpected message";
+             return -EINVAL;
+     }
+
      ret = process_message_header(con, p, end);
      if (ret < 0)
              return ret;

I am slightly worried about this place [1]:

        if (con->state == CEPH_CON_S_V2_AUTH) {
                buf = alloc_conn_buf(con, ctrl_len);
                if (!buf)
                        return -ENOMEM;

                memcpy(buf, con->v2.in_kvecs[0].iov_base, ctrl_len);
                return __handle_control(con, buf);
        }
Quoted 2 lines

It looks like we always return -EINVAL here because con->state == CEPH_CON_S_V2_AUTH. Am I missing something here?

__handle_control() can be called in a few different states (i.e. under a few different con->state values), including CEPH_CON_S_V2_AUTH. When __handle_control() is called from the above branch, it's expected to be for a control frame. This patch makes __handle_control() insist on CEPH_CON_S_OPEN only for message frames (FRAME_TAG_MESSAGE) so it won't always fail with EINVAL here.

Thanks,

Ilya

Reviewed-by
#4 lore raw
Quoted 45 lines · Ilya Dryomov
Quoted 41 lines · Viacheslav Dubeyko
Quoted 17 lines · Ilya Dryomov

Similar checks are performed for all control frames, but an early check for message frames was missing. process_message() is already set up to terminate the loop in case the state changes while con->ops->dispatch() handler is being executed.

---
 net/ceph/messenger_v2.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ceph/messenger_v2.c +0 -0
index ed618435d33a..c4ddf7911f7d 100644
@@ -2905,6 +2905,11 @@ static int __handle_control(struct ceph_connection *con, void *p)
      if (con->v2.in_desc.fd_tag != FRAME_TAG_MESSAGE)

net/ceph/messenger_v2.c static int __handle_control(struct ceph_connection *con, void *p) · line 2915

Quoted 10 lines
net/ceph/messenger_v2.c +5 -0
              return process_control(con, p, end);
 
+     if (con->state != CEPH_CON_S_OPEN) {
+             con->error_msg = "protocol error, unexpected message";
+             return -EINVAL;
+     }
+
      ret = process_message_header(con, p, end);
      if (ret < 0)
              return ret;

I am slightly worried about this place [1]:

        if (con->state == CEPH_CON_S_V2_AUTH) {
                buf = alloc_conn_buf(con, ctrl_len);
                if (!buf)
                        return -ENOMEM;

                memcpy(buf, con->v2.in_kvecs[0].iov_base, ctrl_len);
                return __handle_control(con, buf);
        }
Quoted 2 lines

It looks like we always return -EINVAL here because con->state == CEPH_CON_S_V2_AUTH. Am I missing something here?

Quoted 8 lines

__handle_control() can be called in a few different states (i.e. under a few different con->state values), including CEPH_CON_S_V2_AUTH. When __handle_control() is called from the above branch, it's expected to be for a control frame. This patch makes __handle_control() insist on CEPH_CON_S_OPEN only for message frames (FRAME_TAG_MESSAGE) so it won't always fail with EINVAL here.

OK. I see. The patch looks good.

Thanks,
Slava.