Skip to content

Commit

Permalink
libceph: validate con->state at the top of try_write()
Browse files Browse the repository at this point in the history
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().

Cc: [email protected]
Link: https://tracker.ceph.com/issues/23706
Signed-off-by: Ilya Dryomov <[email protected]>
Reviewed-by: Jason Dillaman <[email protected]>
  • Loading branch information
idryomov committed Apr 26, 2018
1 parent 7b4c443 commit 9c55ad1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions net/ceph/messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,11 @@ static int try_write(struct ceph_connection *con)
int ret = 1;

dout("try_write start %p state %lu\n", con, con->state);
if (con->state != CON_STATE_PREOPEN &&
con->state != CON_STATE_CONNECTING &&
con->state != CON_STATE_NEGOTIATING &&
con->state != CON_STATE_OPEN)
return 0;

more:
dout("try_write out_kvec_bytes %d\n", con->out_kvec_bytes);
Expand All @@ -2594,6 +2599,8 @@ static int try_write(struct ceph_connection *con)
}

more_kvec:
BUG_ON(!con->sock);

/* kvec data queued? */
if (con->out_kvec_left) {
ret = write_partial_kvec(con);
Expand Down

0 comments on commit 9c55ad1

Please sign in to comment.