Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2245434imm; Mon, 28 May 2018 04:40:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpoiExPFRx/wzIqzp+6kv9iJcIM5mX0w2rghhj7Wc7bnt9xdbhTibDzDloya9/v+ZbRThZN X-Received: by 2002:a65:4204:: with SMTP id c4-v6mr10153295pgq.26.1527507657028; Mon, 28 May 2018 04:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527507656; cv=none; d=google.com; s=arc-20160816; b=tm1IBtC2PWH4fXfFLdNk0EouxyyNl55aJnnGqzathht+GcHRBn7I4pleKOFzhE9NxH n+uM2xWtmvrAvqZ30dO2RMiqAPtD5T6xnYRlvx/qaWeTSGzp6EHuRw8Qzj5KYhJHdVlX FbeuENVobwTauhj1517hqjHkTndsa+yGZfIVtoYdKhBsckLGwltRsJkhKWxnx85pEjLD leJ6Y9szDLaXe4yx4xdCjMHhy7oK6BFWO24+ucmRdSy42epC6OpzbpRtX2UOIrnUccts 5Ib2oPvO/wVUSmRXgvlB5Ky9JT+eJeYQXpg0hqcQlMZf/xy/2RPFKfIddQtzTcx5UHW3 JxpA== 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:dkim-signature :arc-authentication-results; bh=inEEHDqgK1d/R80S2nH9a43TVqcFyqVSeUqTOXWWHYM=; b=neDTQ5h4bT2mNqMTS/S5IKMP6DIWyuju+Cf62l5yo9ZvJGbn/9KHEHY+I8lCBTDNuB znXC+e0M6fb5g1Z1WyIfXwC6p+OjlfLbCpbsXzYngoXtPpOdgpMxit8MqFQkhVb2c4Be K6Xd5sJvyPJstmb1KrDzuBNXpHuk0ivGe9ZBI2n7DbCfSiWvWcLxiB0kKD32jF3Eu/Tw puRMZeS2HP5SrbeQ9Cy9bLXGe4xYJ2SrAQP8FZzpCUzrhxkIa7Jmj5A2BbKOMX5fVPjH 3W5T4rH27xg4S00O7Si74HAjnYCRuRe8HeP3aL6MSXC0lwV0p5EOp9lEao2B4cxVDlne jyLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VbSwooIA; 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 d15-v6si11331459pgf.390.2018.05.28.04.40.42; Mon, 28 May 2018 04:40:56 -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; dkim=pass header.i=@kernel.org header.s=default header.b=VbSwooIA; 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 S938056AbeE1LMS (ORCPT + 99 others); Mon, 28 May 2018 07:12:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932506AbeE1LMP (ORCPT ); Mon, 28 May 2018 07:12:15 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 0E62320845; Mon, 28 May 2018 11:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505934; bh=p1P0Qj9B5YkjPk+aCabyo63fNsE8GlyFcudCwPhGZLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VbSwooIAiNuCgym2mTuWd1K9b4G/8laqg8KyE8pbKFmFbfQ/CPeTjr4jOHY4LKhSB FvCJJ7Iwg4D5vU3DMnYnhWYZafT9U51zlpvFnbFaY4lG0x4swKsAH/ibwsQNH4aQpn KXZHmRlHT9QXwjgZng8eKXD+uYQsg+7qCgenWrnU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 4.16 180/272] f2fs: fix to set KEEP_SIZE bit in f2fs_zero_range Date: Mon, 28 May 2018 12:03:33 +0200 Message-Id: <20180528100255.839918191@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 17cd07ae95073c298af92c1ba14ac58ce84de33b ] As Jayashree Mohan reported: A simple workload to reproduce this would be : 1. create foo 2. Write (8K - 16K) // foo size = 16K now 3. fsync() 4. falloc zero_range , keep_size (4202496 - 4210688) // foo size must be 16K 5. fdatasync() Crash now On recovery, we see that the file size is 4210688 and not 16K, which violates the semantics of keep_size flag. We have a test case to reproduce this using CrashMonkey on 4.15 kernel. Try this out by simply running : ./c_harness -f /dev/sda -d /dev/cow_ram0 -t f2fs -e 102400 -P -v tests/generic_468_zero.so The root cause is that we miss to set KEEP_SIZE bit correctly in zero_range when zeroing block cross EOF with FALLOC_FL_KEEP_SIZE, let's fix this missing case. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/file.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1348,8 +1348,12 @@ static int f2fs_zero_range(struct inode } out: - if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size) - f2fs_i_size_write(inode, new_size); + if (new_size > i_size_read(inode)) { + if (mode & FALLOC_FL_KEEP_SIZE) + file_set_keep_isize(inode); + else + f2fs_i_size_write(inode, new_size); + } out_sem: up_write(&F2FS_I(inode)->i_mmap_sem);