From: Bob Liu Subject: [PATCH v2 3/3] tmem: fix Out-of-bounds read reported by Coverity Date: Wed, 7 May 2014 14:30:50 +0800 Message-ID: <1399444250-17529-3-git-send-email-bob.liu@oracle.com> References: <1399444250-17529-1-git-send-email-bob.liu@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WhvO9-0002o1-MP for xen-devel@lists.xenproject.org; Wed, 07 May 2014 06:31:33 +0000 Received: by mail-pd0-f176.google.com with SMTP id y13so630614pdi.21 for ; Tue, 06 May 2014 23:31:30 -0700 (PDT) In-Reply-To: <1399444250-17529-1-git-send-email-bob.liu@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: andrew.cooper3@citrix.com, keir@xen.org, jbeulich@suse.com List-Id: xen-devel@lists.xenproject.org CID 1198729, CID 1198730 and CID 1198734 complain about "Out-of-bounds read". This patch fixes them by casting the 'firstbyte' to (uint8_t), some unnecessary assertion also be dropped. Signed-off-by: Bob Liu Reviewed-by: Andrew Cooper --- xen/common/tmem.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/xen/common/tmem.c b/xen/common/tmem.c index f2dc26e..93235c6 100644 --- a/xen/common/tmem.c +++ b/xen/common/tmem.c @@ -399,7 +399,7 @@ static void pcd_disassociate(struct tmem_page_descriptor *pgp, struct tmem_pool { struct tmem_page_content_descriptor *pcd = pgp->pcd; struct page_info *pfp = pgp->pcd->pfp; - uint16_t firstbyte = pgp->firstbyte; + uint8_t firstbyte = pgp->firstbyte; char *pcd_tze = pgp->pcd->tze; pagesize_t pcd_size = pcd->size; pagesize_t pgp_size = pgp->size; @@ -407,8 +407,6 @@ static void pcd_disassociate(struct tmem_page_descriptor *pgp, struct tmem_pool pagesize_t pcd_csize = pgp->pcd->size; ASSERT(tmem_dedup_enabled()); - ASSERT(firstbyte != NOT_SHAREABLE); - ASSERT(firstbyte < 256); if ( have_pcd_rwlock ) ASSERT_WRITELOCK(&pcd_tree_rwlocks[firstbyte]); @@ -1231,7 +1229,7 @@ static bool_t tmem_try_to_evict_pgp(struct tmem_page_descriptor *pgp, bool_t *ho struct tmem_object_root *obj = pgp->us.obj; struct tmem_pool *pool = obj->pool; struct client *client = pool->client; - uint16_t firstbyte = pgp->firstbyte; + uint8_t firstbyte = pgp->firstbyte; if ( pool->is_dying ) return 0; @@ -1239,10 +1237,9 @@ static bool_t tmem_try_to_evict_pgp(struct tmem_page_descriptor *pgp, bool_t *ho { if ( tmem_dedup_enabled() ) { - firstbyte = pgp->firstbyte; - if ( firstbyte == NOT_SHAREABLE ) + if ( pgp->firstbyte == NOT_SHAREABLE ) goto obj_unlock; - ASSERT(firstbyte < 256); + firstbyte = pgp->firstbyte; if ( !write_trylock(&pcd_tree_rwlocks[firstbyte]) ) goto obj_unlock; if ( pgp->pcd->pgp_ref_count > 1 && !pgp->eviction_attempted ) -- 1.7.10.4