Received: by 10.192.165.156 with SMTP id m28csp1122571imm; Wed, 11 Apr 2018 12:52:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+pMmmR+hQQVmRqXPNt7QCskqDpSPZEqSN1KoVPptKl/7PjTJMaA6BE6NgLbVMhNtfWzWwE X-Received: by 2002:a17:902:b7c7:: with SMTP id v7-v6mr6372475plz.190.1523476347751; Wed, 11 Apr 2018 12:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523476347; cv=none; d=google.com; s=arc-20160816; b=boCltXYbZY1NPKhXQq8/rH8EeKqLvx8UOdEMRgCEqENRh+Jvt0y+gUfmclQrXOu8DO eSbAdUSegVuOe+v2CUQeu6HoT77zTq1hatdmYN7OfEbFcL8ODDb0LMmxJHRdQ//1tnpa 9umqeX+CJGhLxbN15FHBzX4FIFhWI3PXBWyhjW1y7+VhFR6GB+wEd4nSEn3oXx6EdpAJ 9J1HoT6gebMc5Dj3LIrQJxDIKxCemhmyffLBd4gE6EUHPJM1vKmUUH3EJ/k37Ac25I4I LJfRmHpshz5OYHPgwzGK3hAt6vd6RtbrPozjl5J3vcMCdPfV7MqlbNQkYF9Zz/MOO5tc aPOg== 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=oKgNAqVgSgeQs8vlMoShhgSoji1fqdqJqULA/+ffijw=; b=uG2tOSl69+9tWlKHZ3wV29GkFHWzavmFG5THPDZxP7oso1ylpJGmab8CfD/Ij/GEek 6dN5wXiW4QzkrWqo0iv2b4u4AcrrktHvrE6Xt02iFR9wcRX79xGqD2njg0kod5O91omg 6BuS3B2kbcPvRfL4mOwEMmp/X5qlIg/uUNL7AbH/WP5pQfRx2Wtim/JYyhftwhtb5IUj hIK4zXpLuyj/r03XpasoOOegJPoUxejHvxIMBUDoI6vtVX0ZE8qh0esdJvQpX2i3QA8w ltwcoOIC3aZ609VPGmuyF6WlSWBj1Fp0sUBnB84D8gK2zJgL4c7gDMfyRjn4y3D/P0Sb 1FPA== 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 q61-v6si1626735plb.729.2018.04.11.12.51.50; Wed, 11 Apr 2018 12:52:27 -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 S934014AbeDKS65 (ORCPT + 99 others); Wed, 11 Apr 2018 14:58:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36846 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932560AbeDKS6z (ORCPT ); Wed, 11 Apr 2018 14:58:55 -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 99DE3DD3; Wed, 11 Apr 2018 18:58:54 +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.9 107/310] ext4: fix off-by-one on max nr_pages in ext4_find_unwritten_pgoff() Date: Wed, 11 Apr 2018 20:34:06 +0200 Message-Id: <20180411183626.810637061@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@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.9-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 @@ -429,7 +429,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)