Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3874583pxb; Tue, 17 Nov 2020 05:59:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb+/86Ks4w7yiKBI2uAAdCHQJRYK/46BgPrVq34v9OBylPqZyY2mkUQx4/fRrrTv6l0AFv X-Received: by 2002:a05:6402:1585:: with SMTP id c5mr20178510edv.372.1605621542049; Tue, 17 Nov 2020 05:59:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621542; cv=none; d=google.com; s=arc-20160816; b=i6gc9QPN3Iep6R97WgWO0jzq8hIMRK/8FKIuH7SL01DMZ7ZhmO8yFOianvywIFbhM1 TQQ6r7F8cEd+KXGW49WSExOoubVlXoIH0yCJkGD1PvtZqCLdcs5yYQA4tVK4dHuRdNEJ BXH/SmVQKLejl1nTfUlkF+02RGAFVyORfdwh8j/fDV3MXiGFbuyrYy+FVzqomZTmuAG5 j3ixBBS3swZ7xXQ9IqE4/N4ZdCkBnGk6v2niHqK9ZnO7yqFBGN/K9ljO62K67OPVYCsU 6hjFoKO7jvy2LcHt5YzeAHja9vYR6mADldA+yG9t/viYlhjw8nvTkURK1kyg9WUYbQKg njfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QgCVc5XKPcMogpVM2+zezkHgdY9e3NMX1HLflQIeqD4=; b=Mqiy4BzxTpQNegwF0V5BsP3Q8EtinAZYHkBENPywjxxCNrSxFGCzhi1Ma8A4ZuNKo7 hZ6XGazU8wAYcILyF9amxcui0/CKQXkIEiyiL5FB9dDvtACsrr6Ps4hG27kiZtGgCyze vX69to76zFSprwsoKk7GebZ4jwEIoYd3t0WMcc6svWq9ZXkeBQbcmIL6b4w0O26D2JmO ftMu1hksxi78+hAQ/EuIV4AAcNRAMRY4MDmRWxzy1lp7ShAKFEj6Fek84olxnhXCzljt lV5fmBNaCZf4WY57jYH9Mh8xeuVv2pTf7/nD40syXa7ryp6lgh4dcYaH6X6vZ3u49ICV o4Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xYZojWap; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k9si13040808ejx.605.2020.11.17.05.58.39; Tue, 17 Nov 2020 05:59:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xYZojWap; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731052AbgKQN5H (ORCPT + 99 others); Tue, 17 Nov 2020 08:57:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:56238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731104AbgKQNWE (ORCPT ); Tue, 17 Nov 2020 08:22:04 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A5A4D221FE; Tue, 17 Nov 2020 13:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619324; bh=e6UyMN3hF1Sjnmt9zKWw8WaZgONJIs6z6eppvdaU9u4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xYZojWapph+haugQCNjn5HRY1SWhcTYmBNzvWBx8xgKj4htMY5H+4/sLs563ABlgC GAd7MkOQB7HntYC0wP5FS/ulKoK9/2FC8+5rad71SvnNhTQC+yeoFPxMhs1AgZR1Uk HUEFkreq49W43og6u0clIll2fWmjE5II7bJVJ+GA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , "Matthew Wilcox (Oracle)" , David Sterba Subject: [PATCH 4.19 075/101] btrfs: fix potential overflow in cluster_pages_for_defrag on 32bit arch Date: Tue, 17 Nov 2020 14:05:42 +0100 Message-Id: <20201117122116.770326371@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox (Oracle) commit a1fbc6750e212c5675a4e48d7f51d44607eb8756 upstream. On 32-bit systems, this shift will overflow for files larger than 4GB as start_index is unsigned long while the calls to btrfs_delalloc_*_space expect u64. CC: stable@vger.kernel.org # 4.4+ Fixes: df480633b891 ("btrfs: extent-tree: Switch to new delalloc space reserve and release") Reviewed-by: Josef Bacik Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: David Sterba [ define the variable instead of repeating the shift ] Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1239,6 +1239,7 @@ static int cluster_pages_for_defrag(stru u64 page_start; u64 page_end; u64 page_cnt; + u64 start = (u64)start_index << PAGE_SHIFT; int ret; int i; int i_done; @@ -1255,8 +1256,7 @@ static int cluster_pages_for_defrag(stru page_cnt = min_t(u64, (u64)num_pages, (u64)file_end - start_index + 1); ret = btrfs_delalloc_reserve_space(inode, &data_reserved, - start_index << PAGE_SHIFT, - page_cnt << PAGE_SHIFT); + start, page_cnt << PAGE_SHIFT); if (ret) return ret; i_done = 0; @@ -1346,8 +1346,7 @@ again: btrfs_mod_outstanding_extents(BTRFS_I(inode), 1); spin_unlock(&BTRFS_I(inode)->lock); btrfs_delalloc_release_space(inode, data_reserved, - start_index << PAGE_SHIFT, - (page_cnt - i_done) << PAGE_SHIFT, true); + start, (page_cnt - i_done) << PAGE_SHIFT, true); } @@ -1374,8 +1373,7 @@ out: put_page(pages[i]); } btrfs_delalloc_release_space(inode, data_reserved, - start_index << PAGE_SHIFT, - page_cnt << PAGE_SHIFT, true); + start, page_cnt << PAGE_SHIFT, true); btrfs_delalloc_release_extents(BTRFS_I(inode), page_cnt << PAGE_SHIFT); extent_changeset_free(data_reserved); return ret;