Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1751730ybz; Sat, 18 Apr 2020 07:45:58 -0700 (PDT) X-Google-Smtp-Source: APiQypJLdRphRjk1OMgVYLs6ZejefzyD+Pce7xa0Du6XukpMxZm37ZfzDrQOpIQ5ukFaH8TP0Jyg X-Received: by 2002:a05:6402:1b0b:: with SMTP id by11mr7317569edb.269.1587221158115; Sat, 18 Apr 2020 07:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587221158; cv=none; d=google.com; s=arc-20160816; b=LyxON0mVJk0uKDx7aqETtctC2aEBlopakwQnuS5tS9CtecfrrNN6hFi7rFTsZJJ/Q0 dGLWwG9lDLv2Dy2RWKxVs0hOCZfpb4isvcXuh2toT1B8f19z8YXENWjge+y/1Wl2hD3B nGBzaLc6S/DctmKT0mHJ93AA4tm7AMJ8DliTeNKd8HIei0CNdyaAGk7O5wHbzMPk/AxR SQTRtWU8PBEZLnsc1xM0Txj/oBuRxo5iWt1RnMo2UwqFX3uL4SOX5UoaJIbIyM5Fgui+ LNSkfDvtYqTRyfvWnDT25ZTSWEEO3GB0htqmHDC8I81ADYdgvNeHaDT3QmW25CwmxNYP Zyqw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y0s1Y4UQkIFjCtzlrjyrO5wa3iYjVpCIq8GXssedpZk=; b=mVJXvQI4pbC33nJWTs2AO63a+xOD9TleO9nxaLsel9ttG490sld9dtDouGTWPROxBD aNcIv93/g9GR+wvrnRCYyIdEqCtasoBUbYRhsv6NI6+md8sEbv7f6ivDlDm7t0Oh5i5O /SLf0bd3lBME2HGraEI2UcFu1cYqXsp90qV/ODxTB8eLecS+C1RfT0ydVgNsvV3x68NC 6XOUBlub9m4nwNJ78rf4wW/dfiC8f6cPnUQwvao28xEMfs++fiF1ihTFpjvpXmTGEq5A a93zOIsQHEO7DPXbSF6KmVF3axwr/5hr+BP/iRdSObmmAo/g00JH2ajCELyX4hq9jJDI GiNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OT8wmrHC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v24si17065374edr.501.2020.04.18.07.45.35; Sat, 18 Apr 2020 07:45:58 -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=OT8wmrHC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728138AbgDROlt (ORCPT + 99 others); Sat, 18 Apr 2020 10:41:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:51310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728107AbgDROlq (ORCPT ); Sat, 18 Apr 2020 10:41:46 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 23D7D21D6C; Sat, 18 Apr 2020 14:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587220906; bh=B7l1JhQD7sZsRdFdz7Xv7IUnTyzfxeDDq7bjoIlTKh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OT8wmrHC5gyMzn9IMd3AK51ZwD4LAUPtQAfh6i1hGEwdCFO2DpMdTQHgR+iG/cc+q 6DO0dfdQIcVoNRvGW2z45gy/ubrxDQfULDVHZv/64Tl1AfLzrXbC9mRWgJ8dzIAik9 GNehTACRevGpTMT2oYZhJPP6WHvrV+DcqRBchGKw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Changwei Ge , Andrew Morton , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Gang He , Jun Piao , Linus Torvalds , Sasha Levin , ocfs2-devel@oss.oracle.com Subject: [PATCH AUTOSEL 5.4 46/78] ocfs2: no need try to truncate file beyond i_size Date: Sat, 18 Apr 2020 10:40:15 -0400 Message-Id: <20200418144047.9013-46-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200418144047.9013-1-sashal@kernel.org> References: <20200418144047.9013-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 783fda856e1034dee90a873f7654c418212d12d7 ] 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: Sasha Levin --- fs/ocfs2/alloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index f9baefc76cf9b..0a6fe7d5aba74 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -7403,6 +7403,10 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh, 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); -- 2.20.1