Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp109147ybg; Mon, 8 Jun 2020 17:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnI2ws9HNLB8x90KcyKyMoVgxQS7vC+mYe1VnDGMJdDe+dDQUWOYh7mB8+Mxmw4FZB7jjx X-Received: by 2002:a50:e387:: with SMTP id b7mr22021606edm.190.1591663886644; Mon, 08 Jun 2020 17:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663886; cv=none; d=google.com; s=arc-20160816; b=kJd6N6LnMC5Q1TgDqU9T3jTrAQ7/DNzLAORcG3pq73DVQWGBI411XGlUwCO1eUAxD+ SBTnERL7svsXjE6Da9Ckjr5LUkCGewtsI7PZEdYDZQ6nFl0FqsLHqH6W5lcWzAftHQZx CMoir2k0vRs5c6NEZeTBz0uPl0TldRHSaqO+PdQD16k4+vxKjBI2ZKjV9BBm5mNbgwU5 46MUMM00TgVOshuq3BurMrXuGwtbn/jEeX0Jop/gc5izrEkLSEo26aQE8dvtycT7MGOK Odl5EoUzlSwvpQnO3J6XWmFA6xan5ZwG1rv94pjPthHbKPDGnkZOlwRdCT79KdTpwSN8 7c2w== 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=rjGBQLjR+vdOGS9D14CCYdvyHs59gh68j+CPSONic8M=; b=qKPtmBjnTX6h9hRIBt2pTsFnzBxiVsBEXPB5wGXMc4sK7s8kpzPkKacANYkRcr741x wlKH48gn4DuZ8AmvEi9sH+3PZyDg32IcWK6IXJEdDLBL50eEyp5VgrM9u7o9e1TV7z8g auawUMiyiLV7BQ9/PXDQM+nlupEpBtOHIt3zF/gSTBdX89ixrJmpxI4WQ04iadXsRRz/ 3y04tmfYiW2I5yqf2lVlQy8PC44knbzV35lEUhTKkeOmW3NuQmdiEfXgzU0GN7JTUnZN cKCwRpDFEHQ6IOYmwcqtNuvp2aq+yrmIWiEZ3bMo7r4cHQwmCyRaEOqpvuswCQGUWnwP LIkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tbqZljDg; 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 si29si9896023ejb.40.2020.06.08.17.51.01; Mon, 08 Jun 2020 17:51:26 -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=tbqZljDg; 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 S1733256AbgFIAtP (ORCPT + 99 others); Mon, 8 Jun 2020 20:49:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:57206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728773AbgFHXKs (ORCPT ); Mon, 8 Jun 2020 19:10:48 -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 82B6A20897; Mon, 8 Jun 2020 23:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657848; bh=dvPNjkEX0FRyQBVGbL9mveFmQllKPKlqmbk8N+PJ+1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tbqZljDgp0br6CsAunnVnprxXiFjawfgh8pSeJWATURW6D24Yytg59ZlOmgpi1aQx jTBzbG3rwYKjIQ+24+hPtJFg0aYhHY9YuYDGIhmKZkV3n13pgMEpjJIGaQkwg1TXkI 2oXidCR8sJc/FxZQrUNSWqbRNndqUNF/cK+71Jac= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Brian Foster , "Darrick J . Wong" , Christoph Hellwig , Sasha Levin , linux-xfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 214/274] xfs: don't fail verifier on empty attr3 leaf block Date: Mon, 8 Jun 2020 19:05:07 -0400 Message-Id: <20200608230607.3361041-214-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-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: Brian Foster [ Upstream commit f28cef9e4daca11337cb9f144cdebedaab69d78c ] The attr fork can transition from shortform to leaf format while empty if the first xattr doesn't fit in shortform. While this empty leaf block state is intended to be transient, it is technically not due to the transactional implementation of the xattr set operation. We historically have a couple of bandaids to work around this problem. The first is to hold the buffer after the format conversion to prevent premature writeback of the empty leaf buffer and the second is to bypass the xattr count check in the verifier during recovery. The latter assumes that the xattr set is also in the log and will be recovered into the buffer soon after the empty leaf buffer is reconstructed. This is not guaranteed, however. If the filesystem crashes after the format conversion but before the xattr set that induced it, only the format conversion may exist in the log. When recovered, this creates a latent corrupted state on the inode as any subsequent attempts to read the buffer fail due to verifier failure. This includes further attempts to set xattrs on the inode or attempts to destroy the attr fork, which prevents the inode from ever being removed from the unlinked list. To avoid this condition, accept that an empty attr leaf block is a valid state and remove the count check from the verifier. This means that on rare occasions an attr fork might exist in an unexpected state, but is otherwise consistent and functional. Note that we retain the logic to avoid racing with metadata writeback to reduce the window where this can occur. Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_attr_leaf.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 1d67cc9f4209..5d0b55281f9d 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -308,14 +308,6 @@ xfs_attr3_leaf_verify( if (fa) return fa; - /* - * In recovery there is a transient state where count == 0 is valid - * because we may have transitioned an empty shortform attr to a leaf - * if the attr didn't fit in shortform. - */ - if (!xfs_log_in_recovery(mp) && ichdr.count == 0) - return __this_address; - /* * firstused is the block offset of the first name info structure. * Make sure it doesn't go off the block or crash into the header. @@ -331,6 +323,13 @@ xfs_attr3_leaf_verify( (char *)bp->b_addr + ichdr.firstused) return __this_address; + /* + * NOTE: This verifier historically failed empty leaf buffers because + * we expect the fork to be in another format. Empty attr fork format + * conversions are possible during xattr set, however, and format + * conversion is not atomic with the xattr set that triggers it. We + * cannot assume leaf blocks are non-empty until that is addressed. + */ buf_end = (char *)bp->b_addr + mp->m_attr_geo->blksize; for (i = 0, ent = entries; i < ichdr.count; ent++, i++) { fa = xfs_attr3_leaf_verify_entry(mp, buf_end, leaf, &ichdr, -- 2.25.1