Skip to content

Commit 33419c0

Browse files
idryomovbwhacks
authored andcommitted
libceph: validate con->state at the top of try_write()
commit 9c55ad1 upstream. ceph_con_workfn() validates con->state before calling try_read() and then try_write(). However, try_read() temporarily releases con->mutex, notably in process_message() and ceph_con_in_msg_alloc(), opening the window for ceph_con_close() to sneak in, close the connection and release con->sock. When try_write() is called on the assumption that con->state is still valid (i.e. not STANDBY or CLOSED), a NULL sock gets passed to the networking stack: BUG: unable to handle kernel NULL pointer dereference at 0000000000000020 IP: selinux_socket_sendmsg+0x5/0x20 Make sure con->state is valid at the top of try_write() and add an explicit BUG_ON for this, similar to try_read(). Link: https://tracker.ceph.com/issues/23706 Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Jason Dillaman <dillaman@redhat.com> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent 7c7a062 commit 33419c0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

net/ceph/messenger.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,11 @@ static int try_write(struct ceph_connection *con)
24532453
int ret = 1;
24542454

24552455
dout("try_write start %p state %lu\n", con, con->state);
2456+
if (con->state != CON_STATE_PREOPEN &&
2457+
con->state != CON_STATE_CONNECTING &&
2458+
con->state != CON_STATE_NEGOTIATING &&
2459+
con->state != CON_STATE_OPEN)
2460+
return 0;
24562461

24572462
more:
24582463
dout("try_write out_kvec_bytes %d\n", con->out_kvec_bytes);
@@ -2478,6 +2483,8 @@ static int try_write(struct ceph_connection *con)
24782483
}
24792484

24802485
more_kvec:
2486+
BUG_ON(!con->sock);
2487+
24812488
/* kvec data queued? */
24822489
if (con->out_skip) {
24832490
ret = write_partial_skip(con);

0 commit comments

Comments
 (0)