libceph: admit message frames only in CEPH_CON_S_OPEN state
Ilya Dryomov
maintainerPATCH 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
@@ -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
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 whilecon->ops->dispatch()handler is being executed.Signed-off-by Ilya Dryomov <[email protected]>--- net/ceph/messenger_v2.c | 5 +++++ 1 file changed, 5 insertions(+)net/ceph/messenger_v2.c +5
-1@@ -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
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 whilecon->ops->dispatch()handler is being executed.Signed-off-by Ilya Dryomov <[email protected]>--- net/ceph/messenger_v2.c | 5 +++++ 1 file changed, 5 insertions(+)net/ceph/messenger_v2.c +0
-0@@ -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
-0return 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
Ilya Dryomov
maintainerQuoted 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 whilecon->ops->dispatch()handler is being executed.Signed-off-by Ilya Dryomov <[email protected]>--- net/ceph/messenger_v2.c | 5 +++++ 1 file changed, 5 insertions(+)net/ceph/messenger_v2.c +0
-0@@ -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
-0return 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
-EINVALhere becausecon->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
Viacheslav Dubeyko
Reviewed-byQuoted 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 whilecon->ops->dispatch()handler is being executed.Signed-off-by Ilya Dryomov <[email protected]>--- net/ceph/messenger_v2.c | 5 +++++ 1 file changed, 5 insertions(+)net/ceph/messenger_v2.c +0
-0@@ -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
-0return 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
-EINVALhere becausecon->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 differentcon->statevalues), includingCEPH_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 onCEPH_CON_S_OPENonly for message frames (FRAME_TAG_MESSAGE) so it won't always fail with EINVAL here.
OK. I see. The patch looks good.
Thanks,
Slava.