Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1670117ybz; Thu, 16 Apr 2020 13:20:48 -0700 (PDT) X-Google-Smtp-Source: APiQypIOZa/vZ+fkBqcfiLLngh827TU4A/vK3vaW+LxhvZ7YWx8Gkw8Pz+RmMc3BUW45KmIK82ub X-Received: by 2002:a50:ba83:: with SMTP id x3mr11277414ede.193.1587068447923; Thu, 16 Apr 2020 13:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587068447; cv=none; d=google.com; s=arc-20160816; b=VmBP552jOZgfv9j37ek5FZ6bqtX027Wzem9/mo75acWhz4MXKf8K+6+eMkVuy6mQTc unAxTCxZloX53ROah+E7nJn6tvaY4fx6ZyAiLGlVJiMbltnJnMENFaPp/7k8kzPa7jCA ST3mLX47gyXW9R5plBBjeEWeiFWYf54qNLJSyu2u0WVt5P5cGVpqlNO+VJOilvYNMVo9 RaOqnn94BRBhkVFlLlQzRR6hGk7W5whNpZTlMjy9/33HZCB1XgYo3TMoMKz9Cy30vewT wdBQCAxwn9Oxzi3Qt70us/tF+ZgUJE2i3FfMCmQ9X5PrjidCgKiwlWpkrBVe4NY0FuG8 Jttg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ot6YOs4qGrAaDt9vmzR/B3/spuEceGInLVKdb/zn3qc=; b=K0e+abHYyHAH2309mJIi6FPDmkZXNR3j8Q96GIBM9M/nY0vpFnEM58n29zeWqX0fTe qnKBozm9DdBfJDvdRmwcrLhYlc7ZR21RgZpK9S/7vzp1XzQ3yjnX7/gtXJlkhDm5uI0D ZT7CtLbIkCvDf7QEoooQI5S6z7DQwW3r0YIbLtKbQy2Ou0zXmXjtXUrMdZjIqCFKwkrB R2klkIyD51yaJtVgPUtBPZyjgo5NZNhk2G8ATomuKmoL6K0jMqhPgf2Ls87A4MwguuPd K0FPJ2syr9cscrG4ibbKqynktrB/1A7eEMR4X7F7XyLuv0m4ujI9CReLFYDwGc7fi3M8 xJCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Td8haKEP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si300013edi.76.2020.04.16.13.20.24; Thu, 16 Apr 2020 13:20:47 -0700 (PDT) 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=Td8haKEP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442027AbgDPOOD (ORCPT + 99 others); Thu, 16 Apr 2020 10:14:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:36106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726022AbgDPNuO (ORCPT ); Thu, 16 Apr 2020 09:50:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C3C522063A; Thu, 16 Apr 2020 13:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587045014; bh=GMCeEdBjC+Mv67Ici8GialvdPUryQ4WJJTJWdXnnZhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Td8haKEPPkStV8mFyrcEj2SMdzwx2D4nkl/yFalt4t5lsy3b8bLTAKGVTsvYz29CW WERN7mFsgBPF2TgPPQiWIakDScf/SfryAZTD7oqupLjl4MWNGjVHZoIp28JCU21C3S LHIP1Pd83KmrWEI1l5WCMf5/L2R23oXsqbnVxQZQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Changwei Ge , Andrew Morton , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Gang He , Jun Piao , Linus Torvalds Subject: [PATCH 5.4 194/232] ocfs2: no need try to truncate file beyond i_size Date: Thu, 16 Apr 2020 15:24:48 +0200 Message-Id: <20200416131339.437707967@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Changwei Ge commit 783fda856e1034dee90a873f7654c418212d12d7 upstream. Linux fallocate(2) with FALLOC_FL_PUNCH_HOLE mode set, its offset can exceed the inode size. Ocfs2 now doesn't allow that offset beyond inode size. This restriction is not necessary and violates fallocate(2) semantics. If fallocate(2) offset is beyond inode size, just return success and do nothing further. Otherwise, ocfs2 will crash the kernel. kernel BUG at fs/ocfs2//alloc.c:7264! ocfs2_truncate_inline+0x20f/0x360 [ocfs2] ocfs2_remove_inode_range+0x23c/0xcb0 [ocfs2] __ocfs2_change_file_space+0x4a5/0x650 [ocfs2] ocfs2_fallocate+0x83/0xa0 [ocfs2] vfs_fallocate+0x148/0x230 SyS_fallocate+0x48/0x80 do_syscall_64+0x79/0x170 Signed-off-by: Changwei Ge Signed-off-by: Andrew Morton Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Gang He Cc: Jun Piao Cc: Link: http://lkml.kernel.org/r/20200407082754.17565-1-chge@linux.alibaba.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/alloc.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -7403,6 +7403,10 @@ int ocfs2_truncate_inline(struct inode * struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; struct ocfs2_inline_data *idata = &di->id2.i_data; + /* No need to punch hole beyond i_size. */ + if (start >= i_size_read(inode)) + return 0; + if (end > i_size_read(inode)) end = i_size_read(inode);