libceph: avoid NULL kref_put from NULL alloc_msg return
authorSage Weil <sage@inktank.com>
Thu, 25 Oct 2012 15:49:41 +0000 (08:49 -0700)
committerAlex Elder <elder@inktank.com>
Fri, 26 Oct 2012 21:35:04 +0000 (16:35 -0500)
The ceph_on_in_msg_alloc() method calls the ->alloc_msg() helper which
may return NULL.  It also drops con->mutex while it allocates a message,
which means that the connection state may change (e.g., get closed).  If
that happens, we clean up and bail out.  Avoid calling ceph_msg_put() on
a NULL return value and triggering a crash.

This was observed when an ->alloc_msg() call races with a timeout that
resends a zillion messages and resets the connection, and ->alloc_msg()
returns NULL (because the request was resent to another target).

Fixes http://tracker.newdream.net/issues/3342

Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Alex Elder <elder@inktank.com>
net/ceph/messenger.c

index 66f6f56bcb2325bef8c12dfd77a13dd56032e408..1041114453db400b36d6b3429937425f11a0198f 100644 (file)
@@ -2742,7 +2742,8 @@ static int ceph_con_in_msg_alloc(struct ceph_connection *con, int *skip)
                msg = con->ops->alloc_msg(con, hdr, skip);
                mutex_lock(&con->mutex);
                if (con->state != CON_STATE_OPEN) {
-                       ceph_msg_put(msg);
+                       if (msg)
+                               ceph_msg_put(msg);
                        return -EAGAIN;
                }
                con->in_msg = msg;