Ilya Dryomov 30c85553d8 libceph: validate con->state at the top of try_write()
commit 9c55ad1c214d9f8c4594ac2c3fa392c1c32431a7 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().

Cc: stable@vger.kernel.org
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-01 15:13:09 -07:00
..
2016-12-03 23:54:25 -05:00
2017-11-15 15:53:17 +01:00
2018-04-13 19:48:29 +02:00
2018-03-31 18:11:35 +02:00
2016-10-20 11:23:08 -04:00
2018-04-20 08:21:07 +02:00
2018-04-24 09:34:17 +02:00
2017-10-08 10:26:06 +02:00
2016-08-17 19:36:23 -04:00
2016-08-17 19:36:23 -04:00