From patchwork Thu Mar 27 18:17:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3899181 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 465AEBF540 for ; Thu, 27 Mar 2014 18:18:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FEFC20253 for ; Thu, 27 Mar 2014 18:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A796820225 for ; Thu, 27 Mar 2014 18:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757048AbaC0SSq (ORCPT ); Thu, 27 Mar 2014 14:18:46 -0400 Received: from mail-ee0-f50.google.com ([74.125.83.50]:65228 "EHLO mail-ee0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756966AbaC0SSp (ORCPT ); Thu, 27 Mar 2014 14:18:45 -0400 Received: by mail-ee0-f50.google.com with SMTP id c13so3272629eek.9 for ; Thu, 27 Mar 2014 11:18:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=6lZ4nJiBylU/1Wk4r6jnlV/nmcy0gaZ9YeHICw4Crho=; b=iooCh0y9CRoLyjKgGdgbFzh9Lm9ZNVwgXumKJHm+T9y7SMgTz5+I37VLdlbfMrySoE /KSrmOaZdMd+GSNnUqp8T/mwClj7QcUIWb6rA0RzyZcC3fO5K0X/Kz5ExpuVOjqmpFQ9 TiAP7bMIi1TrD4Id+rMXvHbrqIOh4R/FnQruOERzSWCdg/cAPlq1vO2DcMxtmhRdTg7E J2bCzMrsF8hMOo+e9fidlake4yKlyKJr0aLU8pyBnWpmcZonhB9a1lWIWlE+qTXcd7uF jTi6hfEq+LCMBRviV91ubnCr0kgBQqyBfHgTNqdHzQ8Sylwk08SfWHJI1V6SVI/ae+Zk 5QLQ== X-Gm-Message-State: ALoCoQnisWBmrXktPCW+sjzzcayK7P00buqwnNLwMCcNBjfEraozwp9vMhpJCQjRLOMnRPops1aq X-Received: by 10.14.193.201 with SMTP id k49mr3158811een.50.1395944324600; Thu, 27 Mar 2014 11:18:44 -0700 (PDT) Received: from localhost ([109.110.66.7]) by mx.google.com with ESMTPSA id o7sm5962702eew.25.2014.03.27.11.18.43 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 11:18:44 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 09/33] libceph: fix crush_decode() call site in osdmap_decode() Date: Thu, 27 Mar 2014 20:17:55 +0200 Message-Id: <1395944299-21970-10-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> References: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The size of the memory area feeded to crush_decode() should be limited not only by osdmap end, but also by the crush map length. Also, drop unnecessary dout() (dout() in crush_decode() conveys the same info) and step past crush map only if it is decoded successfully. Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder --- net/ceph/osdmap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 19aca4d3c5dd..b70357adbdc0 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -796,16 +796,13 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map) /* crush */ ceph_decode_32_safe(p, end, len, e_inval); - dout("osdmap_decode crush len %d from off 0x%x\n", len, - (int)(*p - start)); - ceph_decode_need(p, end, len, e_inval); - map->crush = crush_decode(*p, end); - *p += len; + map->crush = crush_decode(*p, min(*p + len, end)); if (IS_ERR(map->crush)) { err = PTR_ERR(map->crush); map->crush = NULL; goto bad; } + *p += len; /* ignore the rest */ *p = end;