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,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 D1E6AC43381 for ; Sat, 30 Mar 2019 01:34:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92D7F2183F for ; Sat, 30 Mar 2019 01:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909642; bh=qW2A3pzZhdCEAwNbFIboI9FbT4nJ0KMg+zBoOwSMQcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=N/raicHDEG+Ow5swoXQYmXB90/o0q7TiSlsxWif2QQ7/hRbTS/uVZB1VI/iU2KVe4 ydk8exw88LltaduPxYMPM9nKnl4QnEQNJSUMUOuSyGPFkyMvdmytQ3cZMzeoVIuGbD IG4sJHorr4XLBy9IEVSEhRr1cM/VDuBMnsnUBH7o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731641AbfC3Bd4 (ORCPT ); Fri, 29 Mar 2019 21:33:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:40254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732301AbfC3BcP (ORCPT ); Fri, 29 Mar 2019 21:32:15 -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 19300218E2; Sat, 30 Mar 2019 01:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909534; bh=qW2A3pzZhdCEAwNbFIboI9FbT4nJ0KMg+zBoOwSMQcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0GVdleChpl1PBUqtN/NsKZqpC/qyaHqhdgWIx8E0OfFbGn+iq58nJKOnemveVFCom Bek5F7fhCpNN0o0p19PNjl1QN9vP6fnkINPMD0va+UEaQ7tVtj4K4c5+i77SImOcr4 2xR41c1xS29o1RzDi8WXC6b91xR9Ilc1fuvGUkTk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Darrick J. Wong" , Theodore Ts'o , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 12/16] ext4: prohibit fstrim in norecovery mode Date: Fri, 29 Mar 2019 21:31:56 -0400 Message-Id: <20190330013200.1130-12-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330013200.1130-1-sashal@kernel.org> References: <20190330013200.1130-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: "Darrick J. Wong" [ 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 bcd7c4788903..e44e3cd738b6 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -599,6 +599,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