Received: by 10.192.165.156 with SMTP id m28csp1171041imm; Wed, 11 Apr 2018 13:50:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx48/2PtAwndyorZ9bBghwp8Ot6XZsYMgJGzldbXBXNJtUNH2b9iqYnIw+ID7m67RUsCbPvzU X-Received: by 10.101.92.69 with SMTP id v5mr4368552pgr.405.1523479818595; Wed, 11 Apr 2018 13:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523479818; cv=none; d=google.com; s=arc-20160816; b=agIj1ME3CsOL/OY1hc91Osbkm8lioEzJ7vdiZ7T95zdlHwNNAphqt4r6YGIttGajEJ vdvxM6lIl51O0euNzr0rEss1+CREzpWfV6jkh01/uVUUW6MI1SE9pUmO3fmr2+YLgXmU vvwN5P4GoJHUekdJOHuSXcxYQC74VI9nPYimBJ8PqWtSoa/o+NylLNHwtL6NF8zDMghx ws3uzFsUSyJ0Tjuhq08qIegWHOGWGxxY4jC1F5lEVW3JciY25HHGJYIbaT7Sqya9xFWX gVHVSMoTlU1cygbsD/+Lt3Bv4+WyLk/WIh3jKefM0adqMaN+iJFfjy6JG36i52JH96ab snCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=bPbdUVWs9n+GzKoIywGlr+hDe6DdbJpKG+LR8AgfvMk=; b=U9w+Z9GG//58gl6pFH0rODinHk3xq8pDt8nyoRkwHPT0LypGBuvNk4/VZ/jM/iUhGl hUVVuGjNcuDYohsVhllizf+6PzTCOqD0HXEyafVDjRCD9Muvw4G6/RUwkappEaZ1Ej32 8HjhrEWoxUkWuDOJldBAPKD9dTmQU4p1nq6xaD/Hzt8CBrIyKV3rImNMo+YArrfRUjpQ iW/ryVMLq7MUJef2ldVKf3O4d2GLWhGb6679UVio7s5gtJdHDs0i4H+EFDOkGTsEwh85 TbPXJm1jK33lF7r1uDSawpczeXlFh0z77BIFUV5YBDteGxsAq8MomZj5tbQUTzw6axA8 T7wA== ARC-Authentication-Results: i=1; mx.google.com; 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 g7si1427433pfm.106.2018.04.11.13.49.41; Wed, 11 Apr 2018 13:50:18 -0700 (PDT) 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; 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 S1756143AbeDKUqg (ORCPT + 99 others); Wed, 11 Apr 2018 16:46:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59002 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755017AbeDKSqj (ORCPT ); Wed, 11 Apr 2018 14:46:39 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B9B4DD91; Wed, 11 Apr 2018 18:46:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eryu Guan , Theodore Tso , Jan Kara , Sasha Levin Subject: [PATCH 4.4 074/190] ext4: fix off-by-one on max nr_pages in ext4_find_unwritten_pgoff() Date: Wed, 11 Apr 2018 20:35:20 +0200 Message-Id: <20180411183554.645052661@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183550.114495991@linuxfoundation.org> References: <20180411183550.114495991@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eryu Guan [ Upstream commit 624327f8794704c5066b11a52f9da6a09dce7f9a ] ext4_find_unwritten_pgoff() is used to search for offset of hole or data in page range [index, end] (both inclusive), and the max number of pages to search should be at least one, if end == index. Otherwise the only page is missed and no hole or data is found, which is not correct. When block size is smaller than page size, this can be demonstrated by preallocating a file with size smaller than page size and writing data to the last block. E.g. run this xfs_io command on a 1k block size ext4 on x86_64 host. # xfs_io -fc "falloc 0 3k" -c "pwrite 2k 1k" \ -c "seek -d 0" /mnt/ext4/testfile wrote 1024/1024 bytes at offset 2048 1 KiB, 1 ops; 0.0000 sec (42.459 MiB/sec and 43478.2609 ops/sec) Whence Result DATA EOF Data at offset 2k was missed, and lseek(2) returned ENXIO. This is unconvered by generic/285 subtest 07 and 08 on ppc64 host, where pagesize is 64k. Because a recent change to generic/285 reduced the preallocated file size to smaller than 64k. Signed-off-by: Eryu Guan Signed-off-by: Theodore Ts'o Reviewed-by: Jan Kara Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/ext4/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -460,7 +460,7 @@ static int ext4_find_unwritten_pgoff(str int i, num; unsigned long nr_pages; - num = min_t(pgoff_t, end - index, PAGEVEC_SIZE); + num = min_t(pgoff_t, end - index, PAGEVEC_SIZE - 1) + 1; nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index, (pgoff_t)num); if (nr_pages == 0)