]> git.baikalelectronics.ru Git - kernel.git/commit
libceph: check data_len in ->alloc_msg()
authorIlya Dryomov <idryomov@gmail.com>
Wed, 2 Sep 2015 08:37:09 +0000 (11:37 +0300)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 9 Sep 2015 06:52:17 +0000 (09:52 +0300)
commitbd6a025c8ba59743f60bb36262b25179ffb6d21e
treec5341ec8d2b91adaa17d4ef3177a0b04ef9581a7
parent0e3f97e3bc753dd2917e72a2bfe64fed3f0875e8
libceph: check data_len in ->alloc_msg()

Only ->alloc_msg() should check data_len of the incoming message
against the preallocated ceph_msg, doing it in the messenger is not
right.  The contract is that either ->alloc_msg() returns a ceph_msg
which will fit all of the portions of the incoming message, or it
returns NULL and possibly sets skip, signaling whether NULL is due to
an -ENOMEM.  ->alloc_msg() should be the only place where we make the
skip/no-skip decision.

I stumbled upon this while looking at con/osd ref counting.  Right now,
if we get a non-extent message with a larger data portion than we are
prepared for, ->alloc_msg() returns a ceph_msg, and then, when we skip
it in the messenger, we don't put the con/osd ref acquired in
ceph_con_in_msg_alloc() (which is normally put in process_message()),
so this also fixes a memory leak.

An existing BUG_ON in ceph_msg_data_cursor_init() ensures we don't
corrupt random memory should a buggy ->alloc_msg() return an unfit
ceph_msg.

While at it, I changed the "unknown tid" dout() to a pr_warn() to make
sure all skips are seen and unified format strings.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
net/ceph/messenger.c
net/ceph/osd_client.c