Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3867966pxb; Tue, 17 Nov 2020 05:47:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHRgekq82j7qd1/CXF4vZmSMVZ1T7yohL4AK6OEPa3Oa7kcfkbMd4sZNX6Od0f503XkL6j X-Received: by 2002:a17:906:8319:: with SMTP id j25mr20832321ejx.68.1605620866474; Tue, 17 Nov 2020 05:47:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620866; cv=none; d=google.com; s=arc-20160816; b=db8U1oUdAwEpE7OkDA0tfbMBbdGXB71Ca7I3dagEFVjVcLMYdgZt34rtHJvS2c6tcW auTZ3dTLsT445RMV2ffnuZ4JNEPHOFLjU+H/18bu420WDno0E5fvd3GxX3fFhaVmLKdX BiAty39An/SEzPVaKYFgflIW2+qlzNGMYnSCpN1BD3bHDN4PfPbZJBF/YIVqBjr0VkWD nBezRk9Fvk8JOa47O10iXfMl8eVrZ/a33oNylYhp1GnwxYkxi/6yVpQBPPTx1+VDo2ii dfC3PtjkOuSPFzFGIJO1MABzkHdYZZO0S3crdY4z1Fh48CpQH7rimkGhUiNTSUgAlM3V 1fEA== 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=VbSmmH9P34fgxdPXp8Qb6ib7wvyCjjvvmBuKotFj48c=; b=zqSqGTpFycG7fcHIWWsaqY7Drv1gtwYjb6/ajemxe8qM0q1Ng1QyInd2/42sD7RL/j BGViEyaJiIFkD5iW59Xa+fAVDc7n8UWbpJhwVLvG0Fmxfz4nJD09WoSgk7wEDBZlW8dZ c4n0OqbP8OECnqOBO2lIea2OvQQ56ApryWTD70BTa2+KTTliQ4747FWlV33gH94Mhu1Q fJWGR5o7DZsmxeVNw67rDygapcjtei/WDyYUNJjTWYYNc2SZ232n2v6IcoZR+pUTcgiW Hu08mpSRWc8NwzMGjG/xjfLhdiDWrzYLQ/01tUZRPuhrmGJaH5zH2HiDoao2tIbBq4xB aMww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O8qH5wUV; 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 s3si1188240edt.326.2020.11.17.05.47.21; Tue, 17 Nov 2020 05:47:46 -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=O8qH5wUV; 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 S1732844AbgKQNpl (ORCPT + 99 others); Tue, 17 Nov 2020 08:45:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:51282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732687AbgKQNj2 (ORCPT ); Tue, 17 Nov 2020 08:39:28 -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 EDB0824695; Tue, 17 Nov 2020 13:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620367; bh=7R0dZauWIWuIurbo1dI7lJaXShXrrZAkqR/55o9O18o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O8qH5wUVzilgKUTgsEDnRPXgtiJ+6Qm3TfaM9zVOjtXbwX41HT6Cj6Grv6irAVYFH 2P32oGSVKdsPCPNOTqXtPrlsaS0fcyssXgW/YN3CvEYChQlTljFhQkfmNntyNkBKtV qVxkucHHi3VTIELUxXPkhZpAShjJ8tonUPjV5KBI= 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 5.9 187/255] btrfs: fix potential overflow in cluster_pages_for_defrag on 32bit arch Date: Tue, 17 Nov 2020 14:05:27 +0100 Message-Id: <20201117122148.025371260@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@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 @@ -1261,6 +1261,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; @@ -1277,8 +1278,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(BTRFS_I(inode), &data_reserved, - start_index << PAGE_SHIFT, - page_cnt << PAGE_SHIFT); + start, page_cnt << PAGE_SHIFT); if (ret) return ret; i_done = 0; @@ -1367,8 +1367,7 @@ again: btrfs_mod_outstanding_extents(BTRFS_I(inode), 1); spin_unlock(&BTRFS_I(inode)->lock); btrfs_delalloc_release_space(BTRFS_I(inode), data_reserved, - start_index << PAGE_SHIFT, - (page_cnt - i_done) << PAGE_SHIFT, true); + start, (page_cnt - i_done) << PAGE_SHIFT, true); } @@ -1395,8 +1394,7 @@ out: put_page(pages[i]); } btrfs_delalloc_release_space(BTRFS_I(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;