Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5996439ybc; Wed, 27 Nov 2019 13:06:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxlwrMbHMTMTg0kFgDUeSjeMtOc5/p1BDu4EzSH5cbG7eWPHPapSyDVnBgfFeCL5NDSg9Ae X-Received: by 2002:a50:8c02:: with SMTP id p2mr34216445edp.30.1574888816399; Wed, 27 Nov 2019 13:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888816; cv=none; d=google.com; s=arc-20160816; b=K5xuuDphTnH+vxqFdmQ9Up6lddFlmHyzSSDQyw+pkHdI+jhXBjMTcpd0qyRy0uZEEO bV7CSWeXF/8ryprg1jQKc0fsn3foxB4+7rTtTzyRsWK9szZER2F7SgpwcEsVBuZC8V0D yH+98PuIjYn+kGJPrfcMS92mCwEGitK9T8/+LpPyvtffzH+5YsXF6X7dT9CHdBiJFKvo dMoJRLDP9Z78XB3uADU7TmpTfai0Ql/KACtwNw0Y+2APM3sxrEF5ZUPTjWcYBgIZoHN6 mNg888Ek2bPLy6dUo4Dq6V0sr8f27aH+ZXpjyELn1qZ4PS0BIfyxYiub+Z++9Z/B9KVR Lkbw== 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=Cboaq46JC2CoHALHx0Q9iU6hIUELyP2RClPNHB/aLwg=; b=gT7+YR5p66WENL+s0Ju9zFWIOQWSY63pr3QVnPlKEds15jf1H/KYumwyoisEy05iRS IGFKUBULlSM7EsM8ITRWDTngIvJyjOZDMPo/3/N+SpeoL2NfydAwJ9KGNgnRLtkKTEdQ JtCmDMuJdqzCKOq+N68Q30RFJwezYLcgq2MgQdyAyhIwlwR097JRa8gfKjuf+CkNRSaI zvWIPtt5exvhuBuApRgV5cj8G29LmvBhEUnN+Rn/kEdNuMfYPJ+ASALCRsA70vtW4TEQ qFZlmD/O19mlVOgizQpTvJNE/xo/8PUR7dwj62ELrJ6CUou6cxUNNHLNgBVERyROP+x6 Az5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S1jmk9zr; 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 l15si10027476ejd.187.2019.11.27.13.06.32; Wed, 27 Nov 2019 13:06:56 -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=S1jmk9zr; 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 S1732043AbfK0VDa (ORCPT + 99 others); Wed, 27 Nov 2019 16:03:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:56610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731679AbfK0VDY (ORCPT ); Wed, 27 Nov 2019 16:03:24 -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 8EDAC217AB; Wed, 27 Nov 2019 21:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888603; bh=Z5a/og1bx1sz2Y6k8bJubC1q/duzlsbMbgSblkYn4a0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S1jmk9zr7qi52XPLDLBVSbGLDSfwdcdP7ms2+i8x2EW5RAQ3uRQnzT3GdX8XIeZVI flpgF/XOVxSYrWLBAbrKtAowMzU0kFAC7P+HvGrod6gruXecZ1BfZsl4xIpUpIaLO3 vosVox/2AtnYvRldS0qeWV1CDSKYoUMhvQ9hzBl8= 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.19 199/306] ocfs2: fix clusters leak in ocfs2_defrag_extent() Date: Wed, 27 Nov 2019 21:30:49 +0100 Message-Id: <20191127203129.722775199@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 f55f82ca34250..1565dd8e8856e 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) { BUG_ON(!ocfs2_is_refcount_inode(inode)); @@ -312,6 +314,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; } } @@ -336,6 +339,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