From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D0ACC10F0E for ; Thu, 18 Apr 2019 18:24:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4ED252064A for ; Thu, 18 Apr 2019 18:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555611881; bh=iUCt3cqMsdeQ+glEsJC+CCbRZLOxuVFVyx38jwLdSjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EkXuUDwAjn8ZUjP86VuYI4L8xlcd8oNkLx0CnKGL9F+wS2JIJCmLFxXhDjmzKGn79 nt4wa/u3cPi2tOKu1Q0AAVbJJxcxbamnL3jSvHzW7oljAmvnHbMvkSX+/ojCNgf6jz JAPCXLFVSb3071gbCRRsBdv3/ubIhSQBicpao36I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391554AbfDRSYj (ORCPT ); Thu, 18 Apr 2019 14:24:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:35010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391340AbfDRSFg (ORCPT ); Thu, 18 Apr 2019 14:05:36 -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 5CF26217FA; Thu, 18 Apr 2019 18:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555610735; bh=iUCt3cqMsdeQ+glEsJC+CCbRZLOxuVFVyx38jwLdSjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zj5UiITGOftJPHSGxSV1SFDqceWfziz6cJib/P++FV6JqVSa3xS4yag9+85epXa/g ndlHri/l9vipFJHSw+K5WvG6o5Ha4ZatuE9Hy30ZwI59iEme2M7u57bIlXfDXX8X/w 4zHzcKMHRDLSJ4WVjvRi2HJGION27sJZRyhQfMNk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Theodore Tso , Sasha Levin Subject: [PATCH 4.14 37/92] ext4: prohibit fstrim in norecovery mode Date: Thu, 18 Apr 2019 19:56:55 +0200 Message-Id: <20190418160433.569902616@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160430.325165109@linuxfoundation.org> References: <20190418160430.325165109@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 [ Upstream commit 18915b5873f07e5030e6fb108a050fa7c71c59fb ] The ext4 fstrim implementation uses the block bitmaps to find free space that can be discarded. If we haven't replayed the journal, the bitmaps will be stale and we absolutely *cannot* use stale metadata to zap the underlying storage. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ioctl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 7917cc89ab21..3dbf4e414706 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -940,6 +940,13 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (!blk_queue_discard(q)) return -EOPNOTSUPP; + /* + * We haven't replayed the journal, so we cannot use our + * block-bitmap-guided storage zapping commands. + */ + if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) + return -EROFS; + if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range))) return -EFAULT; -- 2.19.1