Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2084602ybb; Fri, 29 Mar 2019 18:39:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQcT1xCfnFTGBlSFSGHDtETwBmt4+GmiE8R11CHO3sYln5CrLlBAh8vQqcRnJyjFtk3gD7 X-Received: by 2002:a63:1048:: with SMTP id 8mr25435152pgq.70.1553909976855; Fri, 29 Mar 2019 18:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909976; cv=none; d=google.com; s=arc-20160816; b=HeY58L5XirslsDh5d6FWjvG0Mr6bjxVKL5winUZdWvq+edqmwaY3xorW9rUFCOudgV NIBgBCFTagxF8kfXNhBkwTRNK4gAqrj23Z+dyA0miXjtYDlbH+tFhIpPqQrc4eCNW2p+ anHtK3XzK5fiLfREda2oW37gN4SgpBH/DywmXjamBtHBQannhZVrXlcDr/bDLGxdHyQK 3B0kA0lASqO+PWB8gimMJrzVRK4DdmIpjIW3aTuA2pxbrNcRPE5jVE74S3vt2wzUgI+y hCBThiEEixPdKdXyETh7DhNSyOf7UzgNxNYNTmDOEgCTvo7Rp3MT1RS2bolx85fYSE9r KK+A== 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=O4L2zuetJaBuqNSMYMhzO4zz9eMKIf52dM/scBtm4E4=; b=uU6sbXyzfrTwRJVfFaDXVdzb2YN/Zc2MoWWcFXE2fBKh3o6yoNN06mxh7FPt9XkQrM p8HYH2EMG+T61v6TAwXqjtUNEGR+mnh23rW5Xh9Uy7OjhvKgJ/ryceiBBbRDG5Pw6bft C8GBQ4VL2LRKoUbBQy0TPpW9kXfmTFxmIYBQAK1HvZLiotATlu/5bIskpoiBi0C4oSqC Q2zpMG+CFUd9Eo59YsiUdtaeoUa0Fl7IqHQQ2T1jCh9a7/WCZCuFp/eJmFkKyZjIdvMI Y7SN+X3gbOPtjD1+tMjOYw6ndil30/Fhprl03IflXT6D5SrX2i1DHAjjwvirAPjk6Gcn EBrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oxBpNnEz; 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 d12si3325528pgj.416.2019.03.29.18.39.21; Fri, 29 Mar 2019 18:39:36 -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=oxBpNnEz; 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 S1731498AbfC3BaY (ORCPT + 99 others); Fri, 29 Mar 2019 21:30:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:37428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731438AbfC3BaR (ORCPT ); Fri, 29 Mar 2019 21:30:17 -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 5272E217F5; Sat, 30 Mar 2019 01:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909417; bh=cRkDvbkGVjYnAxmFphy6GMC2+BOMm5V6n+aNWwX+i6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oxBpNnEz9B8Hvo+iUZ//ilAxgMos4BZqyoywQN2EcHd6dSVxiy5UXwhiKGTtRioeW ROAREYvGZrP3yiLyptLau3Iub6/qdmrb/3aLNA+1P5QOVDOaxUiUaotapG+323nvul WbXHFJbSVprAM2xyNTml6KT5/l8MB61IfMcTj1lM= 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.19 42/57] ext4: prohibit fstrim in norecovery mode Date: Fri, 29 Mar 2019 21:28:35 -0400 Message-Id: <20190330012854.32212-42-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330012854.32212-1-sashal@kernel.org> References: <20190330012854.32212-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 2e76fb55d94a..5f24fdc140ad 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -999,6 +999,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