Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5979304ybc; Wed, 27 Nov 2019 12:48:02 -0800 (PST) X-Google-Smtp-Source: APXvYqzw8V57Xt/dmRZzIq7XEaG5hA+N/7oASabMguUOA3bEUpMQg1ox+t7QwUDC1aLOeKR37rMr X-Received: by 2002:a05:6402:791:: with SMTP id d17mr34628913edy.12.1574887682513; Wed, 27 Nov 2019 12:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887682; cv=none; d=google.com; s=arc-20160816; b=dN1XiDfraPnNyhjadClYvxF/ltDbgr424xgbTn7XE/rDOzbYltrzhIzcTG83UuED6z KdNHuL+1kzkJw92RO23LsDT9q4238j/9B/J7e2Kjolg+aoK2Dx7E33FanRRixWCIfeBF /oeUITZ1k59i+XRExOqWdBv0X031CTu/d2kiwdVMr+2gR05iJqrTEbnsk07i0mUjQt6z fqZ9NHIUZVzpqIJ8SKjWDVpvzYlSLpdb4z9gEOSDVMYTRvo/Q/y2xV08wt9Hyr9MiTjb t36t0ylJEEeI/iUS/xNBAq9j3+U2EgBMy96aGW2jhnzGtNOLAgY0rihHldlagAbmM23a pndA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jp5hXABhdNOGSCEilntLQN4Uvr3RuUP2MQ/9PCoT9OI=; b=Jw4qS+Q+07j8g6kLlsVgYmZiLLHcouMo03DFUy5eRhiJK5Fvd/8s1xXnwDjj9VC1vZ 5GF4wHpmJ6B6TL73T4w5W4Io3tqgn3W+s9W3Mg48tYNcyA2aR6y4A9I2asJvluaW4psu pq6qNcMEMVJPCvdDjHJscr/dbs78QpeGLBNREtUO+5VwopOlUkVQ7SggY37+19S3UY88 03gJrgeN5wbSRS5423jT89Fm4wmRpcACObBbOjl4XOBCZEdAGrKP6vYDSaSGMl7MquFI Udgi/TVHBwNxMzKq4T887DCcmAK7VxCD0yO57aGLmlAZvcmfKKT8nH5w/WUMjIECsOkF 6V2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1JXdlBDN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j30si1720321ejo.214.2019.11.27.12.47.38; Wed, 27 Nov 2019 12:48:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1JXdlBDN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbfK0UnC (ORCPT + 99 others); Wed, 27 Nov 2019 15:43:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:49822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727813AbfK0Umz (ORCPT ); Wed, 27 Nov 2019 15:42:55 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 200E8215A5; Wed, 27 Nov 2019 20:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887374; bh=RfNt5H0u5JixeIom6TwwaUehdoBhx0+rcH2DGPQH2iY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1JXdlBDNawh7aMvKN6LxBSPl03sd3WCL6kjrqxj2NEIKNod1ml6oktjt/LTYoGcOX ZSPFZG02KV+PAWMKaPOMolDRupXwi00W2bZlEumTAhEV5AAG+5CJOiiFaUm9lRMi0D CXbYPmUWilVDrcMdj36/ncCwdZL7uuPkPmVo5XBw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Larry Chen , Andrew Morton , Mark Fasheh , Joel Becker , Junxiao Bi , Joseph Qi , Changwei Ge , Linus Torvalds , Sasha Levin Subject: [PATCH 4.9 086/151] ocfs2: fix clusters leak in ocfs2_defrag_extent() Date: Wed, 27 Nov 2019 21:31:09 +0100 Message-Id: <20191127203036.669191575@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203000.773542911@linuxfoundation.org> References: <20191127203000.773542911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Larry Chen [ Upstream commit 6194ae4242dec0c9d604bc05df83aa9260a899e4 ] ocfs2_defrag_extent() might leak allocated clusters. When the file system has insufficient space, the number of claimed clusters might be less than the caller wants. If that happens, the original code might directly commit the transaction without returning clusters. This patch is based on code in ocfs2_add_clusters_in_btree(). [akpm@linux-foundation.org: include localalloc.h, reduce scope of data_ac] Link: http://lkml.kernel.org/r/20180904041621.16874-3-lchen@suse.com Signed-off-by: Larry Chen Reviewed-by: Andrew Morton Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Joseph Qi Cc: Changwei Ge Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/move_extents.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index c179afd0051a0..afaa044f5f6bd 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -25,6 +25,7 @@ #include "ocfs2_ioctl.h" #include "alloc.h" +#include "localalloc.h" #include "aops.h" #include "dlmglue.h" #include "extent_map.h" @@ -222,6 +223,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, struct ocfs2_refcount_tree *ref_tree = NULL; u32 new_phys_cpos, new_len; u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); + int need_free = 0; if ((ext_flags & OCFS2_EXT_REFCOUNTED) && *len) { @@ -315,6 +317,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, if (!partial) { context->range->me_flags &= ~OCFS2_MOVE_EXT_FL_COMPLETE; ret = -ENOSPC; + need_free = 1; goto out_commit; } } @@ -339,6 +342,20 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, mlog_errno(ret); out_commit: + if (need_free && context->data_ac) { + struct ocfs2_alloc_context *data_ac = context->data_ac; + + if (context->data_ac->ac_which == OCFS2_AC_USE_LOCAL) + ocfs2_free_local_alloc_bits(osb, handle, data_ac, + new_phys_cpos, new_len); + else + ocfs2_free_clusters(handle, + data_ac->ac_inode, + data_ac->ac_bh, + ocfs2_clusters_to_blocks(osb->sb, new_phys_cpos), + new_len); + } + ocfs2_commit_trans(osb, handle); out_unlock_mutex: -- 2.20.1