Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2084063ybb; Fri, 29 Mar 2019 18:38:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFKZBKGa0eWYCUXqBBbkvs0xOB3EDzS4QidiLRrbvgpD+8tMKzFtcP6Wu+PTwCRq0cU9vk X-Received: by 2002:a62:b602:: with SMTP id j2mr37178906pff.68.1553909917623; Fri, 29 Mar 2019 18:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909917; cv=none; d=google.com; s=arc-20160816; b=ef6/9FVmnPyzbhFbJ5jKFpyft0sIpTadSexMgglUc1Z1jHSe/rMZLfOyR01Xv5ogz+ YjvLXalVwQ8Qs+bT0+WTi4XHnjaB0zRJqaM7cxAcBI0FahRj/vslUg6KKqZ1Dl+5rQtK uDtCNpfdElMR3fi1sZLrQkZGRYWrXBFtmA4jDb6iur6cJM1VmKRjy94tahHD1jKhFMbe hN6WsXA+VTY8qXshKVxgB2/R9wGWIrR8stnZT08uZRuEejxp5FtbatJuQxKZroJgPSUk 91lzNXBb0TGHOwct6BPaimwTYmwJLPjZGocEeX1KEPrnN0Rhb3KBeM4BV6kYAMiLyzI5 iJGQ== 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=+7rKdxv87va5z/GTMVJjtSzaVqLyJnNpfrUWkusCW+E=; b=WNNl7hvWl5+dRSBlaEkUCDWGALdaeWk8YxDq/greh6dZans8Tye96NrAF9G8cVsUPZ SrBz3GzlAkmy1NRIgDHt21Nr9+TAtDzj2kNuUUObx9ktWvS2VTOIOacHbpVrb3OZ6xd5 oFGqV6lcHcU7QOYr/sefUHyE+GVdDeVbkiG3Y+Sffe1Q28t4DSxW1it7CuXOcTMmr1lD qSkcaJunf6Ok1/jWZcIVLjR7AgOTgT4YGtf6ShFszi8V7L6WUhDvfkcp2nVlVhB/ir7G 7Gv17Oj8hjSwVjQE0n7fjGBEnHdKk/RD3op9sJ+9t1HoNZDlPTjo3C0/t8MisLmblOce rnGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jd9Homdd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si3375930pla.89.2019.03.29.18.38.22; Fri, 29 Mar 2019 18:38:37 -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=Jd9Homdd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731831AbfC3Bgf (ORCPT + 99 others); Fri, 29 Mar 2019 21:36:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:38602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730954AbfC3BbJ (ORCPT ); Fri, 29 Mar 2019 21:31:09 -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 7024F217F5; Sat, 30 Mar 2019 01:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909469; bh=DmawPRaMrk1HaIMhcxgDMlWe2Oo1jLyWLs30oNu+jug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jd9Homdd443lCGXNLhV1Mc5MKNPCzKRjlSS8kQV5BRAcR4Bb+D9+NHjwQ5r6PxlF4 ZryZ/2mwqTS0MAnTN7VZu5eXCGsakuaUT+4gfLWsOH8/TY5739fb7WLpyTOIc4fLPE 7GTaiet/lAC/WHCuStCBgzdAvvHgUGeZEOfui1l8= 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.14 25/37] ext4: prohibit fstrim in norecovery mode Date: Fri, 29 Mar 2019 21:30:08 -0400 Message-Id: <20190330013020.379-25-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330013020.379-1-sashal@kernel.org> References: <20190330013020.379-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: "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 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